mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 23:17:12 +01:00
move rest into pages
This commit is contained in:
@@ -10,7 +10,7 @@ import 'react-dates/initialize'
|
|||||||
import { DateRangePicker, SingleDatePicker } from 'react-dates'
|
import { DateRangePicker, SingleDatePicker } from 'react-dates'
|
||||||
|
|
||||||
import Required from './required'
|
import Required from './required'
|
||||||
import { dateFormat } from '../lib/dateHelper'
|
import { dateFormat } from '../helpers/date'
|
||||||
|
|
||||||
const fetcher = (path) => fetch(path).then((r) => r.json())
|
const fetcher = (path) => fetch(path).then((r) => r.json())
|
||||||
|
|
||||||
@@ -1,4 +1,2 @@
|
|||||||
import react from 'react'
|
|
||||||
|
|
||||||
const Required = () => <span>*</span>
|
const Required = () => <span>*</span>
|
||||||
export default Required
|
export default Required
|
||||||
@@ -11,7 +11,7 @@ import Contact from './contact'
|
|||||||
//import Driver from './driver'
|
//import Driver from './driver'
|
||||||
|
|
||||||
function WizardInternal() {
|
function WizardInternal() {
|
||||||
const { onSubmit, state } = useContext(WizardContext)
|
const { onSubmit, state, storeData } = useContext(WizardContext)
|
||||||
const { postData, postDataSuccess, postDataError } = state
|
const { postData, postDataSuccess, postDataError } = state
|
||||||
|
|
||||||
if (postDataSuccess) {
|
if (postDataSuccess) {
|
||||||
@@ -23,7 +23,7 @@ function WizardInternal() {
|
|||||||
Sollen die eingegebenen Daten in Deinem Browser für die nächste
|
Sollen die eingegebenen Daten in Deinem Browser für die nächste
|
||||||
Buchung gespeichert werden?
|
Buchung gespeichert werden?
|
||||||
</p>
|
</p>
|
||||||
<Button>Ja, bitte speichern</Button>
|
<Button onClick={storeData}>Ja, bitte speichern</Button>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
import React, { useReducer } from 'react'
|
import React, { useReducer, useEffect } from 'react'
|
||||||
|
|
||||||
|
import { storeFormData, loadFormData } from '../helpers/storage'
|
||||||
|
|
||||||
export const WizardContext = React.createContext()
|
export const WizardContext = React.createContext()
|
||||||
|
|
||||||
@@ -93,6 +95,11 @@ async function createBooking(formData) {
|
|||||||
export default function WizardStore({ children }) {
|
export default function WizardStore({ children }) {
|
||||||
const [state, dispatch] = useReducer(debugReducer, initialState)
|
const [state, dispatch] = useReducer(debugReducer, initialState)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const data = loadFormData()
|
||||||
|
dispatch({ type: ACTIONS.SET_FORM_DATA, payload: data })
|
||||||
|
}, [])
|
||||||
|
|
||||||
const onChangeEvent = (event) => {
|
const onChangeEvent = (event) => {
|
||||||
const { name, value } = event.target
|
const { name, value } = event.target
|
||||||
|
|
||||||
@@ -121,9 +128,11 @@ export default function WizardStore({ children }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const storeData = () => storeFormData(state.formData)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WizardContext.Provider
|
<WizardContext.Provider
|
||||||
value={{ state, dispatch, onChangeEvent, onChange, onSubmit }}
|
value={{ state, dispatch, onChangeEvent, onChange, onSubmit, storeData }}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</WizardContext.Provider>
|
</WizardContext.Provider>
|
||||||
17
pages/helpers/storage.js
Normal file
17
pages/helpers/storage.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
const FORM_DATA_KEY = 'pfadiBussleFormData'
|
||||||
|
|
||||||
|
function getStorage() {
|
||||||
|
return localStorage
|
||||||
|
}
|
||||||
|
|
||||||
|
export function storeFormData({ org, name, email, street, zip, city }) {
|
||||||
|
getStorage().setItem(
|
||||||
|
FORM_DATA_KEY,
|
||||||
|
JSON.stringify({ org, name, email, street, zip, city })
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function loadFormData() {
|
||||||
|
const dataAsString = getStorage().getItem(FORM_DATA_KEY)
|
||||||
|
return JSON.parse(dataAsString || '{}')
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import Head from 'next/head'
|
import Head from 'next/head'
|
||||||
|
|
||||||
import Wizard from '../components/wizard'
|
import Wizard from './components/wizard'
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user