mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
move contexts all out in own toplevel dir
- rename wizard to book
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
@@ -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 (
|
||||
<WizardStore>
|
||||
<WizardInternal />
|
||||
</WizardStore>
|
||||
<BookStore>
|
||||
<BookForm />
|
||||
</BookStore>
|
||||
)
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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<WizardAction>
|
||||
interface BookStore {
|
||||
state: BookingStoreState
|
||||
dispatch: React.Dispatch<BookAction>
|
||||
onChange: (data: object) => void
|
||||
onChangeEvent: (event: React.ChangeEvent<React.ElementRef<'input'>>) => void
|
||||
onSubmit: () => void
|
||||
forgetData: () => void
|
||||
}
|
||||
|
||||
interface WizardAction {
|
||||
interface BookAction {
|
||||
type: string
|
||||
payload?: any
|
||||
}
|
||||
|
||||
export const WizardContext: React.Context<WizardStore> = React.createContext<
|
||||
WizardStore
|
||||
export const BookContext: React.Context<BookStore> = 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 (
|
||||
<WizardContext.Provider
|
||||
<BookContext.Provider
|
||||
value={{
|
||||
state,
|
||||
dispatch,
|
||||
@@ -195,6 +195,6 @@ export default function WizardStore({ children }) {
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</WizardContext.Provider>
|
||||
</BookContext.Provider>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react'
|
||||
import { UserData } from '../../lib/session'
|
||||
import { UserData } from '../lib/session'
|
||||
|
||||
const UserContext = React.createContext<UserData>({
|
||||
username: undefined,
|
||||
@@ -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 || {}
|
||||
|
||||
@@ -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 (
|
||||
<Layout>
|
||||
<h1 className="mb-3 text-xl font-extrabold">Buchungsanfrage</h1>
|
||||
<Wizard />
|
||||
<Book />
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user