Feat/SW-454 Create select rate page foundation * Extract select-rate page to its own, fixed route * Rename availability to hotelsAvailability * Update availability hotels response * Number to string Approved-by: Pontus Dreij
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
"use client"
|
|
import { useRouter, useSearchParams } from "next/navigation"
|
|
|
|
import RoomCard from "./RoomCard"
|
|
|
|
import styles from "./roomSelection.module.css"
|
|
|
|
import { RoomSelectionProps } from "@/types/components/hotelReservation/selectRate/roomSelection"
|
|
|
|
export default function RoomSelection({
|
|
rates,
|
|
nrOfNights,
|
|
nrOfAdults,
|
|
}: RoomSelectionProps) {
|
|
const router = useRouter()
|
|
const searchParams = useSearchParams()
|
|
|
|
function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
|
e.preventDefault()
|
|
const queryParams = new URLSearchParams(searchParams)
|
|
queryParams.set("roomClass", e.currentTarget.roomClass?.value)
|
|
queryParams.set("flexibility", e.currentTarget.flexibility?.value)
|
|
router.push(`select-bed?${queryParams}`)
|
|
}
|
|
|
|
return (
|
|
<div className={styles.wrapper}>
|
|
<ul className={styles.roomList}>
|
|
{rates.map((room) => (
|
|
<li key={room.id}>
|
|
<form
|
|
method="GET"
|
|
action={`select-bed?${searchParams}`}
|
|
onSubmit={handleSubmit}
|
|
>
|
|
<input
|
|
type="hidden"
|
|
name="roomClass"
|
|
value={room.id}
|
|
id={`room-${room.id}`}
|
|
/>
|
|
<RoomCard
|
|
room={room}
|
|
nrOfAdults={nrOfAdults}
|
|
nrOfNights={nrOfNights}
|
|
breakfastIncluded={room.breakfastIncluded}
|
|
/>
|
|
</form>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
<div className={styles.summary}>This is summary</div>
|
|
</div>
|
|
)
|
|
}
|