From 8cb5c3812c60c4f51989784197dde13494443471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Gonz=C3=A1lez=20Mu=C3=B1oz?= Date: Wed, 18 Dec 2024 17:45:37 +0100 Subject: [PATCH] project creation: ignores restoration years when creating conservation project --- client/src/containers/projects/new/index.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/client/src/containers/projects/new/index.tsx b/client/src/containers/projects/new/index.tsx index d902a571..fcf39364 100644 --- a/client/src/containers/projects/new/index.tsx +++ b/client/src/containers/projects/new/index.tsx @@ -67,17 +67,16 @@ export const onSubmit = async (data: CreateCustomProjectForm) => { {}, ); - const validYears = // @ts-expect-error fix later - (originalValues.parameters.restorationYearlyBreakdown as number[]) - .map((v, index) => { - // if (!v) return undefined; + const isRestoration = data.activity === ACTIVITY.RESTORATION; - return { + const validYears = isRestoration // @ts-expect-error fix later + ? (originalValues.parameters.restorationYearlyBreakdown as number[]) + .map((v, index) => ({ year: index == 0 ? -1 : index, hectares: v, - }; - }) - .filter((v) => v.hectares > 0); + })) + .filter((v) => v.hectares > 0) + : []; const { // @ts-expect-error fix later @@ -96,7 +95,7 @@ export const onSubmit = async (data: CreateCustomProjectForm) => { // @ts-expect-error fix later restParameters.plantingSuccessRate / 100, }), - ...(originalValues.activity === ACTIVITY.RESTORATION && { + ...(isRestoration && { ...(validYears.length > 0 && { restorationYearlyBreakdown: validYears.map(({ year, hectares }) => ({ year,