37 lines
873 B
TypeScript
37 lines
873 B
TypeScript
import { type Action, type State, type Steps } from './types';
|
|
|
|
const steps: Steps[] = [
|
|
'master-select',
|
|
'client-select',
|
|
'service-select',
|
|
'datetime-select',
|
|
'success',
|
|
];
|
|
|
|
export function reducer(state: State, action: Action): State {
|
|
switch (action.type) {
|
|
case 'NEXT_STEP': {
|
|
const currentIndex = steps.indexOf(state.step);
|
|
const nextIndex = currentIndex + 1;
|
|
const nextStep = steps[nextIndex];
|
|
|
|
return nextStep ? { ...state, step: nextStep } : state;
|
|
}
|
|
|
|
case 'PREV_STEP': {
|
|
const currentIndex = steps.indexOf(state.step);
|
|
const previousIndex = currentIndex - 1;
|
|
const previousStep = steps[previousIndex];
|
|
|
|
return previousStep ? { ...state, step: previousStep } : state;
|
|
}
|
|
|
|
case 'SET_STEP': {
|
|
return { ...state, step: action.payload };
|
|
}
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
}
|