mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
use types instead of interfaces
This commit is contained in:
@@ -3,27 +3,15 @@ import { useRouter } from 'next/router'
|
||||
import { clearBookingData, loadBookingData } from '../helpers/storage'
|
||||
|
||||
import { createBooking } from '../helpers/booking'
|
||||
import { Booker } from '../db/booker'
|
||||
import { Booking } from '../db/booking'
|
||||
|
||||
interface BookFormData {
|
||||
startDate: string
|
||||
endDate: string
|
||||
purpose: string
|
||||
org: string
|
||||
destination: string
|
||||
name: string
|
||||
email: string
|
||||
phone: string
|
||||
street: string
|
||||
zip: string
|
||||
city: string
|
||||
storeData?: boolean
|
||||
}
|
||||
export type BookFormData = Omit<Booking, 'uuid'> &
|
||||
Booker & {
|
||||
storeData?: boolean
|
||||
}
|
||||
|
||||
interface Booking {
|
||||
uuid: string
|
||||
}
|
||||
|
||||
interface BookingStoreState {
|
||||
type BookingProviderState = {
|
||||
postData?: boolean
|
||||
postDataError?: string
|
||||
postDataSuccess?: boolean
|
||||
@@ -34,8 +22,8 @@ interface BookingStoreState {
|
||||
dataStoredLoaded: boolean
|
||||
}
|
||||
|
||||
interface BookStore {
|
||||
state: BookingStoreState
|
||||
type BookProvider = {
|
||||
state: BookingProviderState
|
||||
dispatch: React.Dispatch<BookAction>
|
||||
onChange: (data: object) => void
|
||||
onChangeEvent: (event: React.ChangeEvent<React.ElementRef<'input'>>) => void
|
||||
@@ -43,13 +31,13 @@ interface BookStore {
|
||||
forgetData: () => void
|
||||
}
|
||||
|
||||
interface BookAction {
|
||||
type BookAction = {
|
||||
type: string
|
||||
payload?: any
|
||||
}
|
||||
|
||||
export const BookContext: React.Context<BookStore> = React.createContext<
|
||||
BookStore
|
||||
export const BookContext: React.Context<BookProvider> = React.createContext<
|
||||
BookProvider
|
||||
>(null)
|
||||
|
||||
export const ACTIONS = {
|
||||
@@ -61,7 +49,7 @@ export const ACTIONS = {
|
||||
DATA_STORED_FORGOTTEN: 'dataStoredForgotten',
|
||||
}
|
||||
|
||||
function reducer(state: BookingStoreState, action: BookAction) {
|
||||
function reducer(state: BookingProviderState, action: BookAction) {
|
||||
switch (action.type) {
|
||||
case ACTIONS.SET_FORM_DATA:
|
||||
return {
|
||||
@@ -115,7 +103,7 @@ function reducer(state: BookingStoreState, action: BookAction) {
|
||||
}
|
||||
}
|
||||
|
||||
const initialState: BookingStoreState = {
|
||||
const initialState: BookingProviderState = {
|
||||
postData: false,
|
||||
postDataError: null,
|
||||
postDataSuccess: null,
|
||||
|
||||
Reference in New Issue
Block a user