Disable buttons when loading and add toggle-buttons api

This commit is contained in:
Arnaud 2024-09-25 13:09:06 +02:00
parent a982ba09d3
commit 1ef4031522
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
2 changed files with 13 additions and 13 deletions

View File

@ -35,11 +35,8 @@ export type StepperAction =
step: number;
}
| {
type: "toggle-next";
type: "toggle-buttons";
isNextEnable: boolean;
}
| {
type: "toggle-back";
isBackEnable: boolean;
};
@ -71,6 +68,8 @@ const reducer = () => (state: StepperState, action: StepperAction) => {
case "loading": {
return {
...state,
isBackEnable: false,
isNextEnable: false,
step: action.step,
progress: true,
};
@ -84,17 +83,11 @@ const reducer = () => (state: StepperState, action: StepperAction) => {
};
}
case "toggle-next": {
return {
...state,
isNextEnable: action.isNextEnable,
};
}
case "toggle-back": {
case "toggle-buttons": {
return {
...state,
isBackEnable: action.isBackEnable,
isNextEnable: action.isNextEnable,
};
}
}

View File

@ -27,8 +27,9 @@ const Template = (p: Props) => {
useEffect(() => {
dispatch({
type: "toggle-next",
type: "toggle-buttons",
isNextEnable: true,
isBackEnable: true,
});
}, [dispatch]);
@ -38,6 +39,12 @@ const Template = (p: Props) => {
const onNextStep = async (step: number) => {
p.onNextStep(step);
dispatch({
type: "toggle-buttons",
isNextEnable: true,
isBackEnable: true,
});
dispatch({
step,
type: "next",