42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
/* eslint-disable canonical/id-match */
|
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
import { type StateCreator } from 'zustand';
|
|
|
|
export type Steps =
|
|
| 'client-select'
|
|
| 'datetime-select'
|
|
| 'error'
|
|
| 'loading'
|
|
| 'master-select'
|
|
| 'service-select'
|
|
| 'success';
|
|
|
|
export type StepsSlice = {
|
|
_setStepSequence: (steps: Steps[]) => void;
|
|
_stepSequence: Steps[];
|
|
nextStep: () => void;
|
|
prevStep: () => void;
|
|
setStep: (step: Steps) => void;
|
|
step: Steps;
|
|
};
|
|
|
|
export const createStepsSlice: StateCreator<StepsSlice> = (set, get) => ({
|
|
_setStepSequence: (steps) => set({ _stepSequence: steps }),
|
|
_stepSequence: [],
|
|
nextStep: () => {
|
|
const { _stepSequence, step } = get();
|
|
const index = _stepSequence.indexOf(step);
|
|
const next = _stepSequence[index + 1];
|
|
if (next) set({ step: next });
|
|
},
|
|
|
|
prevStep: () => {
|
|
const { _stepSequence, step } = get();
|
|
const index = _stepSequence.indexOf(step);
|
|
const previous = _stepSequence[index - 1];
|
|
if (previous) set({ step: previous });
|
|
},
|
|
setStep: (step) => set({ step }),
|
|
step: 'loading',
|
|
});
|