add a wizard

This commit is contained in:
Thomas Ruoff
2020-07-06 00:27:02 +02:00
parent 298427b777
commit cbfb421c02
6 changed files with 157 additions and 136 deletions

View File

@@ -1,8 +1,10 @@
import React, { useReducer } from 'react'
export const AppContext = React.createContext()
export const WizardContext = React.createContext()
export const ACTIONS = {
NEXT_STEP: 'nextStep',
PREV_STEP: 'prevStep',
SET_MULTIPLE_DAYS: 'setMultipleDays',
SET_DATE: 'setDate',
SET_FOCUSED_INPUT: 'setFocusedInput',
@@ -12,6 +14,16 @@ export const ACTIONS = {
function reducer(state, action) {
switch (action.type) {
case ACTIONS.NEXT_STEP:
return {
...state,
currentStep: state.currentStep + 1, // wizards steps unkown here
}
case ACTIONS.PREV_STEP:
return {
...state,
currentStep: Math.max(0, state.currentStep - 1),
}
case ACTIONS.SET_MULTIPLE_DAYS:
return {
...state,
@@ -45,6 +57,7 @@ function debugReducer(state, action) {
}
const initialState = {
currentStep: 0,
multipleDays: null,
bookedOn: [
'2020-07-10',
@@ -55,12 +68,12 @@ const initialState = {
],
}
export default function AppStore({ children }) {
export default function WizardStore({ children }) {
const [state, dispatch] = useReducer(debugReducer, initialState)
return (
<AppContext.Provider value={{ state, dispatch }}>
<WizardContext.Provider value={{ state, dispatch }}>
{children}
</AppContext.Provider>
</WizardContext.Provider>
)
}