feat: make steps of enter details flow dynamic depending on data

This commit is contained in:
Simon Emanuelsson
2024-11-18 09:13:23 +01:00
committed by Joakim Jäderberg
parent d49e301634
commit c6fc500d9e
62 changed files with 959 additions and 659 deletions

View File

@@ -17,5 +17,5 @@ export interface BreakfastPackage
extends z.output<typeof breakfastPackageSchema> {}
export interface BreakfastProps {
packages: BreakfastPackages | null
packages: BreakfastPackages
}

View File

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

View File

@@ -1,3 +0,0 @@
import { StepEnum } from "./step"
export type EnterDetailsProviderProps = { step: StepEnum; isMember: boolean }

View File

@@ -0,0 +1,6 @@
import type { RoomsData } from "./bookingData"
export interface SummaryProps {
showMemberPrice: boolean
room: RoomsData
}

View File

@@ -1,4 +1,4 @@
import { StepEnum } from "../enterDetails/step"
import { StepEnum } from "@/types/enums/step"
export interface SectionAccordionProps {
header: string

View File

@@ -0,0 +1,3 @@
import { createDetailsStore } from "@/stores/details"
export type DetailsStore = ReturnType<typeof createDetailsStore>

3
types/contexts/steps.ts Normal file
View File

@@ -0,0 +1,3 @@
import { createStepsStore } from "@/stores/steps"
export type StepsStore = ReturnType<typeof createStepsStore>

View File

@@ -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
View File

@@ -0,0 +1,6 @@
export enum StepEnum {
selectBed = "select-bed",
breakfast = "breakfast",
details = "details",
payment = "payment",
}

View File

@@ -0,0 +1,3 @@
export interface DetailsProviderProps extends React.PropsWithChildren {
isMember: boolean
}

10
types/providers/steps.ts Normal file
View 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
View 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
View 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[]
}