Skip to content

Commit

Permalink
stub out save method
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Sep 22, 2024
1 parent e417b49 commit 1626b97
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface MapAndLabelContextValue {
addInitialFeaturesToMap: (features: Feature[]) => void;
editFeature: (index: number) => void;
copyFeature: (sourceIndex: number, destinationIndex: number) => void;
saveFeature: (index: number) => void;
removeFeature: (index: number) => void;
mapAndLabelProps: PresentationalProps;
errors: {
Expand Down Expand Up @@ -218,6 +219,11 @@ export const MapAndLabelProvider: React.FC<MapAndLabelProviderProps> = (
setActiveIndex((features && features.length - 2) || 0);
};

const saveFeature = (index: number) => {
// TODO separate schema field validation from "Continue"
formik.handleSubmit();
};

return (
<MapAndLabelContext.Provider
value={{
Expand All @@ -231,6 +237,7 @@ export const MapAndLabelProvider: React.FC<MapAndLabelProviderProps> = (
addInitialFeaturesToMap,
editFeature,
copyFeature,
saveFeature,
removeFeature,
isFeatureInvalid,
errors: {
Expand Down
29 changes: 18 additions & 11 deletions editor.planx.uk/src/@planx/components/MapAndLabel/Public/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const VerticalFeatureTabs: React.FC = () => {
editFeature,
isFeatureInvalid,
removeFeature,
saveFeature,
} = useMapAndLabelContext();

if (!features) {
Expand Down Expand Up @@ -165,17 +166,23 @@ const VerticalFeatureTabs: React.FC = () => {
activeIndex={activeIndex}
formik={formik}
/>
<Button
onClick={() => removeFeature(activeIndex)}
sx={{
fontWeight: FONT_WEIGHT_SEMI_BOLD,
gap: (theme) => theme.spacing(2),
marginTop: 2,
}}
>
<DeleteIcon color="warning" fontSize="medium" />
Remove
</Button>
<Box display="flex" gap={2} mt={2}>
<Button
variant="contained"
color="primary"
data-testid="save-item-button"
onClick={() => saveFeature(activeIndex)}
>
Save
</Button>
<Button
onClick={() => removeFeature(activeIndex)}
sx={{ fontWeight: FONT_WEIGHT_SEMI_BOLD }}
>
<DeleteIcon color="warning" fontSize="medium" />
Remove
</Button>
</Box>
</TabPanel>
))}
</TabContext>
Expand Down

0 comments on commit 1626b97

Please sign in to comment.