From 0294a80eabce73ad9383db7901fe291c7aa09d11 Mon Sep 17 00:00:00 2001 From: Pontus Dreij Date: Wed, 6 Nov 2024 10:04:59 +0100 Subject: [PATCH 1/2] fix(SW-449): Updated Date format to match current web --- .../hotelreservation/(standard)/select-rate/page.tsx | 4 ++-- components/BookingWidget/Client.tsx | 8 ++++---- components/Forms/BookingWidget/index.tsx | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-rate/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-rate/page.tsx index 816c937ae..99554d1c1 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-rate/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-rate/page.tsx @@ -49,11 +49,11 @@ export default async function SelectRatePage({ searchParams.fromDate && dt(searchParams.fromDate).isAfter(dt().subtract(1, "day")) ? searchParams.fromDate - : dt().utc().format("YYYY-MM-DD") + : dt().utc().format("YYYY-MM-D") const validToDate = searchParams.toDate && dt(searchParams.toDate).isAfter(validFromDate) ? searchParams.toDate - : dt().utc().add(1, "day").format("YYYY-MM-DD") + : dt().utc().add(1, "day").format("YYYY-MM-D") const adults = selectRoomParamsObject.room[0].adults || 1 // TODO: Handle multiple rooms const childrenCount = selectRoomParamsObject.room[0].child?.length const children = selectRoomParamsObject.room[0].child diff --git a/components/BookingWidget/Client.tsx b/components/BookingWidget/Client.tsx index 95f113242..70daa6a20 100644 --- a/components/BookingWidget/Client.tsx +++ b/components/BookingWidget/Client.tsx @@ -86,11 +86,11 @@ export default function BookingWidgetClient({ // UTC is required to handle requests from far away timezones https://scandichotels.atlassian.net/browse/SWAP-6375 & PET-507 // This is specifically to handle timezones falling in different dates. fromDate: isDateParamValid - ? bookingWidgetSearchData?.fromDate?.toString() - : dt().utc().format("YYYY-MM-DD"), + ? dt(bookingWidgetSearchData?.fromDate).format("YYYY-M-D") + : dt().utc().format("YYYY-M-D"), toDate: isDateParamValid - ? bookingWidgetSearchData?.toDate?.toString() - : dt().utc().add(1, "day").format("YYYY-MM-DD"), + ? dt(bookingWidgetSearchData?.toDate).format("YYYY-M-D") + : dt().utc().add(1, "day").format("YYYY-M-D"), }, bookingCode: "", redemption: false, diff --git a/components/Forms/BookingWidget/index.tsx b/components/Forms/BookingWidget/index.tsx index 731e17033..6c78ea341 100644 --- a/components/Forms/BookingWidget/index.tsx +++ b/components/Forms/BookingWidget/index.tsx @@ -25,8 +25,7 @@ export default function Form({ locations, type }: BookingWidgetFormProps) { type, }) - const { formState, handleSubmit, register } = - useFormContext() + const { handleSubmit, register } = useFormContext() function onSubmit(data: BookingWidgetSchema) { const locationData: Location = JSON.parse(decodeURIComponent(data.location)) From 42e5da1ee0f8c09ae7720aecc6d2a9252f956ac4 Mon Sep 17 00:00:00 2001 From: Pontus Dreij Date: Fri, 8 Nov 2024 15:13:24 +0100 Subject: [PATCH 2/2] fix(SW-449): Updated next.config date rule --- components/DatePicker/index.tsx | 10 ++++------ components/TempDesignSystem/Form/Date/index.tsx | 2 +- next.config.js | 4 ++-- server/routers/hotels/query.ts | 5 ++--- 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/components/DatePicker/index.tsx b/components/DatePicker/index.tsx index 962a8fc96..ca4fec3bd 100644 --- a/components/DatePicker/index.tsx +++ b/components/DatePicker/index.tsx @@ -47,7 +47,7 @@ export default function DatePickerForm({ name = "date" }: DatePickerFormProps) { if (!dt(selected).isBefore(dt(), "day")) { if (isSelectingFrom) { setValue(name, { - fromDate: dt(selected).format("YYYY-MM-DD"), + fromDate: dt(selected).format("YYYY-MM-D"), toDate: undefined, }) setIsSelectingFrom(false) @@ -57,11 +57,11 @@ export default function DatePickerForm({ name = "date" }: DatePickerFormProps) { if (toDate.isAfter(fromDate)) { setValue(name, { fromDate: selectedDate.fromDate, - toDate: toDate.format("YYYY-MM-DD"), + toDate: toDate.format("YYYY-MM-D"), }) } else { setValue(name, { - fromDate: toDate.format("YYYY-MM-DD"), + fromDate: toDate.format("YYYY-MM-D"), toDate: selectedDate.fromDate, }) } @@ -75,9 +75,7 @@ export default function DatePickerForm({ name = "date" }: DatePickerFormProps) { if (!selectedDate.toDate) { setValue(name, { fromDate: selectedDate.fromDate, - toDate: dt(selectedDate.fromDate) - .add(1, "day") - .format("YYYY-MM-DD"), + toDate: dt(selectedDate.fromDate).add(1, "day").format("YYYY-MM-D"), }) setIsSelectingFrom(true) } diff --git a/components/TempDesignSystem/Form/Date/index.tsx b/components/TempDesignSystem/Form/Date/index.tsx index 4e8f4a7af..3712cb94b 100644 --- a/components/TempDesignSystem/Form/Date/index.tsx +++ b/components/TempDesignSystem/Form/Date/index.tsx @@ -83,7 +83,7 @@ export default function DateSelect({ name, registerOptions = {} }: DateProps) { .date(Number(day)) if (newDate.isValid()) { - setValue(name, newDate.format("YYYY-MM-DD"), { + setValue(name, newDate.format("YYYY-MM-D"), { shouldDirty: true, shouldTouch: true, shouldValidate: true, diff --git a/next.config.js b/next.config.js index 2e8553f1c..c65772ab7 100644 --- a/next.config.js +++ b/next.config.js @@ -137,7 +137,7 @@ const nextConfig = { { key: "fromDate", type: "query", - value: "^([12]\\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01]))$", + value: "^([12]\\d{3}-(0[1-9]|1[0-2])-([1-9]|[12]\\d|3[01]))$", }, ], permanent: false, @@ -169,7 +169,7 @@ const nextConfig = { { key: "toDate", type: "query", - value: "^([12]\\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01]))$", + value: "^([12]\\d{3}-(0[1-9]|1[0-2])-([1-9]|[12]\\d|3[01]))$", }, ], permanent: false, diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index 39771b1c8..882eefb6b 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -974,11 +974,10 @@ export const hotelQueryRouter = router({ const { lang } = ctx const apiLang = toApiLang(lang) - const params = { Adults: input.adults, - EndDate: dt(input.toDate).format("YYYY-MM-DD"), - StartDate: dt(input.fromDate).format("YYYY-MM-DD"), + EndDate: dt(input.toDate).format("YYYY-MM-D"), + StartDate: dt(input.fromDate).format("YYYY-MM-D"), language: apiLang, }