diff --git a/app/[lang]/(live)/(public)/hotelreservation/[section]/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/[section]/page.tsx index b3ef81538..3ebb491e5 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/[section]/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/[section]/page.tsx @@ -1,11 +1,12 @@ import { notFound } from "next/navigation" +import { getProfileSafely } from "@/lib/trpc/memoizedRequests" import { serverClient } from "@/lib/trpc/server" +import Details from "@/components/HotelReservation/EnterDetails/Details" import HotelSelectionHeader from "@/components/HotelReservation/HotelSelectionHeader" import BedSelection from "@/components/HotelReservation/SelectRate/BedSelection" import BreakfastSelection from "@/components/HotelReservation/SelectRate/BreakfastSelection" -import Details from "@/components/HotelReservation/SelectRate/Details" import Payment from "@/components/HotelReservation/SelectRate/Payment" import RoomSelection from "@/components/HotelReservation/SelectRate/RoomSelection" import SectionAccordion from "@/components/HotelReservation/SelectRate/SectionAccordion" @@ -79,6 +80,7 @@ export default async function SectionsPage({ searchParams, }: PageArgs) { setLang(params.lang) + const profile = await getProfileSafely() const hotel = await serverClient().hotel.hotelData.get({ hotelId: "811", @@ -114,6 +116,11 @@ export default async function SectionsPage({ const currentSearchParams = new URLSearchParams(searchParams).toString() + let user = null + if (profile && !("error" in profile)) { + user = profile + } + return (
@@ -171,7 +178,7 @@ export default async function SectionsPage({ header={intl.formatMessage({ id: "Your details" })} path={`details?${currentSearchParams}`} > - {params.section === "details" &&
} + {params.section === "details" ?
: null} diff --git a/components/Forms/BookingWidget/FormContent/Search/SearchList/index.tsx b/components/Forms/BookingWidget/FormContent/Search/SearchList/index.tsx index 2bbc3b43d..a8736e69d 100644 --- a/components/Forms/BookingWidget/FormContent/Search/SearchList/index.tsx +++ b/components/Forms/BookingWidget/FormContent/Search/SearchList/index.tsx @@ -20,6 +20,7 @@ import type { SearchListProps } from "@/types/components/search" export default function SearchList({ getItemProps, getMenuProps, + handleClearSearchHistory, highlightedIndex, isOpen, locations, @@ -125,6 +126,7 @@ export default function SearchList({ @@ -161,6 +163,7 @@ export default function SearchList({ diff --git a/components/Forms/BookingWidget/FormContent/Search/index.tsx b/components/Forms/BookingWidget/FormContent/Search/index.tsx index 1ce969a29..353c2807b 100644 --- a/components/Forms/BookingWidget/FormContent/Search/index.tsx +++ b/components/Forms/BookingWidget/FormContent/Search/index.tsx @@ -43,6 +43,11 @@ export default function Search({ locations }: SearchProps) { [locations] ) + function handleClearSearchHistory() { + localStorage.removeItem(localStorageKey) + dispatch({ type: ActionType.CLEAR_HISTORY_LOCATIONS }) + } + function handleOnBlur() { if (!value && state.searchData?.name) { setValue(name, state.searchData.name) @@ -79,11 +84,8 @@ export default function Search({ locations }: SearchProps) { } } - function handleOnSelect(selectedItem: Location | null | "clear-search") { - if (selectedItem === "clear-search") { - localStorage.removeItem(localStorageKey) - dispatch({ type: ActionType.CLEAR_HISTORY_LOCATIONS }) - } else if (selectedItem) { + function handleOnSelect(selectedItem: Location | null) { + if (selectedItem) { const stringified = JSON.stringify(selectedItem) setValue("location", encodeURIComponent(stringified)) sessionStorage.setItem(sessionStorageKey, stringified) @@ -167,6 +169,7 @@ export default function Search({ locations }: SearchProps) { ({ + defaultValues: { + countryCode: user?.address?.countryCode ?? "", + email: user?.email ?? "", + firstname: user?.firstName ?? "", + lastname: user?.lastName ?? "", + phoneNumber: user?.phoneNumber ?? "", + }, + mode: "all", + resolver: zodResolver(user ? signedInDetailsSchema : detailsSchema), + reValidateMode: "onChange", + }) + + return ( + +
+
+ + {intl.formatMessage({ id: "Guest information" })} + +
+
+ + + + + + +
+ {user ? null : ( + + )} + +
+
+
+ ) +} diff --git a/components/HotelReservation/EnterDetails/Details/schema.ts b/components/HotelReservation/EnterDetails/Details/schema.ts new file mode 100644 index 000000000..92f1a5629 --- /dev/null +++ b/components/HotelReservation/EnterDetails/Details/schema.ts @@ -0,0 +1,19 @@ +import { z } from "zod" + +import { phoneValidator } from "@/utils/phoneValidator" + +export const detailsSchema = z.object({ + countryCode: z.string(), + email: z.string().email(), + firstname: z.string(), + lastname: z.string(), + phoneNumber: phoneValidator(), +}) + +export const signedInDetailsSchema = z.object({ + countryCode: z.string().optional(), + email: z.string().email().optional(), + firstname: z.string().optional(), + lastname: z.string().optional(), + phoneNumber: phoneValidator().optional(), +}) diff --git a/components/HotelReservation/HotelCard/index.tsx b/components/HotelReservation/HotelCard/index.tsx index 82b0c4b91..99feb01ab 100644 --- a/components/HotelReservation/HotelCard/index.tsx +++ b/components/HotelReservation/HotelCard/index.tsx @@ -48,10 +48,10 @@ export default async function HotelCard({ hotel }: HotelCardProps) { {hotelData.name} - + {`${hotelData.address.streetAddress}, ${hotelData.address.city}`} - + {`${hotelData.location.distanceToCentre} ${intl.formatMessage({ id: "km to city center" })}`} @@ -79,7 +79,7 @@ export default async function HotelCard({ hotel }: HotelCardProps) { {price?.regularAmount} {price?.currency} / {intl.formatMessage({ id: "night" })} - approx 280 eur + approx 280 eur
@@ -90,7 +90,7 @@ export default async function HotelCard({ hotel }: HotelCardProps) { {price?.memberAmount} {price?.currency} / {intl.formatMessage({ id: "night" })} - approx 280 eur + approx 280 eur