From 09c4ac06a7a4b9811528a72456cc468685272cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Gonz=C3=A1lez=20Mu=C3=B1oz?= Date: Mon, 16 Dec 2024 12:17:56 +0100 Subject: [PATCH] Revert "removes restorationActivity from defaults" This reverts commit 456eb836 --- .../cost-inputs-overrides/capex/index.tsx | 15 ++++++++++++-- .../form/cost-inputs-overrides/opex/index.tsx | 13 ++++++++++-- .../cost-inputs-overrides/other/index.tsx | 13 ++++++++++-- client/src/containers/projects/new/index.tsx | 20 +------------------ 4 files changed, 36 insertions(+), 25 deletions(-) diff --git a/client/src/containers/projects/form/cost-inputs-overrides/capex/index.tsx b/client/src/containers/projects/form/cost-inputs-overrides/capex/index.tsx index b9100d47..f2b2b778 100644 --- a/client/src/containers/projects/form/cost-inputs-overrides/capex/index.tsx +++ b/client/src/containers/projects/form/cost-inputs-overrides/capex/index.tsx @@ -34,12 +34,18 @@ const NO_DATA: DataColumnDef[] = []; export default function CapexCostInputsTable() { const form = useFormContext(); - const { ecosystem, countryCode, activity } = form.getValues(); + const { + ecosystem, + countryCode, + activity, + parameters: { restorationActivity }, + } = form.getValues(); const { queryKey } = queryKeys.customProjects.defaultCosts({ ecosystem, countryCode, activity, + restorationActivity, }); const { data, isSuccess } = @@ -50,6 +56,7 @@ export default function CapexCostInputsTable() { ecosystem, countryCode, activity, + ...(activity === ACTIVITY.RESTORATION && { restorationActivity }), }, }, { @@ -71,7 +78,11 @@ export default function CapexCostInputsTable() { defaultValue: data.body.data[key as keyof typeof data.body.data], value: "", })), - enabled: !!ecosystem && !!countryCode && !!activity, + enabled: + !!ecosystem && + !!countryCode && + ((!!activity && activity === ACTIVITY.CONSERVATION) || + (activity === ACTIVITY.RESTORATION && !!restorationActivity)), }, ); diff --git a/client/src/containers/projects/form/cost-inputs-overrides/opex/index.tsx b/client/src/containers/projects/form/cost-inputs-overrides/opex/index.tsx index c0207c42..746ccd0c 100644 --- a/client/src/containers/projects/form/cost-inputs-overrides/opex/index.tsx +++ b/client/src/containers/projects/form/cost-inputs-overrides/opex/index.tsx @@ -34,12 +34,18 @@ const NO_DATA: DataColumnDef[] = []; export default function OpexCostInputsTable() { const form = useFormContext(); - const { ecosystem, countryCode, activity } = form.getValues(); + const { + ecosystem, + countryCode, + activity, + parameters: { restorationActivity }, + } = form.getValues(); const { queryKey } = queryKeys.customProjects.defaultCosts({ ecosystem, countryCode, activity, + restorationActivity, }); const { data, isSuccess } = client.customProjects.getDefaultCostInputs.useQuery( @@ -49,6 +55,7 @@ export default function OpexCostInputsTable() { ecosystem, countryCode, activity, + ...(activity === ACTIVITY.RESTORATION && { restorationActivity }), }, }, { @@ -70,7 +77,9 @@ export default function OpexCostInputsTable() { defaultValue: data.body.data[key as keyof typeof data.body.data], value: "", })), - enabled: !!ecosystem && !!countryCode && !!activity, + enabled: + (!!activity && activity === ACTIVITY.CONSERVATION) || + (activity === ACTIVITY.RESTORATION && !!restorationActivity), }, ); diff --git a/client/src/containers/projects/form/cost-inputs-overrides/other/index.tsx b/client/src/containers/projects/form/cost-inputs-overrides/other/index.tsx index 4ed57fa5..be174738 100644 --- a/client/src/containers/projects/form/cost-inputs-overrides/other/index.tsx +++ b/client/src/containers/projects/form/cost-inputs-overrides/other/index.tsx @@ -34,12 +34,18 @@ const NO_DATA: DataColumnDef[] = []; export default function OtherCostInputsTable() { const form = useFormContext(); - const { ecosystem, countryCode, activity } = form.getValues(); + const { + ecosystem, + countryCode, + activity, + parameters: { restorationActivity }, + } = form.getValues(); const { queryKey } = queryKeys.customProjects.defaultCosts({ ecosystem, countryCode, activity, + restorationActivity, }); const { data, isSuccess } = client.customProjects.getDefaultCostInputs.useQuery( @@ -49,6 +55,7 @@ export default function OtherCostInputsTable() { ecosystem, countryCode, activity, + ...(activity === ACTIVITY.RESTORATION && { restorationActivity }), }, }, { @@ -70,7 +77,9 @@ export default function OtherCostInputsTable() { defaultValue: data.body.data[key as keyof typeof data.body.data], value: "", })), - enabled: !!ecosystem && !!countryCode && !!activity, + enabled: + (!!activity && activity === ACTIVITY.CONSERVATION) || + (activity === ACTIVITY.RESTORATION && !!restorationActivity), }, ); diff --git a/client/src/containers/projects/new/index.tsx b/client/src/containers/projects/new/index.tsx index 1904e861..d5d9c0d5 100644 --- a/client/src/containers/projects/new/index.tsx +++ b/client/src/containers/projects/new/index.tsx @@ -67,22 +67,6 @@ export const onSubmit = (data: CreateCustomProjectForm) => { data = { ...originalValues, - parameters: { - ...originalValues.parameters, - // @ts-expect-error fix later - ...(originalValues.parameters?.plantingSuccessRate && { - // @ts-expect-error fix later - plantingSuccessRate: plantingSuccessRate / 100, - }), - ...(originalValues.activity === ACTIVITY.RESTORATION && { - restorationYearlyBreakdown: [ - ...new Set(originalValues.parameters.restorationYearlyBreakdown), - ].map((hectareas, index) => ({ - year: index, - annualHectaresRestored: hectareas, - })), - }), - }, assumptions: { ...Object.keys(originalValues.assumptions ?? {}).reduce( (acc, assumptionKey) => { @@ -136,7 +120,7 @@ export default function CreateCustomProject() { resolver: zodResolver(CreateCustomProjectSchema), defaultValues: { projectName: "test", - activity: ACTIVITY.RESTORATION, + activity: ACTIVITY.CONSERVATION, ecosystem: ECOSYSTEM.SEAGRASS, countryCode: countryOptions?.[0]?.value, projectSizeHa: 20, @@ -150,8 +134,6 @@ export default function CreateCustomProject() { projectSpecificEmissionFactor: 0, emissionFactorSOC: 0, emissionFactorAGB: 0, - // @ts-expect-error fix later - plantingSuccessRate: 80, }, assumptions: { baselineReassessmentFrequency: undefined,