feat: make steps of enter details flow dynamic depending on data
This commit is contained in:
committed by
Joakim Jäderberg
parent
d49e301634
commit
c6fc500d9e
@@ -17,5 +17,5 @@ export interface BreakfastPackage
|
||||
extends z.output<typeof breakfastPackageSchema> {}
|
||||
|
||||
export interface BreakfastProps {
|
||||
packages: BreakfastPackages | null
|
||||
packages: BreakfastPackages
|
||||
}
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
export enum StepEnum {
|
||||
selectBed = "select-bed",
|
||||
breakfast = "breakfast",
|
||||
details = "details",
|
||||
payment = "payment",
|
||||
}
|
||||
import { StepEnum } from "@/types/enums/step"
|
||||
|
||||
export const StepStoreKeys: Record<StepEnum, "bedType" | "breakfast" | null> = {
|
||||
"select-bed": "bedType",
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { StepEnum } from "./step"
|
||||
|
||||
export type EnterDetailsProviderProps = { step: StepEnum; isMember: boolean }
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { RoomsData } from "./bookingData"
|
||||
|
||||
export interface SummaryProps {
|
||||
showMemberPrice: boolean
|
||||
room: RoomsData
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { StepEnum } from "../enterDetails/step"
|
||||
import { StepEnum } from "@/types/enums/step"
|
||||
|
||||
export interface SectionAccordionProps {
|
||||
header: string
|
||||
|
||||
3
types/contexts/details.ts
Normal file
3
types/contexts/details.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { createDetailsStore } from "@/stores/details"
|
||||
|
||||
export type DetailsStore = ReturnType<typeof createDetailsStore>
|
||||
3
types/contexts/steps.ts
Normal file
3
types/contexts/steps.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { createStepsStore } from "@/stores/steps"
|
||||
|
||||
export type StepsStore = ReturnType<typeof createStepsStore>
|
||||
@@ -1,5 +1,4 @@
|
||||
export enum BreakfastPackageEnum {
|
||||
FREE_MEMBER_BREAKFAST = "BRF0",
|
||||
REGULAR_BREAKFAST = "BRF1",
|
||||
NO_BREAKFAST = "NO_BREAKFAST",
|
||||
}
|
||||
|
||||
6
types/enums/step.ts
Normal file
6
types/enums/step.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export enum StepEnum {
|
||||
selectBed = "select-bed",
|
||||
breakfast = "breakfast",
|
||||
details = "details",
|
||||
payment = "payment",
|
||||
}
|
||||
3
types/providers/details.ts
Normal file
3
types/providers/details.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export interface DetailsProviderProps extends React.PropsWithChildren {
|
||||
isMember: boolean
|
||||
}
|
||||
10
types/providers/steps.ts
Normal file
10
types/providers/steps.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { BedTypeSelection } from "@/types/components/hotelReservation/enterDetails/bedType"
|
||||
import { StepEnum } from "@/types/enums/step"
|
||||
import type { BreakfastPackage } from "../components/hotelReservation/enterDetails/breakfast"
|
||||
|
||||
export interface StepsProviderProps extends React.PropsWithChildren {
|
||||
bedTypes: BedTypeSelection[]
|
||||
breakfastPackages: BreakfastPackage[] | null
|
||||
isMember: boolean
|
||||
step: StepEnum
|
||||
}
|
||||
40
types/stores/details.ts
Normal file
40
types/stores/details.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import type { BedTypeSchema } from "@/types/components/hotelReservation/enterDetails/bedType"
|
||||
import type { BookingData } from "@/types/components/hotelReservation/enterDetails/bookingData"
|
||||
import type { BreakfastPackage } from "@/types/components/hotelReservation/enterDetails/breakfast"
|
||||
import type { DetailsSchema } from "@/types/components/hotelReservation/enterDetails/details"
|
||||
import { StepEnum } from "@/types/enums/step"
|
||||
|
||||
export interface DetailsState {
|
||||
actions: {
|
||||
setIsSubmittingDisabled: (isSubmittingDisabled: boolean) => void
|
||||
setTotalPrice: (totalPrice: TotalPrice) => void
|
||||
toggleSummaryOpen: () => void,
|
||||
updateBedType: (data: BedTypeSchema) => void
|
||||
updateBreakfast: (data: BreakfastPackage | false) => void
|
||||
updateDetails: (data: DetailsSchema) => void
|
||||
updateValidity: (property: StepEnum, isValid: boolean) => void
|
||||
}
|
||||
data: DetailsSchema & {
|
||||
bedType: BedTypeSchema | undefined
|
||||
breakfast: BreakfastPackage | false | undefined
|
||||
booking: BookingData
|
||||
}
|
||||
isSubmittingDisabled: boolean
|
||||
isSummaryOpen: boolean
|
||||
isValid: Record<StepEnum, boolean>
|
||||
totalPrice: TotalPrice
|
||||
}
|
||||
|
||||
export interface InitialState extends Partial<DetailsState> {
|
||||
booking: BookingData
|
||||
}
|
||||
|
||||
interface Price {
|
||||
currency: string
|
||||
price: number
|
||||
}
|
||||
|
||||
export interface TotalPrice {
|
||||
euro: Price | undefined
|
||||
local: Price
|
||||
}
|
||||
10
types/stores/steps.ts
Normal file
10
types/stores/steps.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { StepEnum } from "@/types/enums/step"
|
||||
|
||||
export interface StepState {
|
||||
completeStep: () => void
|
||||
navigate: (step: StepEnum) => void
|
||||
setStep: (step: StepEnum) => void
|
||||
|
||||
currentStep: StepEnum
|
||||
steps: StepEnum[]
|
||||
}
|
||||
Reference in New Issue
Block a user