Merged in feat/enter-details-multiroom (pull request #1280)

feat(SW-1259): Enter details multiroom

* refactor: remove per-step URLs

* WIP: map multiroom data

* fix: lint errors in details page

* fix: made useEnterDetailsStore tests pass

* fix: WIP refactor enter details store

* fix: WIP enter details store update

* fix: added room index to select correct room

* fix: added logic for navigating between steps and rooms

* fix: update summary to work with store changes

* fix: added room and total price calculation

* fix: removed unused code and added test for breakfast included

* refactor: move store selectors into helpers

* refactor: session storage state for multiroom booking

* feat: update enter details accordion navigation

* fix: added room index to each form component so they select correct room

* fix: added unique id to input to handle case when multiple inputs have same name

* fix: update payment step with store changes

* fix: rebase issues

* fix: now you should only be able to go to a step if previous room is completed

* refactor: cleanup

* fix: if no availability just skip that room for now

* fix: add select-rate Summary and adjust typings


Approved-by: Arvid Norlin
This commit is contained in:
Tobias Johansson
2025-02-11 14:24:24 +00:00
committed by Arvid Norlin
parent f43ee4a0e6
commit b394d54c3f
48 changed files with 1870 additions and 1150 deletions

View File

@@ -2,41 +2,47 @@ import type { BedTypeSchema } from "@/types/components/hotelReservation/enterDet
import type { BreakfastPackage } from "@/types/components/hotelReservation/enterDetails/breakfast"
import type {
DetailsSchema,
RoomPrice,
RoomRate,
SignedInDetailsSchema,
} from "@/types/components/hotelReservation/enterDetails/details"
import type { StepEnum } from "@/types/enums/step"
import type { SelectRateSearchParams } from "../components/hotelReservation/selectRate/selectRate"
import type { DetailsProviderProps } from "../providers/enter-details"
import type { Price } from "../components/hotelReservation/price"
import type {
Child,
SelectRateSearchParams,
} from "../components/hotelReservation/selectRate/selectRate"
import type { Packages } from "../requests/packages"
interface TPrice {
currency: string
price: number
export interface InitialRoomData {
roomRate: RoomRate
roomType: string
rateDetails: string[] | undefined
cancellationText: string
roomFeatures: Packages | null
bedType?: BedTypeSchema // used when there is only one bedtype to preselect it
}
export interface RoomPrice {
perNight: Price
perStay: Price
}
export interface Price {
requested: TPrice | undefined
local: TPrice
}
export interface FormValues {
export interface RoomState extends InitialRoomData {
adults: number
childrenInRoom: Child[] | undefined
bedType: BedTypeSchema | undefined
booking: SelectRateSearchParams
breakfast: BreakfastPackage | false | undefined
guest: DetailsSchema | SignedInDetailsSchema
roomPrice: RoomPrice
}
export type InitialState = {
booking: SelectRateSearchParams
vat: number
rooms: InitialRoomData[]
breakfast?: false
}
export interface DetailsState {
actions: {
completeStep: () => void
navigate: (step: StepEnum) => void
setStep: (step: StepEnum | null, roomIndex?: number) => void
setIsSubmittingDisabled: (isSubmittingDisabled: boolean) => void
setStep: (step: StepEnum) => void
setTotalPrice: (totalPrice: Price) => void
toggleSummaryOpen: () => void
togglePriceDetailsModalOpen: () => void
@@ -45,40 +51,42 @@ export interface DetailsState {
updateDetails: (data: DetailsSchema) => void
updateSeachParamString: (searchParamString: string) => void
}
bedType: BedTypeSchema | undefined
booking: SelectRateSearchParams
breakfast: BreakfastPackage | false | undefined
currentStep: StepEnum
formValues: FormValues
guest: DetailsSchema
isSubmittingDisabled: boolean
isSummaryOpen: boolean
isPriceDetailsModalOpen: boolean
isValid: Record<StepEnum, boolean>
packages: Packages | null
roomRate: DetailsProviderProps["roomRate"]
roomPrice: RoomPrice
steps: StepEnum[]
rooms: RoomState[]
totalPrice: Price
searchParamString: string
vat: number
bookingProgress: BookingProgress
}
export type InitialState = Pick<DetailsState, "booking" | "packages"> &
Pick<DetailsProviderProps, "roomRate" | "vat"> & {
bedType?: BedTypeSchema
breakfast?: false
export type PersistedState = {
booking: SelectRateSearchParams
bookingProgress: BookingProgress
rooms: RoomState[]
}
export type RoomStep = {
step: StepEnum
isValid: boolean
}
export type RoomStatus = {
isComplete: boolean
currentStep: StepEnum | null
lastCompletedStep: StepEnum | undefined
steps: {
[StepEnum.selectBed]: RoomStep
[StepEnum.breakfast]?: RoomStep
[StepEnum.details]: RoomStep
}
}
export type RoomRate = DetailsProviderProps["roomRate"]
export type PersistedState = Pick<
DetailsState,
"bedType" | "booking" | "breakfast" | "guest"
>
export type PersistedStatePart =
| Pick<DetailsState, "bedType">
| Pick<DetailsState, "booking">
| Pick<DetailsState, "breakfast">
| Pick<DetailsState, "guest">
export type BookingProgress = {
currentRoomIndex: number
roomStatuses: RoomStatus[]
canProceedToPayment: boolean
}