Skip to content

Commit 941a060

Browse files
committedMay 29, 2024
fix: bug prod etape 5 et 6 avec bouton oui / non (#41)
1 parent 956d9d4 commit 941a060

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed
 

‎src/app/simulation/etapes/Step5/index.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ const schemaNon = z.object({
3535
return { message: context.defaultError };
3636
},
3737
}),
38+
espacesExterieursCommuns: z.undefined(),
3839
});
3940

4041
export const Step5 = () => {
4142
const [radioState, setRadioState] = useState<(typeof OuiNonLabels)[number] | undefined>();
42-
const { store } = usePacoupaSessionStorage();
43+
const { store, setStore } = usePacoupaSessionStorage();
4344

4445
useEffect(() => {
4546
setRadioState((store.possedeEspacesExterieursCommuns as (typeof OuiNonLabels)[number]) ?? "Oui");
@@ -52,8 +53,11 @@ export const Step5 = () => {
5253
el.checked = false;
5354
},
5455
);
56+
setStore({ ...store, espacesExterieursCommuns: undefined });
5557
}
56-
}, [radioState]);
58+
// Doesn't depend on store and make a recursive call if present.
59+
// eslint-disable-next-line react-hooks/exhaustive-deps
60+
}, [radioState, setStore]);
5761

5862
return (
5963
<>

‎src/app/simulation/etapes/Step6/index.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,28 @@ const schemaNon = z.object({
3535
return { message: context.defaultError };
3636
},
3737
}),
38+
espacesExterieursPersonnels: z.undefined(),
3839
});
3940

4041
export const Step6 = () => {
4142
const [radioState, setRadioState] = useState<(typeof OuiNonLabels)[number] | undefined>();
42-
const { store } = usePacoupaSessionStorage();
43+
const { store, setStore } = usePacoupaSessionStorage();
4344

4445
useEffect(() => {
45-
setRadioState((store.possedeEspacesExterieursPersonnels as (typeof OuiNonLabels)[number]) ?? "Oui");
46+
setRadioState((store.possedeEspacesExterieursCommuns as (typeof OuiNonLabels)[number]) ?? "Oui");
4647
}, [store]);
47-
4848
useEffect(() => {
4949
if (radioState === "Non") {
5050
(document.getElementsByName("espacesExterieursPersonnels") as NodeListOf<HTMLInputElement>).forEach(
5151
(el: HTMLInputElement) => {
5252
el.checked = false;
5353
},
5454
);
55+
setStore({ ...store, espacesExterieursPersonnels: undefined });
5556
}
56-
}, [radioState]);
57+
// Doesn't depend on store and make a recursive call if present.
58+
// eslint-disable-next-line react-hooks/exhaustive-deps
59+
}, [radioState, setStore]);
5760

5861
return (
5962
<>

0 commit comments

Comments
 (0)
Please sign in to comment.