fix: extend bedType to include discription and roomTypeCode
This commit is contained in:
@@ -3,45 +3,52 @@
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { useCallback, useEffect } from "react"
|
import { useCallback, useEffect } from "react"
|
||||||
import { FormProvider, useForm } from "react-hook-form"
|
import { FormProvider, useForm } from "react-hook-form"
|
||||||
import { useIntl } from "react-intl"
|
|
||||||
|
|
||||||
import { useEnterDetailsStore } from "@/stores/enter-details"
|
import { useEnterDetailsStore } from "@/stores/enter-details"
|
||||||
|
|
||||||
import { KingBedIcon } from "@/components/Icons"
|
import { KingBedIcon } from "@/components/Icons"
|
||||||
import RadioCard from "@/components/TempDesignSystem/Form/ChoiceCard/Radio"
|
import RadioCard from "@/components/TempDesignSystem/Form/ChoiceCard/Radio"
|
||||||
|
|
||||||
import { bedTypeSchema } from "./schema"
|
import { bedTypeFormSchema } from "./schema"
|
||||||
|
|
||||||
import styles from "./bedOptions.module.css"
|
import styles from "./bedOptions.module.css"
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
BedTypeFormSchema,
|
||||||
BedTypeProps,
|
BedTypeProps,
|
||||||
BedTypeSchema,
|
|
||||||
} from "@/types/components/hotelReservation/enterDetails/bedType"
|
} from "@/types/components/hotelReservation/enterDetails/bedType"
|
||||||
|
|
||||||
export default function BedType({ bedTypes }: BedTypeProps) {
|
export default function BedType({ bedTypes }: BedTypeProps) {
|
||||||
const intl = useIntl()
|
|
||||||
const bedType = useEnterDetailsStore((state) => state.userData.bedType)
|
const bedType = useEnterDetailsStore((state) => state.userData.bedType)
|
||||||
|
|
||||||
const methods = useForm<BedTypeSchema>({
|
const methods = useForm<BedTypeFormSchema>({
|
||||||
defaultValues: bedType
|
defaultValues: bedType?.roomTypeCode
|
||||||
? {
|
? {
|
||||||
bedType,
|
bedType: bedType.roomTypeCode,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
criteriaMode: "all",
|
criteriaMode: "all",
|
||||||
mode: "all",
|
mode: "all",
|
||||||
resolver: zodResolver(bedTypeSchema),
|
resolver: zodResolver(bedTypeFormSchema),
|
||||||
reValidateMode: "onChange",
|
reValidateMode: "onChange",
|
||||||
})
|
})
|
||||||
|
|
||||||
const completeStep = useEnterDetailsStore((state) => state.completeStep)
|
const completeStep = useEnterDetailsStore((state) => state.completeStep)
|
||||||
|
|
||||||
const onSubmit = useCallback(
|
const onSubmit = useCallback(
|
||||||
(values: BedTypeSchema) => {
|
(bedTypeRoomCode: BedTypeFormSchema) => {
|
||||||
completeStep(values)
|
const matchingRoom = bedTypes.find(
|
||||||
|
(roomType) => roomType.value === bedTypeRoomCode.bedType
|
||||||
|
)
|
||||||
|
if (matchingRoom) {
|
||||||
|
const bedType = {
|
||||||
|
description: matchingRoom.description,
|
||||||
|
roomTypeCode: matchingRoom.value,
|
||||||
|
}
|
||||||
|
completeStep({ bedType })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[completeStep]
|
[completeStep, bedTypes]
|
||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -70,7 +77,7 @@ export default function BedType({ bedTypes }: BedTypeProps) {
|
|||||||
name="bedType"
|
name="bedType"
|
||||||
subtitle={width}
|
subtitle={width}
|
||||||
title={roomType.description}
|
title={roomType.description}
|
||||||
value={roomType.description}
|
value={roomType.value}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import { BedTypeEnum } from "@/types/enums/bedType"
|
|
||||||
|
|
||||||
export const bedTypeSchema = z.object({
|
export const bedTypeSchema = z.object({
|
||||||
|
description: z.string(),
|
||||||
|
roomTypeCode: z.string(),
|
||||||
|
})
|
||||||
|
export const bedTypeFormSchema = z.object({
|
||||||
bedType: z.string(),
|
bedType: z.string(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export default function SectionAccordion({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (step === StepEnum.selectBed) {
|
if (step === StepEnum.selectBed) {
|
||||||
const value = stepData.bedType
|
const value = stepData.bedType
|
||||||
value && setTitle(value)
|
value && setTitle(value.description)
|
||||||
}
|
}
|
||||||
// If breakfast step, check if an option has been selected
|
// If breakfast step, check if an option has been selected
|
||||||
if (step === StepEnum.breakfast && stepData.breakfast) {
|
if (step === StepEnum.breakfast && stepData.breakfast) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { formatNumber } from "@/utils/format"
|
|||||||
|
|
||||||
import styles from "./summary.module.css"
|
import styles from "./summary.module.css"
|
||||||
|
|
||||||
|
import { BedTypeSchema } from "@/types/components/hotelReservation/enterDetails/bedType"
|
||||||
import { RoomsData } from "@/types/components/hotelReservation/enterDetails/bookingData"
|
import { RoomsData } from "@/types/components/hotelReservation/enterDetails/bookingData"
|
||||||
import { BreakfastPackage } from "@/types/components/hotelReservation/enterDetails/breakfast"
|
import { BreakfastPackage } from "@/types/components/hotelReservation/enterDetails/breakfast"
|
||||||
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||||
@@ -32,7 +33,7 @@ export default function Summary({
|
|||||||
showMemberPrice: boolean
|
showMemberPrice: boolean
|
||||||
room: RoomsData
|
room: RoomsData
|
||||||
}) {
|
}) {
|
||||||
const [chosenBed, setChosenBed] = useState<string>()
|
const [chosenBed, setChosenBed] = useState<BedTypeSchema>()
|
||||||
const [chosenBreakfast, setChosenBreakfast] = useState<
|
const [chosenBreakfast, setChosenBreakfast] = useState<
|
||||||
BreakfastPackage | BreakfastPackageEnum.NO_BREAKFAST
|
BreakfastPackage | BreakfastPackageEnum.NO_BREAKFAST
|
||||||
>()
|
>()
|
||||||
@@ -136,7 +137,7 @@ export default function Summary({
|
|||||||
{chosenBed ? (
|
{chosenBed ? (
|
||||||
<div className={styles.entry}>
|
<div className={styles.entry}>
|
||||||
<div>
|
<div>
|
||||||
<Body color="textHighContrast">{chosenBed}</Body>
|
<Body color="textHighContrast">{chosenBed.description}</Body>
|
||||||
<Caption color="uiTextMediumContrast">
|
<Caption color="uiTextMediumContrast">
|
||||||
{intl.formatMessage({ id: "Based on availability" })}
|
{intl.formatMessage({ id: "Based on availability" })}
|
||||||
</Caption>
|
</Caption>
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ import {
|
|||||||
} from "./utils"
|
} from "./utils"
|
||||||
|
|
||||||
import { FacilityCardTypeEnum } from "@/types/components/hotelPage/facilities"
|
import { FacilityCardTypeEnum } from "@/types/components/hotelPage/facilities"
|
||||||
import type { BedType } from "@/types/components/hotelReservation/enterDetails/bedType"
|
import type { BedTypeSelection } from "@/types/components/hotelReservation/enterDetails/bedType"
|
||||||
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel"
|
||||||
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||||
import type { RequestOptionsWithOutBody } from "@/types/fetch"
|
import type { RequestOptionsWithOutBody } from "@/types/fetch"
|
||||||
@@ -763,7 +763,7 @@ export const hotelQueryRouter = router({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.filter((bed): bed is BedType => Boolean(bed))
|
.filter((bed): bed is BedTypeSelection => Boolean(bed))
|
||||||
|
|
||||||
selectedRoomAvailabilitySuccessCounter.add(1, {
|
selectedRoomAvailabilitySuccessCounter.add(1, {
|
||||||
hotelId,
|
hotelId,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
getQueryParamsForEnterDetails,
|
getQueryParamsForEnterDetails,
|
||||||
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
|
|
||||||
|
import type { BedTypeSchema } from "@/types/components/hotelReservation/enterDetails/bedType"
|
||||||
import { BookingData } from "@/types/components/hotelReservation/enterDetails/bookingData"
|
import { BookingData } from "@/types/components/hotelReservation/enterDetails/bookingData"
|
||||||
import { BreakfastPackage } from "@/types/components/hotelReservation/enterDetails/breakfast"
|
import { BreakfastPackage } from "@/types/components/hotelReservation/enterDetails/breakfast"
|
||||||
import { DetailsSchema } from "@/types/components/hotelReservation/enterDetails/details"
|
import { DetailsSchema } from "@/types/components/hotelReservation/enterDetails/details"
|
||||||
@@ -24,7 +25,7 @@ const SESSION_STORAGE_KEY = "enterDetails"
|
|||||||
|
|
||||||
interface EnterDetailsState {
|
interface EnterDetailsState {
|
||||||
userData: {
|
userData: {
|
||||||
bedType: string | undefined
|
bedType: BedTypeSchema | undefined
|
||||||
breakfast: BreakfastPackage | BreakfastPackageEnum.NO_BREAKFAST | undefined
|
breakfast: BreakfastPackage | BreakfastPackageEnum.NO_BREAKFAST | undefined
|
||||||
} & DetailsSchema
|
} & DetailsSchema
|
||||||
roomData: BookingData
|
roomData: BookingData
|
||||||
@@ -35,7 +36,10 @@ interface EnterDetailsState {
|
|||||||
completeStep: (updatedData: Partial<EnterDetailsState["userData"]>) => void
|
completeStep: (updatedData: Partial<EnterDetailsState["userData"]>) => void
|
||||||
navigate: (
|
navigate: (
|
||||||
step: StepEnum,
|
step: StepEnum,
|
||||||
updatedData?: Record<string, string | boolean | BreakfastPackage>
|
updatedData?: Record<
|
||||||
|
string,
|
||||||
|
string | boolean | BreakfastPackage | BedTypeSchema
|
||||||
|
>
|
||||||
) => void
|
) => void
|
||||||
setCurrentStep: (step: StepEnum) => void
|
setCurrentStep: (step: StepEnum) => void
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import { bedTypeSchema } from "@/components/HotelReservation/EnterDetails/BedType/schema"
|
import {
|
||||||
|
bedTypeFormSchema,
|
||||||
|
bedTypeSchema,
|
||||||
|
} from "@/components/HotelReservation/EnterDetails/BedType/schema"
|
||||||
|
|
||||||
export type BedType = {
|
export type BedTypeSelection = {
|
||||||
description: string
|
description: string
|
||||||
size: {
|
size: {
|
||||||
min: number
|
min: number
|
||||||
@@ -11,7 +14,9 @@ export type BedType = {
|
|||||||
value: string
|
value: string
|
||||||
}
|
}
|
||||||
export type BedTypeProps = {
|
export type BedTypeProps = {
|
||||||
bedTypes: BedType[]
|
bedTypes: BedTypeSelection[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BedTypeFormSchema extends z.output<typeof bedTypeFormSchema> {}
|
||||||
|
|
||||||
export interface BedTypeSchema extends z.output<typeof bedTypeSchema> {}
|
export interface BedTypeSchema extends z.output<typeof bedTypeSchema> {}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
export enum BedTypeEnum {
|
|
||||||
KING = "KING",
|
|
||||||
QUEEN = "QUEEN",
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user