From 3e3d59f84fa9ade3abd9146c4ee6de6a2a47885f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Gonz=C3=A1lez?= Date: Wed, 17 Jan 2024 11:33:59 +0100 Subject: [PATCH] fixes project creation after swapping way to set location --- app/layout/projects/new/form/component.tsx | 24 ++++++++++++++++------ app/layout/projects/new/form/constants.ts | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/layout/projects/new/form/component.tsx b/app/layout/projects/new/form/component.tsx index 57f40f0a91..fc1b60a51e 100644 --- a/app/layout/projects/new/form/component.tsx +++ b/app/layout/projects/new/form/component.tsx @@ -42,11 +42,11 @@ import REGION_PU from 'images/info-buttons/img_planning_region_grid.png'; import { DEFAULT_AREA, PA_OPTIONS } from './constants'; export type NewProjectFields = { - PAOptionSelected: string; + PAOptionSelected: (typeof PA_OPTIONS)[number]['value']; countryId: string; planningAreaGridId: string; planningUnitAreakm2: number; - planningUnitGridShape: string; + planningUnitGridShape: 'hexagon' | 'square' | 'from_shapefile'; planningAreaId: string; adminAreaLevel1Id: string; adminAreaLevel2Id: string; @@ -79,16 +79,28 @@ const ProjectForm = ({ onFormUpdate }: ProjectFormProps): JSX.Element => { const onSubmit = (values: NewProjectFields) => { const v = { ...values }; - const { planningAreaGridId } = v; + const { planningAreaGridId, planningAreaId, adminAreaLevel1Id, adminAreaLevel2Id } = v; delete v.PAOptionSelected; delete v.planningAreaGridId; + if (planningAreaGridId || planningAreaId) { + delete v.countryId; + delete v.adminAreaLevel1Id; + delete v.adminAreaLevel2Id; + } + + if (adminAreaLevel1Id || adminAreaLevel2Id) { + delete v.planningAreaId; + } + // TEMPORARY!! // This should be removed once organizations IDs are handled in the user const data = { ...v, - ...(planningAreaGridId && { planningAreaId: planningAreaGridId }), - ...(planningAreaGridId && { planningUnitGridShape: 'from_shapefile' }), + ...(planningAreaGridId && { + planningAreaId: planningAreaGridId, + planningUnitGridShape: 'from_shapefile', + }), organizationId: organizationsData[0].id || '7f1fb7f8-1246-4509-89b9-f48b6f976e3f', } satisfies NewProjectFields & { organizationId: string }; @@ -341,7 +353,7 @@ const ProjectForm = ({ onFormUpdate }: ProjectFormProps): JSX.Element => { placeholder="Select option..." initialSelected={PAOptionSelected} options={OPTIONS} - onChange={(value: string) => { + onChange={(value: NewProjectFields['PAOptionSelected']) => { form.change('PAOptionSelected', value); setPAOptionSelected(value); resetPlanningArea(form); diff --git a/app/layout/projects/new/form/constants.ts b/app/layout/projects/new/form/constants.ts index b32fa86113..c8117da54c 100644 --- a/app/layout/projects/new/form/constants.ts +++ b/app/layout/projects/new/form/constants.ts @@ -18,4 +18,4 @@ export const PA_OPTIONS = [ label: 'No, I don’t have a planning region or planning unit shapefile', value: 'regular', }, -]; +] as const;