feat(sw-452): updated typing on util
This commit is contained in:
@@ -2,6 +2,7 @@ import { getProfileSafely } from "@/lib/trpc/memoizedRequests"
|
|||||||
import { serverClient } from "@/lib/trpc/server"
|
import { serverClient } from "@/lib/trpc/server"
|
||||||
|
|
||||||
import RoomSelection from "@/components/HotelReservation/SelectRate/RoomSelection"
|
import RoomSelection from "@/components/HotelReservation/SelectRate/RoomSelection"
|
||||||
|
import getHotelReservationQueryParams from "@/components/HotelReservation/SelectRate/RoomSelection/utils"
|
||||||
import { setLang } from "@/i18n/serverContext"
|
import { setLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
import styles from "./page.module.css"
|
import styles from "./page.module.css"
|
||||||
@@ -15,8 +16,10 @@ export default async function SelectRatePage({
|
|||||||
}: PageArgs<LangParams & { section: string }, SelectRateSearchParams>) {
|
}: PageArgs<LangParams & { section: string }, SelectRateSearchParams>) {
|
||||||
setLang(params.lang)
|
setLang(params.lang)
|
||||||
|
|
||||||
const roomParams = new URLSearchParams(searchParams)
|
const selecetRoomParams = new URLSearchParams(searchParams)
|
||||||
const adults = roomParams.get("room[0].adults") || "1" // Default to '1' if not found
|
const selecetRoomParamsObject =
|
||||||
|
getHotelReservationQueryParams(selecetRoomParams)
|
||||||
|
const adults = selecetRoomParamsObject.room[0].adults // TODO: Handle multiple rooms
|
||||||
|
|
||||||
const [hotelData, roomConfigurations, user] = await Promise.all([
|
const [hotelData, roomConfigurations, user] = await Promise.all([
|
||||||
serverClient().hotel.hotelData.get({
|
serverClient().hotel.hotelData.get({
|
||||||
@@ -28,7 +31,7 @@ export default async function SelectRatePage({
|
|||||||
hotelId: parseInt(searchParams.hotel, 10),
|
hotelId: parseInt(searchParams.hotel, 10),
|
||||||
roomStayStartDate: searchParams.fromDate,
|
roomStayStartDate: searchParams.fromDate,
|
||||||
roomStayEndDate: searchParams.toDate,
|
roomStayEndDate: searchParams.toDate,
|
||||||
adults: parseInt(adults, 10),
|
adults: adults,
|
||||||
}),
|
}),
|
||||||
getProfileSafely(),
|
getProfileSafely(),
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ export default function FlexibilityOption({
|
|||||||
|
|
||||||
function onChange() {
|
function onChange() {
|
||||||
const rate = {
|
const rate = {
|
||||||
roomTypeCode: roomTypeCode,
|
roomTypeCode,
|
||||||
roomType: roomType,
|
roomType,
|
||||||
priceName: name,
|
priceName: name,
|
||||||
public: publicPrice,
|
public: publicPrice,
|
||||||
member: memberPrice,
|
member: memberPrice,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useState } from "react"
|
|||||||
|
|
||||||
import RateSummary from "./RateSummary"
|
import RateSummary from "./RateSummary"
|
||||||
import RoomCard from "./RoomCard"
|
import RoomCard from "./RoomCard"
|
||||||
import { getHotelReservationQueryParams } from "./utils"
|
import getHotelReservationQueryParams from "./utils"
|
||||||
|
|
||||||
import styles from "./roomSelection.module.css"
|
import styles from "./roomSelection.module.css"
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,28 @@
|
|||||||
import { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
import { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||||
|
|
||||||
function getHotelReservationQueryParams(searchParams: URLSearchParams) {
|
function getHotelReservationQueryParams(searchParams: URLSearchParams) {
|
||||||
const searchParamsObject: SelectRateSearchParams = Array.from(
|
const searchParamsObject: Record<string, unknown> = Array.from(
|
||||||
searchParams.entries()
|
searchParams.entries()
|
||||||
).reduce((acc, [key, value]) => {
|
).reduce<Record<string, unknown>>(
|
||||||
const keys = key.replace(/\]/g, "").split(/\[|\./) // Split keys by '[' or '.'
|
(acc, [key, value]) => {
|
||||||
keys.reduce((nestedAcc, k, i) => {
|
const keys = key.replace(/\]/g, "").split(/\[|\./) // Split keys by '[' or '.'
|
||||||
if (i === keys.length - 1) {
|
keys.reduce((nestedAcc, k, i) => {
|
||||||
nestedAcc[k] = value // Assign value at the last key
|
if (i === keys.length - 1) {
|
||||||
} else {
|
// Convert value to number if the key is 'adults' or 'age'
|
||||||
if (!nestedAcc[k]) {
|
;(nestedAcc as Record<string, unknown>)[k] =
|
||||||
nestedAcc[k] = isNaN(Number(keys[i + 1])) ? {} : [] // Initialize as array or object
|
k === "adults" || k === "age" ? Number(value) : value
|
||||||
|
} else {
|
||||||
|
if (!nestedAcc[k]) {
|
||||||
|
nestedAcc[k] = isNaN(Number(keys[i + 1])) ? {} : [] // Initialize as object or array
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return nestedAcc[k] as Record<string, unknown>
|
||||||
return nestedAcc[k]
|
}, acc)
|
||||||
}, acc)
|
return acc
|
||||||
return acc
|
},
|
||||||
}, {} as SelectRateSearchParams)
|
{} as Record<string, unknown>
|
||||||
return searchParamsObject
|
)
|
||||||
|
return searchParamsObject as SelectRateSearchParams
|
||||||
}
|
}
|
||||||
|
|
||||||
export { getHotelReservationQueryParams }
|
export default getHotelReservationQueryParams
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export interface SelectRateSearchParams {
|
|||||||
fromdate: string
|
fromdate: string
|
||||||
todate: string
|
todate: string
|
||||||
room: Room[]
|
room: Room[]
|
||||||
[key: string]: any
|
[key: string]: string | string[] | Room[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Rate {
|
export interface Rate {
|
||||||
|
|||||||
Reference in New Issue
Block a user