mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +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 React, { useContext } from 'react'
|
||||||
import { WizardContext } from './context/wizardStore'
|
import { BookContext } from '../../context/book'
|
||||||
import Input from '../input'
|
import Input from '../input'
|
||||||
|
|
||||||
export default function Contact() {
|
export default function Contact() {
|
||||||
const { state, onChangeEvent } = useContext(WizardContext)
|
const { state, onChangeEvent } = useContext(BookContext)
|
||||||
|
|
||||||
const { org, name, email, phone, street, zip, city } = state.formData
|
const { org, name, email, phone, street, zip, city } = state.formData
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import React, { useContext } from 'react'
|
import React, { useContext } from 'react'
|
||||||
import { WizardContext } from './context/wizardStore'
|
import { BookContext } from '../../context/book'
|
||||||
import InputWrapper from '../inputWrapper'
|
import InputWrapper from '../inputWrapper'
|
||||||
import Calendar from '../calendar'
|
import Calendar from '../calendar'
|
||||||
|
|
||||||
export default function DateSelect() {
|
export default function DateSelect() {
|
||||||
const { onChangeEvent, onChange, state } = useContext(WizardContext)
|
const { onChangeEvent, onChange, state } = useContext(BookContext)
|
||||||
const { startDate, endDate } = state.formData
|
const { startDate, endDate } = state.formData
|
||||||
|
|
||||||
const today = new Date().toISOString().substring(0, 10)
|
const today = new Date().toISOString().substring(0, 10)
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import React, { useContext } from 'react'
|
import React, { useContext } from 'react'
|
||||||
import Contact from './contact'
|
import Contact from './contact'
|
||||||
import WizardStore, { WizardContext } from './context/wizardStore'
|
import BookStore, { BookContext } from '../../context/book'
|
||||||
import DateSelect from './dateSelect'
|
import DateSelect from './dateSelect'
|
||||||
import Reason from './reason'
|
import Reason from './reason'
|
||||||
|
|
||||||
function WizardInternal() {
|
function BookForm() {
|
||||||
const { onSubmit, state, forgetData } = useContext(WizardContext)
|
const { onSubmit, state, forgetData } = useContext(BookContext)
|
||||||
const { postData, postDataError, dataStoredLoaded } = state
|
const { postData, postDataError, dataStoredLoaded } = state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -41,10 +41,10 @@ function WizardInternal() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Wizard() {
|
export default function Book() {
|
||||||
return (
|
return (
|
||||||
<WizardStore>
|
<BookStore>
|
||||||
<WizardInternal />
|
<BookForm />
|
||||||
</WizardStore>
|
</BookStore>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import React, { useContext } from 'react'
|
import React, { useContext } from 'react'
|
||||||
import { WizardContext } from './context/wizardStore'
|
import { BookContext } from '../../context/book'
|
||||||
import Input from '../input'
|
import Input from '../input'
|
||||||
|
|
||||||
export default function Contact() {
|
export default function Contact() {
|
||||||
const { state, onChangeEvent } = useContext(WizardContext)
|
const { state, onChangeEvent } = useContext(BookContext)
|
||||||
|
|
||||||
const { purpose, destination } = state.formData
|
const { purpose, destination } = state.formData
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@ import { useContext } from 'react'
|
|||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import User from './user'
|
import User from './user'
|
||||||
import UserContext from './user/context'
|
import UserContext from '../context/user'
|
||||||
import { USER_ROLE } from '../lib/session'
|
import { USER_ROLE } from '../lib/session'
|
||||||
|
|
||||||
const pathNameLabelMap = {
|
const pathNameLabelMap = {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useContext } from 'react'
|
import { useContext } from 'react'
|
||||||
|
|
||||||
import UserContext from './user/context'
|
import UserContext from '../context/user'
|
||||||
|
|
||||||
export default function User() {
|
export default function User() {
|
||||||
const { username, role } = useContext(UserContext)
|
const { username, role } = useContext(UserContext)
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import React, { useEffect, useReducer } from 'react'
|
import React, { useEffect, useReducer } from 'react'
|
||||||
import { useRouter } from 'next/router'
|
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
|
startDate: string
|
||||||
endDate: string
|
endDate: string
|
||||||
purpose: string
|
purpose: string
|
||||||
@@ -23,33 +23,33 @@ interface Booking {
|
|||||||
uuid: string
|
uuid: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface WizardStoreState {
|
interface BookingStoreState {
|
||||||
postData?: boolean
|
postData?: boolean
|
||||||
postDataError?: string
|
postDataError?: string
|
||||||
postDataSuccess?: boolean
|
postDataSuccess?: boolean
|
||||||
formData: WizardFormData
|
formData: BookFormData
|
||||||
formDataChanged: string[]
|
formDataChanged: string[]
|
||||||
booking?: Booking
|
booking?: Booking
|
||||||
dataStored: boolean
|
dataStored: boolean
|
||||||
dataStoredLoaded: boolean
|
dataStoredLoaded: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface WizardStore {
|
interface BookStore {
|
||||||
state: WizardStoreState
|
state: BookingStoreState
|
||||||
dispatch: React.Dispatch<WizardAction>
|
dispatch: React.Dispatch<BookAction>
|
||||||
onChange: (data: object) => void
|
onChange: (data: object) => void
|
||||||
onChangeEvent: (event: React.ChangeEvent<React.ElementRef<'input'>>) => void
|
onChangeEvent: (event: React.ChangeEvent<React.ElementRef<'input'>>) => void
|
||||||
onSubmit: () => void
|
onSubmit: () => void
|
||||||
forgetData: () => void
|
forgetData: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
interface WizardAction {
|
interface BookAction {
|
||||||
type: string
|
type: string
|
||||||
payload?: any
|
payload?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WizardContext: React.Context<WizardStore> = React.createContext<
|
export const BookContext: React.Context<BookStore> = React.createContext<
|
||||||
WizardStore
|
BookStore
|
||||||
>(null)
|
>(null)
|
||||||
|
|
||||||
export const ACTIONS = {
|
export const ACTIONS = {
|
||||||
@@ -61,7 +61,7 @@ export const ACTIONS = {
|
|||||||
DATA_STORED_FORGOTTEN: 'dataStoredForgotten',
|
DATA_STORED_FORGOTTEN: 'dataStoredForgotten',
|
||||||
}
|
}
|
||||||
|
|
||||||
function reducer(state: WizardStoreState, action: WizardAction) {
|
function reducer(state: BookingStoreState, action: BookAction) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ACTIONS.SET_FORM_DATA:
|
case ACTIONS.SET_FORM_DATA:
|
||||||
return {
|
return {
|
||||||
@@ -115,7 +115,7 @@ function reducer(state: WizardStoreState, action: WizardAction) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: WizardStoreState = {
|
const initialState: BookingStoreState = {
|
||||||
postData: false,
|
postData: false,
|
||||||
postDataError: null,
|
postDataError: null,
|
||||||
postDataSuccess: null,
|
postDataSuccess: null,
|
||||||
@@ -137,7 +137,7 @@ const initialState: WizardStoreState = {
|
|||||||
dataStoredLoaded: undefined,
|
dataStoredLoaded: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function WizardStore({ children }) {
|
export default function BookProvider({ children }) {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [state, dispatch] = useReducer(reducer, initialState)
|
const [state, dispatch] = useReducer(reducer, initialState)
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ export default function WizardStore({ children }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WizardContext.Provider
|
<BookContext.Provider
|
||||||
value={{
|
value={{
|
||||||
state,
|
state,
|
||||||
dispatch,
|
dispatch,
|
||||||
@@ -195,6 +195,6 @@ export default function WizardStore({ children }) {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</WizardContext.Provider>
|
</BookContext.Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { UserData } from '../../lib/session'
|
import { UserData } from '../lib/session'
|
||||||
|
|
||||||
const UserContext = React.createContext<UserData>({
|
const UserContext = React.createContext<UserData>({
|
||||||
username: undefined,
|
username: undefined,
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import '../styles/index.css'
|
import '../styles/index.css'
|
||||||
import UserContext from '../components/user/context'
|
import UserContext from '../context/user'
|
||||||
|
|
||||||
export default function MyApp({ Component, pageProps }) {
|
export default function MyApp({ Component, pageProps }) {
|
||||||
const { username, role } = pageProps?.user || {}
|
const { username, role } = pageProps?.user || {}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import Layout from '../components/layout'
|
import Layout from '../components/layout'
|
||||||
import Wizard from '../components/wizard/index'
|
import Book from '../components/book'
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<h1 className="mb-3 text-xl font-extrabold">Buchungsanfrage</h1>
|
<h1 className="mb-3 text-xl font-extrabold">Buchungsanfrage</h1>
|
||||||
<Wizard />
|
<Book />
|
||||||
</Layout>
|
</Layout>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user