fix: send totalPrice to create booking

This commit is contained in:
Christel Westerberg
2024-11-06 14:09:18 +01:00
parent f4f771ec70
commit 560fb25aee
6 changed files with 23 additions and 24 deletions

View File

@@ -96,6 +96,11 @@ export default async function StepPage({
id: "Select payment method", id: "Select payment method",
}) })
const roomPrice =
user && roomAvailability.memberRate
? roomAvailability.memberRate?.localPrice.pricePerStay
: roomAvailability.publicRate!.localPrice.pricePerStay
return ( return (
<section> <section>
<HistoryStateManager /> <HistoryStateManager />
@@ -136,6 +141,7 @@ export default async function StepPage({
label={mustBeGuaranteed ? guaranteeWithCard : selectPaymentMethod} label={mustBeGuaranteed ? guaranteeWithCard : selectPaymentMethod}
> >
<Payment <Payment
roomPrice={roomPrice}
otherPaymentOptions={ otherPaymentOptions={
hotelData.data.attributes.merchantInformationData hotelData.data.attributes.merchantInformationData
.alternatePaymentOptions .alternatePaymentOptions

View File

@@ -4,13 +4,15 @@ import { env } from "@/env/server"
import { getLocations } from "@/lib/trpc/memoizedRequests" import { getLocations } from "@/lib/trpc/memoizedRequests"
import SelectHotelMap from "@/components/HotelReservation/SelectHotel/SelectHotelMap" import SelectHotelMap from "@/components/HotelReservation/SelectHotel/SelectHotelMap"
import { getHotelReservationQueryParams } from "@/components/HotelReservation/SelectRate/RoomSelection/utils" import {
generateChildrenString,
getHotelReservationQueryParams,
} from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
import { MapModal } from "@/components/MapModal" import { MapModal } from "@/components/MapModal"
import { setLang } from "@/i18n/serverContext" import { setLang } from "@/i18n/serverContext"
import { import {
fetchAvailableHotels, fetchAvailableHotels,
generateChildrenString,
getCentralCoordinates, getCentralCoordinates,
getPointOfInterests, getPointOfInterests,
} from "../../utils" } from "../../utils"

View File

@@ -3,7 +3,7 @@ import { serverClient } from "@/lib/trpc/server"
import { getLang } from "@/i18n/serverContext" import { getLang } from "@/i18n/serverContext"
import { BedTypeEnum } from "@/types/components/bookingWidget/enums" import { ChildBedMapEnum } from "@/types/components/bookingWidget/enums"
import type { AvailabilityInput } from "@/types/components/hotelReservation/selectHotel/availabilityInput" import type { AvailabilityInput } from "@/types/components/hotelReservation/selectHotel/availabilityInput"
import type { HotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps" import type { HotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
import type { Filter } from "@/types/components/hotelReservation/selectHotel/hotelFilters" import type { Filter } from "@/types/components/hotelReservation/selectHotel/hotelFilters"
@@ -50,22 +50,6 @@ export function getFiltersFromHotels(hotels: HotelData[]) {
return filterList return filterList
} }
const bedTypeMap: Record<number, string> = {
[BedTypeEnum.IN_ADULTS_BED]: "ParentsBed",
[BedTypeEnum.IN_CRIB]: "Crib",
[BedTypeEnum.IN_EXTRA_BED]: "ExtraBed",
}
export function generateChildrenString(children: Child[]): string {
return `[${children
?.map((child) => {
const age = child.age
const bedType = bedTypeMap[+child.bed]
return `${age}:${bedType}`
})
.join(",")}]`
}
export function getPointOfInterests(hotels: HotelData[]): PointOfInterest[] { export function getPointOfInterests(hotels: HotelData[]): PointOfInterest[] {
// TODO: this is just a quick transformation to get something there. May need rework // TODO: this is just a quick transformation to get something there. May need rework
return hotels.map((hotel) => ({ return hotels.map((hotel) => ({

View File

@@ -31,6 +31,7 @@ import { toast } from "@/components/TempDesignSystem/Toasts"
import { useHandleBookingStatus } from "@/hooks/booking/useHandleBookingStatus" import { useHandleBookingStatus } from "@/hooks/booking/useHandleBookingStatus"
import useLang from "@/hooks/useLang" import useLang from "@/hooks/useLang"
import { bedTypeMap } from "../../SelectRate/RoomSelection/utils"
import GuaranteeDetails from "./GuaranteeDetails" import GuaranteeDetails from "./GuaranteeDetails"
import PaymentOption from "./PaymentOption" import PaymentOption from "./PaymentOption"
import { PaymentFormData, paymentSchema } from "./schema" import { PaymentFormData, paymentSchema } from "./schema"
@@ -49,7 +50,7 @@ function isPaymentMethodEnum(value: string): value is PaymentMethodEnum {
} }
export default function Payment({ export default function Payment({
hotelId, roomPrice,
otherPaymentOptions, otherPaymentOptions,
savedCreditCards, savedCreditCards,
mustBeGuaranteed, mustBeGuaranteed,
@@ -143,16 +144,19 @@ export default function Payment({
} }
initiateBooking.mutate({ initiateBooking.mutate({
hotelId: hotelId, hotelId: hotel,
checkInDate: fromDate, checkInDate: fromDate,
checkOutDate: toDate, checkOutDate: toDate,
rooms: rooms.map((room) => ({ rooms: rooms.map((room) => ({
adults: room.adults, adults: room.adults,
children: room.children, childrenAges: room.children?.map((child) => ({
age: child.age,
bedType: bedTypeMap[parseInt(child.bed.toString())],
})),
rateCode: room.rateCode, rateCode: room.rateCode,
roomTypeCode: bedType!.roomTypeCode, roomTypeCode: bedType!.roomTypeCode, // A selection has been made in order to get to this step.
guest: { guest: {
title: "", // TODO: do we need title? title: "",
firstName, firstName,
lastName, lastName,
email, email,
@@ -170,6 +174,7 @@ export default function Payment({
room.packages?.includes(RoomPackageCodeEnum.ALLERGY_ROOM) ?? false, room.packages?.includes(RoomPackageCodeEnum.ALLERGY_ROOM) ?? false,
}, },
smsConfirmationRequested: data.smsConfirmation, smsConfirmationRequested: data.smsConfirmation,
roomPrice,
})), })),
payment: { payment: {
paymentMethod, paymentMethod,

View File

@@ -32,6 +32,7 @@ const roomsSchema = z.array(
petFriendly: z.boolean(), petFriendly: z.boolean(),
accessibility: z.boolean(), accessibility: z.boolean(),
}), }),
roomPrice: z.number().or(z.string().transform((val) => Number(val))),
}) })
) )

View File

@@ -28,6 +28,7 @@ export interface BreakfastSelectionProps extends SectionProps {
export interface DetailsProps extends SectionProps {} export interface DetailsProps extends SectionProps {}
export interface PaymentProps { export interface PaymentProps {
roomPrice: string
otherPaymentOptions: string[] otherPaymentOptions: string[]
savedCreditCards: CreditCard[] | null savedCreditCards: CreditCard[] | null
mustBeGuaranteed: boolean mustBeGuaranteed: boolean