Skip to content

Commit

Permalink
feat(web): display previously entered data in urban project decontami…
Browse files Browse the repository at this point in the history
…nation form
  • Loading branch information
stephane-ruhlmann committed Jan 7, 2025
1 parent a7ad952 commit 66fac29
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ describe("Urban project custom creation : soils decontamination", () => {
const newState = store.getState();
expectUpdatedState(initialRootState, newState, {
currentStep: "SOILS_DECONTAMINATION_SURFACE_AREA",
creationDataDiff: {
decontaminationNeeded: "partial",
},
});
});
it("goes to BUILDINGS_INTRODUCTION step and set 0 to decontaminated surface when step is completed with 'none' option", () => {
Expand All @@ -66,6 +69,7 @@ describe("Urban project custom creation : soils decontamination", () => {
expectUpdatedState(initialRootState, newState, {
currentStep: "BUILDINGS_INTRODUCTION",
creationDataDiff: {
decontaminationNeeded: "none",
decontaminatedSurfaceArea: 0,
},
});
Expand All @@ -88,6 +92,7 @@ describe("Urban project custom creation : soils decontamination", () => {
expectUpdatedState(initialRootState, newState, {
currentStep: "BUILDINGS_INTRODUCTION",
creationDataDiff: {
decontaminationNeeded: "unknown",
decontaminatedSurfaceArea: 250,
},
});
Expand All @@ -105,6 +110,7 @@ describe("Urban project custom creation : soils decontamination", () => {
expectUpdatedState(initialRootState, newState, {
currentStep: "STAKEHOLDERS_INTRODUCTION",
creationDataDiff: {
decontaminationNeeded: "none",
decontaminatedSurfaceArea: 0,
},
});
Expand All @@ -124,6 +130,7 @@ describe("Urban project custom creation : soils decontamination", () => {
expectUpdatedState(initialRootState, newState, {
currentStep: "STAKEHOLDERS_INTRODUCTION",
creationDataDiff: {
decontaminationNeeded: "unknown",
decontaminatedSurfaceArea: 250,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export type UrbanProjectState = {
greenSpacesDistribution?: Partial<Record<UrbanGreenSpace, number>>;
livingAndActivitySpacesDistribution?: Partial<Record<UrbanLivingAndActivitySpace, number>>;
publicSpacesDistribution?: Partial<Record<UrbanPublicSpace, number>>;
decontaminationNeeded?: "partial" | "none" | "unknown";
decontaminatedSurfaceArea?: number;
// buildings
buildingsFloorSurfaceArea?: number;
Expand Down Expand Up @@ -400,6 +401,8 @@ const urbanProjectReducer = createReducer({} as ProjectCreationState, (builder)
const nextSectionStep = hasBuildings(state)
? "BUILDINGS_INTRODUCTION"
: "STAKEHOLDERS_INTRODUCTION";

state.urbanProject.creationData.decontaminationNeeded = action.payload;
switch (action.payload) {
case "partial":
state.urbanProject.stepsHistory.push("SOILS_DECONTAMINATION_SURFACE_AREA");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FormInfo from "@/shared/views/layout/WizardFormLayout/FormInfo";
import WizardFormLayout from "@/shared/views/layout/WizardFormLayout/WizardFormLayout";

type Props = {
initialValues?: FormValues;
onSubmit: (data: FormValues) => void;
onBack: () => void;
};
Expand All @@ -14,8 +15,10 @@ export type FormValues = {
decontaminationSelection: "partial" | "none" | "unknown" | null;
};

function SoilsDecontaminationSelection({ onSubmit, onBack }: Props) {
const { register, handleSubmit, formState, watch } = useForm<FormValues>();
function SoilsDecontaminationSelection({ initialValues, onSubmit, onBack }: Props) {
const { register, handleSubmit, formState, watch } = useForm<FormValues>({
defaultValues: initialValues,
});

return (
<WizardFormLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import {
import SoilsDecontaminationSelection, {
FormValues,
} from "@/features/create-project/views/common-views/soils-decontamination/selection/SoilsDecontaminationSelection";
import { useAppDispatch } from "@/shared/views/hooks/store.hooks";
import { useAppDispatch, useAppSelector } from "@/shared/views/hooks/store.hooks";

function SoilsDecontaminationSelectionContainer() {
const decontaminationNeeded = useAppSelector(
(state) => state.projectCreation.urbanProject.creationData.decontaminationNeeded,
);
const dispatch = useAppDispatch();

return (
<SoilsDecontaminationSelection
initialValues={{
decontaminationSelection: decontaminationNeeded ?? null,
}}
onSubmit={(data: FormValues) => {
dispatch(
soilsDecontaminationSelectionCompleted(data.decontaminationSelection ?? "unknown"),
Expand Down

0 comments on commit 66fac29

Please sign in to comment.