fix: send correct values to create booking
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
export const bedTypeSchema = z.object({
|
export const bedTypeSchema = z.object({
|
||||||
description: z.string(),
|
bedType: z.object({ description: z.string(), roomTypeCode: z.string() }),
|
||||||
roomTypeCode: z.string(),
|
|
||||||
})
|
})
|
||||||
export const bedTypeFormSchema = z.object({
|
export const bedTypeFormSchema = z.object({
|
||||||
bedType: z.string(),
|
bedType: z.string(),
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
|
import { isValidPhoneNumber, parsePhoneNumber } from "libphonenumber-js"
|
||||||
import { useRouter, useSearchParams } from "next/navigation"
|
import { useRouter, useSearchParams } from "next/navigation"
|
||||||
import { useEffect, useMemo, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { Label as AriaLabel } from "react-aria-components"
|
import { Label as AriaLabel } from "react-aria-components"
|
||||||
import { FormProvider, useForm } from "react-hook-form"
|
import { FormProvider, useForm } from "react-hook-form"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
@@ -36,7 +37,9 @@ import { PaymentFormData, paymentSchema } from "./schema"
|
|||||||
|
|
||||||
import styles from "./payment.module.css"
|
import styles from "./payment.module.css"
|
||||||
|
|
||||||
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||||
import { PaymentProps } from "@/types/components/hotelReservation/selectRate/section"
|
import { PaymentProps } from "@/types/components/hotelReservation/selectRate/section"
|
||||||
|
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||||
|
|
||||||
const maxRetries = 40
|
const maxRetries = 40
|
||||||
const retryInterval = 2000
|
const retryInterval = 2000
|
||||||
@@ -55,8 +58,22 @@ export default function Payment({
|
|||||||
const lang = useLang()
|
const lang = useLang()
|
||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
const queryParams = useSearchParams()
|
const queryParams = useSearchParams()
|
||||||
const { firstName, lastName, email, phoneNumber, countryCode } =
|
const { userData, roomData } = useEnterDetailsStore((state) => ({
|
||||||
useEnterDetailsStore((state) => state.userData)
|
userData: state.userData,
|
||||||
|
roomData: state.roomData,
|
||||||
|
}))
|
||||||
|
|
||||||
|
const {
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
email,
|
||||||
|
phoneNumber,
|
||||||
|
countryCode,
|
||||||
|
breakfast,
|
||||||
|
bedType,
|
||||||
|
} = userData
|
||||||
|
const { toDate, fromDate, rooms: rooms, hotel } = roomData
|
||||||
|
|
||||||
const [confirmationNumber, setConfirmationNumber] = useState<string>("")
|
const [confirmationNumber, setConfirmationNumber] = useState<string>("")
|
||||||
|
|
||||||
const methods = useForm<PaymentFormData>({
|
const methods = useForm<PaymentFormData>({
|
||||||
@@ -114,34 +131,46 @@ export default function Payment({
|
|||||||
(card) => card.id === data.paymentMethod
|
(card) => card.id === data.paymentMethod
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let phone: string
|
||||||
|
let phoneCountryCodePrefix: string | null = null
|
||||||
|
|
||||||
|
if (isValidPhoneNumber(phoneNumber)) {
|
||||||
|
const parsedPhone = parsePhoneNumber(phoneNumber)
|
||||||
|
phone = parsedPhone.nationalNumber
|
||||||
|
phoneCountryCodePrefix = parsedPhone.countryCallingCode
|
||||||
|
} else {
|
||||||
|
phone = phoneNumber
|
||||||
|
}
|
||||||
|
|
||||||
initiateBooking.mutate({
|
initiateBooking.mutate({
|
||||||
hotelId: hotelId,
|
hotelId: hotelId,
|
||||||
checkInDate: "2024-12-10",
|
checkInDate: fromDate,
|
||||||
checkOutDate: "2024-12-11",
|
checkOutDate: toDate,
|
||||||
rooms: [
|
rooms: rooms.map((room) => ({
|
||||||
{
|
adults: room.adults,
|
||||||
adults: 1,
|
children: room.children,
|
||||||
childrenAges: [],
|
rateCode: room.rateCode,
|
||||||
rateCode: "SAVEEU",
|
roomTypeCode: bedType!.roomTypeCode,
|
||||||
roomTypeCode: "QC",
|
|
||||||
guest: {
|
guest: {
|
||||||
title: "Mr", // TODO: do we need title?
|
title: "", // TODO: do we need title?
|
||||||
firstName,
|
firstName,
|
||||||
lastName,
|
lastName,
|
||||||
email,
|
email,
|
||||||
phoneCountryCodePrefix: phoneNumber.slice(0, 3),
|
phoneCountryCodePrefix,
|
||||||
phoneNumber: phoneNumber.slice(3),
|
phoneNumber: phone,
|
||||||
countryCode,
|
countryCode,
|
||||||
},
|
},
|
||||||
packages: {
|
packages: {
|
||||||
breakfast: true,
|
breakfast: breakfast !== BreakfastPackageEnum.NO_BREAKFAST,
|
||||||
allergyFriendly: true,
|
allergyFriendly:
|
||||||
petFriendly: true,
|
room.packages?.includes(RoomPackageCodeEnum.ALLERGY_ROOM) ?? false,
|
||||||
accessibility: true,
|
petFriendly:
|
||||||
|
room.packages?.includes(RoomPackageCodeEnum.PET_ROOM) ?? false,
|
||||||
|
accessibility:
|
||||||
|
room.packages?.includes(RoomPackageCodeEnum.ALLERGY_ROOM) ?? false,
|
||||||
},
|
},
|
||||||
smsConfirmationRequested: data.smsConfirmation,
|
smsConfirmationRequested: data.smsConfirmation,
|
||||||
},
|
})),
|
||||||
],
|
|
||||||
payment: {
|
payment: {
|
||||||
paymentMethod,
|
paymentMethod,
|
||||||
card: savedCreditCard
|
card: savedCreditCard
|
||||||
@@ -151,12 +180,7 @@ export default function Payment({
|
|||||||
cardType: savedCreditCard.cardType,
|
cardType: savedCreditCard.cardType,
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
cardHolder: {
|
|
||||||
email: "test.user@scandichotels.com",
|
|
||||||
name: "Test User",
|
|
||||||
phoneCountryCode: "",
|
|
||||||
phoneSubscriber: "",
|
|
||||||
},
|
|
||||||
success: `${env.NEXT_PUBLIC_PAYMENT_CALLBACK_URL}/${lang}/success`,
|
success: `${env.NEXT_PUBLIC_PAYMENT_CALLBACK_URL}/${lang}/success`,
|
||||||
error: `${env.NEXT_PUBLIC_PAYMENT_CALLBACK_URL}/${lang}/error${allQueryParams}`,
|
error: `${env.NEXT_PUBLIC_PAYMENT_CALLBACK_URL}/${lang}/error${allQueryParams}`,
|
||||||
cancel: `${env.NEXT_PUBLIC_PAYMENT_CALLBACK_URL}/${lang}/cancel${allQueryParams}`,
|
cancel: `${env.NEXT_PUBLIC_PAYMENT_CALLBACK_URL}/${lang}/cancel${allQueryParams}`,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const roomsSchema = z.array(
|
|||||||
firstName: z.string(),
|
firstName: z.string(),
|
||||||
lastName: z.string(),
|
lastName: z.string(),
|
||||||
email: z.string().email(),
|
email: z.string().email(),
|
||||||
phoneCountryCodePrefix: z.string(),
|
phoneCountryCodePrefix: z.string().nullable(),
|
||||||
phoneNumber: z.string(),
|
phoneNumber: z.string(),
|
||||||
countryCode: z.string(),
|
countryCode: z.string(),
|
||||||
membershipNumber: z.string().optional(),
|
membershipNumber: z.string().optional(),
|
||||||
@@ -42,12 +42,14 @@ const paymentSchema = z.object({
|
|||||||
cardType: z.string(),
|
cardType: z.string(),
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
cardHolder: z.object({
|
cardHolder: z
|
||||||
|
.object({
|
||||||
email: z.string().email(),
|
email: z.string().email(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
phoneCountryCode: z.string(),
|
phoneCountryCode: z.string(),
|
||||||
phoneSubscriber: z.string(),
|
phoneSubscriber: z.string(),
|
||||||
}),
|
})
|
||||||
|
.optional(),
|
||||||
success: z.string(),
|
success: z.string(),
|
||||||
error: z.string(),
|
error: z.string(),
|
||||||
cancel: z.string(),
|
cancel: z.string(),
|
||||||
|
|||||||
@@ -19,4 +19,4 @@ export type BedTypeProps = {
|
|||||||
|
|
||||||
export interface BedTypeFormSchema extends z.output<typeof bedTypeFormSchema> {}
|
export interface BedTypeFormSchema extends z.output<typeof bedTypeFormSchema> {}
|
||||||
|
|
||||||
export interface BedTypeSchema extends z.output<typeof bedTypeSchema> {}
|
export type BedTypeSchema = z.output<typeof bedTypeSchema>["bedType"]
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
import { BedTypeEnum } from "../../bookingWidget/enums"
|
|
||||||
import { RoomPackageCodeEnum } from "../selectRate/roomFilter"
|
import { RoomPackageCodeEnum } from "../selectRate/roomFilter"
|
||||||
|
import { Child } from "../selectRate/selectRate"
|
||||||
interface Child {
|
|
||||||
bed: BedTypeEnum
|
|
||||||
age: number
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Room {
|
interface Room {
|
||||||
adults: number
|
adults: number
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ export interface BreakfastSelectionProps extends SectionProps {
|
|||||||
export interface DetailsProps extends SectionProps {}
|
export interface DetailsProps extends SectionProps {}
|
||||||
|
|
||||||
export interface PaymentProps {
|
export interface PaymentProps {
|
||||||
hotelId: string
|
|
||||||
otherPaymentOptions: string[]
|
otherPaymentOptions: string[]
|
||||||
savedCreditCards: CreditCard[] | null
|
savedCreditCards: CreditCard[] | null
|
||||||
mustBeGuaranteed: boolean
|
mustBeGuaranteed: boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user