use types instead of interfaces

This commit is contained in:
Thomas Ruoff
2021-06-08 23:02:52 +02:00
parent dbe3904759
commit 498f212ee0
10 changed files with 56 additions and 71 deletions

View File

@@ -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,