diff --git a/components/wizard/contact.tsx b/components/book/contact.tsx similarity index 90% rename from components/wizard/contact.tsx rename to components/book/contact.tsx index 993ced1..14933ce 100644 --- a/components/wizard/contact.tsx +++ b/components/book/contact.tsx @@ -1,9 +1,9 @@ import React, { useContext } from 'react' -import { WizardContext } from './context/wizardStore' +import { BookContext } from '../../context/book' import Input from '../input' export default function Contact() { - const { state, onChangeEvent } = useContext(WizardContext) + const { state, onChangeEvent } = useContext(BookContext) const { org, name, email, phone, street, zip, city } = state.formData diff --git a/components/wizard/dateSelect.tsx b/components/book/dateSelect.tsx similarity index 92% rename from components/wizard/dateSelect.tsx rename to components/book/dateSelect.tsx index b8352ba..a95f87b 100644 --- a/components/wizard/dateSelect.tsx +++ b/components/book/dateSelect.tsx @@ -1,10 +1,10 @@ import React, { useContext } from 'react' -import { WizardContext } from './context/wizardStore' +import { BookContext } from '../../context/book' import InputWrapper from '../inputWrapper' import Calendar from '../calendar' export default function DateSelect() { - const { onChangeEvent, onChange, state } = useContext(WizardContext) + const { onChangeEvent, onChange, state } = useContext(BookContext) const { startDate, endDate } = state.formData const today = new Date().toISOString().substring(0, 10) diff --git a/components/wizard/index.tsx b/components/book/index.tsx similarity index 80% rename from components/wizard/index.tsx rename to components/book/index.tsx index 302a292..f12461f 100644 --- a/components/wizard/index.tsx +++ b/components/book/index.tsx @@ -1,11 +1,11 @@ import React, { useContext } from 'react' import Contact from './contact' -import WizardStore, { WizardContext } from './context/wizardStore' +import BookStore, { BookContext } from '../../context/book' import DateSelect from './dateSelect' import Reason from './reason' -function WizardInternal() { - const { onSubmit, state, forgetData } = useContext(WizardContext) +function BookForm() { + const { onSubmit, state, forgetData } = useContext(BookContext) const { postData, postDataError, dataStoredLoaded } = state return ( @@ -41,10 +41,10 @@ function WizardInternal() { ) } -export default function Wizard() { +export default function Book() { return ( - - - + + + ) } diff --git a/components/wizard/reason.tsx b/components/book/reason.tsx similarity index 80% rename from components/wizard/reason.tsx rename to components/book/reason.tsx index 7f50a8f..14a6d4c 100644 --- a/components/wizard/reason.tsx +++ b/components/book/reason.tsx @@ -1,9 +1,9 @@ import React, { useContext } from 'react' -import { WizardContext } from './context/wizardStore' +import { BookContext } from '../../context/book' import Input from '../input' export default function Contact() { - const { state, onChangeEvent } = useContext(WizardContext) + const { state, onChangeEvent } = useContext(BookContext) const { purpose, destination } = state.formData diff --git a/components/navigation.tsx b/components/navigation.tsx index d3d028a..17b3c90 100644 --- a/components/navigation.tsx +++ b/components/navigation.tsx @@ -2,7 +2,7 @@ import { useContext } from 'react' import { useRouter } from 'next/router' import Link from 'next/link' import User from './user' -import UserContext from './user/context' +import UserContext from '../context/user' import { USER_ROLE } from '../lib/session' const pathNameLabelMap = { diff --git a/components/user.tsx b/components/user.tsx index c72b858..b9036e4 100644 --- a/components/user.tsx +++ b/components/user.tsx @@ -1,6 +1,6 @@ import { useContext } from 'react' -import UserContext from './user/context' +import UserContext from '../context/user' export default function User() { const { username, role } = useContext(UserContext) diff --git a/components/wizard/context/wizardStore.tsx b/context/book.tsx similarity index 85% rename from components/wizard/context/wizardStore.tsx rename to context/book.tsx index 8f17a93..f01d25b 100644 --- a/components/wizard/context/wizardStore.tsx +++ b/context/book.tsx @@ -1,10 +1,10 @@ import React, { useEffect, useReducer } from 'react' import { useRouter } from 'next/router' -import { clearBookingData, loadBookingData } from '../../../helpers/storage' +import { clearBookingData, loadBookingData } from '../helpers/storage' -import { createBooking } from '../../../helpers/booking' +import { createBooking } from '../helpers/booking' -interface WizardFormData { +interface BookFormData { startDate: string endDate: string purpose: string @@ -23,33 +23,33 @@ interface Booking { uuid: string } -interface WizardStoreState { +interface BookingStoreState { postData?: boolean postDataError?: string postDataSuccess?: boolean - formData: WizardFormData + formData: BookFormData formDataChanged: string[] booking?: Booking dataStored: boolean dataStoredLoaded: boolean } -interface WizardStore { - state: WizardStoreState - dispatch: React.Dispatch +interface BookStore { + state: BookingStoreState + dispatch: React.Dispatch onChange: (data: object) => void onChangeEvent: (event: React.ChangeEvent>) => void onSubmit: () => void forgetData: () => void } -interface WizardAction { +interface BookAction { type: string payload?: any } -export const WizardContext: React.Context = React.createContext< - WizardStore +export const BookContext: React.Context = React.createContext< + BookStore >(null) export const ACTIONS = { @@ -61,7 +61,7 @@ export const ACTIONS = { DATA_STORED_FORGOTTEN: 'dataStoredForgotten', } -function reducer(state: WizardStoreState, action: WizardAction) { +function reducer(state: BookingStoreState, action: BookAction) { switch (action.type) { case ACTIONS.SET_FORM_DATA: return { @@ -115,7 +115,7 @@ function reducer(state: WizardStoreState, action: WizardAction) { } } -const initialState: WizardStoreState = { +const initialState: BookingStoreState = { postData: false, postDataError: null, postDataSuccess: null, @@ -137,7 +137,7 @@ const initialState: WizardStoreState = { dataStoredLoaded: undefined, } -export default function WizardStore({ children }) { +export default function BookProvider({ children }) { const router = useRouter() const [state, dispatch] = useReducer(reducer, initialState) @@ -184,7 +184,7 @@ export default function WizardStore({ children }) { } return ( - {children} - + ) } diff --git a/components/user/context.tsx b/context/user.tsx similarity index 77% rename from components/user/context.tsx rename to context/user.tsx index 35a72af..b092f6b 100644 --- a/components/user/context.tsx +++ b/context/user.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { UserData } from '../../lib/session' +import { UserData } from '../lib/session' const UserContext = React.createContext({ username: undefined, diff --git a/pages/_app.tsx b/pages/_app.tsx index 159a597..fb8bc39 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,5 +1,5 @@ import '../styles/index.css' -import UserContext from '../components/user/context' +import UserContext from '../context/user' export default function MyApp({ Component, pageProps }) { const { username, role } = pageProps?.user || {} diff --git a/pages/book.tsx b/pages/book.tsx index 6c2b001..03ec93b 100644 --- a/pages/book.tsx +++ b/pages/book.tsx @@ -1,11 +1,11 @@ import Layout from '../components/layout' -import Wizard from '../components/wizard/index' +import Book from '../components/book' export default function Home() { return (

Buchungsanfrage

- +
) }