mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 22:47:15 +01:00
make stored an own page and redirect there
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import React, { useEffect, useReducer } from 'react'
|
||||
import {
|
||||
clearBookingData,
|
||||
loadBookingData,
|
||||
storeBookingData,
|
||||
} from '../../../helpers/storage'
|
||||
import { useRouter } from 'next/router'
|
||||
import { clearBookingData, loadBookingData } from '../../../helpers/storage'
|
||||
import { ValidationError } from './validationError'
|
||||
|
||||
interface WizardFormData {
|
||||
@@ -17,6 +14,7 @@ interface WizardFormData {
|
||||
street: string
|
||||
zip: string
|
||||
city: string
|
||||
storeData?: boolean
|
||||
}
|
||||
|
||||
interface Booking {
|
||||
@@ -40,7 +38,6 @@ interface WizardStore {
|
||||
onChange: (data: object) => void
|
||||
onChangeEvent: (event: React.ChangeEvent<React.ElementRef<'input'>>) => void
|
||||
onSubmit: () => void
|
||||
storeData: (value: boolean) => void
|
||||
forgetData: () => void
|
||||
}
|
||||
|
||||
@@ -57,7 +54,6 @@ export const ACTIONS = {
|
||||
SET_FORM_DATA: 'setFormData',
|
||||
POST_DATA: 'postData',
|
||||
POST_DATA_ERROR: 'postDataError',
|
||||
POST_DATA_SUCCESS: 'postDataSuccess',
|
||||
DATA_STORED: 'dataStored',
|
||||
DATA_STORED_LOADED: 'dataStoredLoaded',
|
||||
DATA_STORED_FORGOTTEN: 'dataStoredForgotten',
|
||||
@@ -91,17 +87,6 @@ function reducer(state: WizardStoreState, action: WizardAction) {
|
||||
postDataError: action.payload,
|
||||
postDataSuccess: null,
|
||||
}
|
||||
case ACTIONS.POST_DATA_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
formData: {
|
||||
...state.formData,
|
||||
},
|
||||
booking: { ...action.payload },
|
||||
postData: false,
|
||||
postDataError: null,
|
||||
postDataSuccess: true,
|
||||
}
|
||||
case ACTIONS.DATA_STORED_LOADED:
|
||||
return {
|
||||
...state,
|
||||
@@ -177,6 +162,7 @@ async function createBooking(formData: WizardFormData) {
|
||||
}
|
||||
|
||||
export default function WizardStore({ children }) {
|
||||
const router = useRouter()
|
||||
const [state, dispatch] = useReducer(reducer, initialState)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -209,21 +195,13 @@ export default function WizardStore({ children }) {
|
||||
|
||||
try {
|
||||
const booking = await createBooking(state.formData)
|
||||
dispatch({ type: ACTIONS.POST_DATA_SUCCESS, payload: booking })
|
||||
router.push(`/booking/${booking.uuid}/stored`)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
dispatch({ type: ACTIONS.POST_DATA_ERROR, payload: error.message })
|
||||
}
|
||||
}
|
||||
|
||||
const storeData = (value: boolean) => {
|
||||
if (value) {
|
||||
storeBookingData(state.booking)
|
||||
}
|
||||
|
||||
dispatch({ type: ACTIONS.DATA_STORED, payload: value })
|
||||
}
|
||||
|
||||
const forgetData = () => {
|
||||
clearBookingData()
|
||||
dispatch({ type: ACTIONS.DATA_STORED_FORGOTTEN })
|
||||
@@ -237,7 +215,6 @@ export default function WizardStore({ children }) {
|
||||
onChangeEvent,
|
||||
onChange,
|
||||
onSubmit,
|
||||
storeData,
|
||||
forgetData,
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user