30 lines
691 B
JavaScript
30 lines
691 B
JavaScript
import { ALLOW_RENDER, SET_STEP, CLEAN_STATE } from './types.js';
|
|
|
|
/**
|
|
* @param {{ currentStep: Number, isAllowRender: boolean}} state
|
|
*/
|
|
|
|
export const rootReducer = (state, action) => {
|
|
const { type, payload } = action;
|
|
|
|
switch (type) {
|
|
case ALLOW_RENDER:
|
|
return { ...state, isAllowRender: true };
|
|
|
|
case SET_STEP:
|
|
setStepToLocalStorage(payload);
|
|
return { ...state, currentStep: payload };
|
|
|
|
case CLEAN_STATE:
|
|
setStepToLocalStorage(1);
|
|
return { ...state, isAllowRender: false, currentStep: 1 };
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
};
|
|
|
|
function setStepToLocalStorage(nextStep) {
|
|
localStorage.setItem('trainingModalCurrentStep', nextStep);
|
|
}
|