Skip to content

Commit

Permalink
formik submits map data
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Aug 18, 2024
1 parent 3388f04 commit a129d35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
19 changes: 9 additions & 10 deletions editor.planx.uk/src/@planx/components/List/Public/Fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,7 @@ export const ChecklistFieldInput: React.FC<Props<ChecklistField>> = (props) => {
);
};

export const DateFieldInput: React.FC<Props<DateField>> = ({
id,
data,
}) => {
export const DateFieldInput: React.FC<Props<DateField>> = ({ id, data }) => {
const { formik, activeIndex } = useListContext();

return (
Expand All @@ -247,7 +244,10 @@ export const DateFieldInput: React.FC<Props<DateField>> = ({
value={formik.values.userData[activeIndex][data.fn] as string}
bordered
onChange={(newDate: string, eventType: string) => {
formik.setFieldValue(`userData[${activeIndex}]['${data.fn}']`, paddedDate(newDate, eventType));
formik.setFieldValue(
`userData[${activeIndex}]['${data.fn}']`,
paddedDate(newDate, eventType),
);
}}
error={get(formik.errors, ["userData", activeIndex, data.fn])}
id={id}
Expand All @@ -267,23 +267,22 @@ export const MapFieldInput: React.FC<Props<MapField>> = (props) => {
const teamSettings = useStore.getState().teamSettings;
const passport = useStore((state) => state.computePassport());

const [features, setFeatures] = useState<Feature[] | undefined>(undefined);
const [_features, setFeatures] = useState<Feature[] | undefined>(undefined);

useEffect(() => {
const geojsonChangeHandler = async ({ detail: geojson }: any) => {
if (geojson["EPSG:3857"]?.features) {
setFeatures(geojson["EPSG:3857"].features);
await formik.setFieldValue(
`userData[${activeIndex}]['${fn}']`,
features,
geojson["EPSG:3857"].features,
);
console.log(features, formik);
} else {
// if the user clicks 'reset' on the map, geojson will be empty object, so set features to undefined
setFeatures(undefined);
await formik.setFieldValue(
`userData[${activeIndex}]['${fn}']`,
features,
undefined,
);
}
};
Expand Down Expand Up @@ -328,5 +327,5 @@ export const MapFieldInput: React.FC<Props<MapField>> = (props) => {
</MapContainer>
</ErrorWrapper>
</InputLabel>
)
);
};
6 changes: 3 additions & 3 deletions editor.planx.uk/src/@planx/components/List/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ export const parseContent = (data: Record<string, any> | undefined): List => ({
...parseMoreInformation(data),
});

const mapValidationSchema = ({ drawMany }: MapField["data"]) =>
const mapValidationSchema = ({ drawType }: MapField["data"]) =>
array()
.required()
.test({
name: "atLeastOneFeature",
message: "Add at least one feature to the map",
message: `Draw at least one ${drawType?.toLocaleLowerCase()} on the map`,
test: (features?: Array<Feature>) => {
return Boolean(drawMany && features && features?.length > 0);
return Boolean(features && features?.length > 0);
},
});

Expand Down

0 comments on commit a129d35

Please sign in to comment.