Skip to content

Commit

Permalink
Revert "removes restorationActivity from defaults"
Browse files Browse the repository at this point in the history
This reverts commit 456eb83
  • Loading branch information
agnlez committed Dec 16, 2024
1 parent 06d8ad2 commit 09c4ac0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ const NO_DATA: DataColumnDef<CapexFormProperty>[] = [];
export default function CapexCostInputsTable() {
const form = useFormContext<CreateCustomProjectForm>();

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 } =
Expand All @@ -50,6 +56,7 @@ export default function CapexCostInputsTable() {
ecosystem,
countryCode,
activity,
...(activity === ACTIVITY.RESTORATION && { restorationActivity }),
},
},
{
Expand All @@ -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)),
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ const NO_DATA: DataColumnDef<OpexFormProperty>[] = [];
export default function OpexCostInputsTable() {
const form = useFormContext<CreateCustomProjectForm>();

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(
Expand All @@ -49,6 +55,7 @@ export default function OpexCostInputsTable() {
ecosystem,
countryCode,
activity,
...(activity === ACTIVITY.RESTORATION && { restorationActivity }),
},
},
{
Expand All @@ -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),
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ const NO_DATA: DataColumnDef<OtherFormProperty>[] = [];
export default function OtherCostInputsTable() {
const form = useFormContext<CreateCustomProjectForm>();

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(
Expand All @@ -49,6 +55,7 @@ export default function OtherCostInputsTable() {
ecosystem,
countryCode,
activity,
...(activity === ACTIVITY.RESTORATION && { restorationActivity }),
},
},
{
Expand All @@ -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),
},
);

Expand Down
20 changes: 1 addition & 19 deletions client/src/containers/projects/new/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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,
Expand All @@ -150,8 +134,6 @@ export default function CreateCustomProject() {
projectSpecificEmissionFactor: 0,
emissionFactorSOC: 0,
emissionFactorAGB: 0,
// @ts-expect-error fix later
plantingSuccessRate: 80,
},
assumptions: {
baselineReassessmentFrequency: undefined,
Expand Down

0 comments on commit 09c4ac0

Please sign in to comment.