diff --git a/components/contact.js b/components/contact.js
index e1a4576..b64a2c9 100644
--- a/components/contact.js
+++ b/components/contact.js
@@ -1,18 +1,14 @@
import { useContext } from 'react'
-import { AppContext, ACTIONS } from '../context/appStore'
+import { WizardContext, ACTIONS } from '../context/wizardStore'
import Form from 'react-bootstrap/Form'
import Col from 'react-bootstrap/Col'
export default function Contact() {
- const { state, dispatch } = useContext(AppContext)
+ const { state, dispatch } = useContext(WizardContext)
const { multipleDays, startDate, endDate } = state
- if (!startDate || (multipleDays && !endDate)) {
- return null
- }
-
return (
<>
diff --git a/components/dateSelect.js b/components/dateSelect.js
index 821b3d9..810d064 100644
--- a/components/dateSelect.js
+++ b/components/dateSelect.js
@@ -1,5 +1,5 @@
import { useContext } from 'react'
-import { AppContext, ACTIONS } from '../context/appStore'
+import { WizardContext, ACTIONS } from '../context/wizardStore'
import Form from 'react-bootstrap/Form'
@@ -8,7 +8,7 @@ import 'react-dates/initialize'
import { DateRangePicker, SingleDatePicker } from 'react-dates'
export default function DateSelect() {
- const { state, dispatch } = useContext(AppContext)
+ const { state, dispatch } = useContext(WizardContext)
const {
multipleDays,
@@ -24,65 +24,88 @@ export default function DateSelect() {
return bookedOn.some((rawDay) => momentDay.isSame(rawDay))
}
- if (multipleDays === null || multipleDays === undefined) {
- return null
- }
-
return (
<>
-
-
- Datum
-
- {state.multipleDays === false && (
-
- dispatch({
- type: ACTIONS.SET_DATE,
- payload: { startDate: date.toISOString() },
- })
- }
- focused={typeof focusedInput === 'boolean' && focusedInput}
- onFocusChange={({ focused }) =>
- dispatch({
- type: ACTIONS.SET_FOCUSED_INPUT,
- payload: focused,
- })
- }
- isDayBlocked={isDayBlocked}
- id="your_unique_id"
- />
- )}
- {state.multipleDays === true && (
- {
- dispatch({
- type: ACTIONS.SET_DATE,
- payload: {
- startDate: startDate && startDate.toISOString(),
- endDate: endDate && endDate.toISOString(),
- },
- })
- }}
- focusedInput={focusedInput}
- onFocusChange={(focusedInput) =>
- dispatch({
- type: ACTIONS.SET_FOCUSED_INPUT,
- payload: focusedInput,
- })
- }
- isDayBlocked={isDayBlocked}
- minDate={moment()}
- />
- )}
+
+ Willst du einen odere mehrere Tage buchen?
+
+ dispatch({ type: ACTIONS.SET_MULTIPLE_DAYS, payload: false })
+ }
+ />
+
+ dispatch({ type: ACTIONS.SET_MULTIPLE_DAYS, payload: true })
+ }
+ />
+ {multipleDays !== null && (
+
+
+ Datum
+
+ {state.multipleDays === false && (
+
+ dispatch({
+ type: ACTIONS.SET_DATE,
+ payload: { startDate: date.toISOString() },
+ })
+ }
+ focused={typeof focusedInput === 'boolean' && focusedInput}
+ onFocusChange={({ focused }) =>
+ dispatch({
+ type: ACTIONS.SET_FOCUSED_INPUT,
+ payload: focused,
+ })
+ }
+ isDayBlocked={isDayBlocked}
+ id="your_unique_id"
+ />
+ )}
+ {state.multipleDays === true && (
+ {
+ dispatch({
+ type: ACTIONS.SET_DATE,
+ payload: {
+ startDate: startDate && startDate.toISOString(),
+ endDate: endDate && endDate.toISOString(),
+ },
+ })
+ }}
+ focusedInput={focusedInput}
+ onFocusChange={(focusedInput) =>
+ dispatch({
+ type: ACTIONS.SET_FOCUSED_INPUT,
+ payload: focusedInput,
+ })
+ }
+ isDayBlocked={isDayBlocked}
+ minDate={moment()}
+ />
+ )}
+
+ )}
>
)
}
diff --git a/components/rangeSelect.js b/components/rangeSelect.js
deleted file mode 100644
index 5941714..0000000
--- a/components/rangeSelect.js
+++ /dev/null
@@ -1,50 +0,0 @@
-import { useContext } from 'react'
-import { AppContext, ACTIONS } from '../context/appStore'
-
-import Form from 'react-bootstrap/Form'
-
-export default function RangeSelect() {
- const { state, dispatch } = useContext(AppContext)
-
- function getValue() {
- const { multipleDays } = state
-
- if (multipleDays === null || multipleDays === undefined) {
- return null
- }
-
- if (multipleDays === true) {
- return 'multiple'
- }
-
- return 'single'
- }
-
- return (
-
- Willst du einen odere mehrere Tage buchen?
-
- dispatch({ type: ACTIONS.SET_MULTIPLE_DAYS, payload: false })
- }
- />
-
- dispatch({ type: ACTIONS.SET_MULTIPLE_DAYS, payload: true })
- }
- />
-
- )
-}
diff --git a/components/wizard.js b/components/wizard.js
new file mode 100644
index 0000000..e0d831b
--- /dev/null
+++ b/components/wizard.js
@@ -0,0 +1,55 @@
+import { useContext } from 'react'
+
+import Button from 'react-bootstrap/Button'
+import Form from 'react-bootstrap/Form'
+
+import WizardStore, { WizardContext, ACTIONS } from '../context/wizardStore'
+
+import DateSelect from './dateSelect'
+import Contact from './contact'
+import Driver from './driver'
+
+const STEPS = [
+ { id: 'DATE_SELECT', component: DateSelect },
+ { id: 'CONTACT', component: Contact },
+]
+
+function WizardInternal() {
+ const { state, dispatch } = useContext(WizardContext)
+ const { currentStep } = state
+
+ const isFirstStep = currentStep === 0
+ const isLastStep = currentStep === STEPS.length - 1
+
+ return (
+
+ )
+}
+
+export default function Wizard() {
+ return (
+
+
+
+ )
+}
diff --git a/context/appStore.js b/context/wizardStore.js
similarity index 73%
rename from context/appStore.js
rename to context/wizardStore.js
index 357548a..e066cd0 100644
--- a/context/appStore.js
+++ b/context/wizardStore.js
@@ -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 (
-
+
{children}
-
+
)
}
diff --git a/pages/index.js b/pages/index.js
index 2d3c9f6..0cbb53a 100644
--- a/pages/index.js
+++ b/pages/index.js
@@ -2,15 +2,7 @@ import { useContext } from 'react'
import Head from 'next/head'
-import AppStore from '../context/appStore'
-
-import RangeSelect from '../components/rangeSelect'
-import DateSelect from '../components/dateSelect'
-import Contact from '../components/contact'
-import Driver from '../components/driver'
-
-import Form from 'react-bootstrap/Form'
-import Button from 'react-bootstrap/Button'
+import Wizard from '../components/wizard'
export default function Home() {
return (
@@ -25,15 +17,7 @@ export default function Home() {
Du willst das Pfadi Bussle buchen? Hier bist du richtig!
-
-
-
+