chore: Cleanup booking widget with types and other minor issues

This commit is contained in:
Christian Andolf
2025-04-02 10:06:28 +02:00
parent 3c810d67a2
commit 14f9b68365
9 changed files with 92 additions and 98 deletions

View File

@@ -27,21 +27,23 @@ export default function MobileToggleButton({
}: BookingWidgetToggleButtonProps) {
const intl = useIntl()
const lang = useLang()
const d = useWatch({ name: "date" })
const location = useWatch({ name: "location" })
const rooms: BookingWidgetSchema["rooms"] = useWatch({ name: "rooms" })
const date = useWatch<BookingWidgetSchema, "date">({ name: "date" })
const location = useWatch<BookingWidgetSchema, "location">({
name: "location",
})
const rooms = useWatch<BookingWidgetSchema, "rooms">({ name: "rooms" })
const parsedLocation: Location | null =
location && isValidJson(location)
? JSON.parse(decodeURIComponent(location))
: null
const selectedFromDate = dt(d.fromDate).locale(lang).format("D MMM")
const selectedToDate = dt(d.toDate).locale(lang).format("D MMM")
const selectedFromDate = dt(date.fromDate).locale(lang).format("D MMM")
const selectedToDate = dt(date.toDate).locale(lang).format("D MMM")
const locationAndDateIsSet = parsedLocation && d
const locationAndDateIsSet = parsedLocation && date
const totalNights = dt(d.toDate).diff(dt(d.fromDate), "days")
const totalNights = dt(date.toDate).diff(dt(date.fromDate), "days")
const totalRooms = rooms.length
const totalAdults = rooms.reduce((acc, room) => {
if (room.adults) {