Skip to content

Commit

Permalink
Merge pull request #1627 from Vizzuality/MRXN23-565-project-creation-…
Browse files Browse the repository at this point in the history
…app-will-not

[MRXN23-565] fixes project creation after swapping way to set location
  • Loading branch information
agnlez authored Jan 17, 2024
2 parents c54ecc7 + 3e3d59f commit 5658b63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions app/layout/projects/new/form/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 };

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/layout/projects/new/form/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

1 comment on commit 5658b63

@vercel
Copy link

@vercel vercel bot commented on 5658b63 Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

marxan – ./

marxan23.vercel.app
marxan-vizzuality1.vercel.app
marxan-git-develop-vizzuality1.vercel.app

Please sign in to comment.