mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
add a wizard
This commit is contained in:
@@ -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>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user