Fix/book 149 incorrect onfocus behaviour booking widget * fix(BOOK-149): fixed labels shifting * fix(BOOK-149): reintroduced sticky position * fix(BOOK-149): added missing border to "where" text field * added overflow to datepicker * comment fixes * removed separate typography declaration * changed to onPress * fix(BOOK-149): moved components to separate files * fix(BOOK-149): removed desktop & mobile specific css classes * fix(BOOK-149): new implementation of date and room modals * dependencies update * fix(BOOK-149): fixed child age dropdown issue, related error message, and Rooms & Guests container height * updated info button to new variant * fix(BOOK-149): prevent scrolling of background when modals are open in Tablet mode * fixed overlay issue and added focus indicator on mobile * fixed missing space in css * rebase and fixed icon buttons after update * simplified to use explicit boolean * PR comments fixes * more PR comment fixes * PR comment fixes * fixed setIsOpen((prev) => !prev) * fixed issues with room error not showing properly on mobile * fixing pr comments * fixed flickering on GuestRoomModal Approved-by: Erik Tiekstra
137 lines
4.3 KiB
TypeScript
137 lines
4.3 KiB
TypeScript
"use client"
|
|
|
|
import { useState } from "react"
|
|
import { type DateRange, DayPicker } from "react-day-picker"
|
|
import { useIntl } from "react-intl"
|
|
|
|
import { Lang } from "@scandic-hotels/common/constants/language"
|
|
import { dt } from "@scandic-hotels/common/dt"
|
|
import { Button } from "@scandic-hotels/design-system/Button"
|
|
import { Divider } from "@scandic-hotels/design-system/Divider"
|
|
import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon"
|
|
import { Typography } from "@scandic-hotels/design-system/Typography"
|
|
|
|
import useLang from "../../../../hooks/useLang"
|
|
import { locales } from "../locales"
|
|
|
|
import styles from "./desktop.module.css"
|
|
import classNames from "react-day-picker/style.module.css"
|
|
|
|
type DatePickerRangeProps = {
|
|
close: () => void
|
|
startMonth?: Date
|
|
hideHeader?: boolean
|
|
selectedRange: DateRange | undefined
|
|
handleOnSelect: (nextRange: DateRange | undefined, selectedDay: Date) => void
|
|
}
|
|
|
|
export default function DatePickerRangeDesktop({
|
|
close,
|
|
handleOnSelect,
|
|
selectedRange,
|
|
}: DatePickerRangeProps) {
|
|
const lang = useLang()
|
|
const intl = useIntl()
|
|
const [month, setMonth] = useState(selectedRange?.from ?? new Date())
|
|
|
|
/** English is default language and doesn't need to be imported */
|
|
const locale = lang === Lang.en ? undefined : locales[lang]
|
|
const currentDate = dt().toDate()
|
|
const lastDayOfPreviousMonth = dt(currentDate)
|
|
.set("date", 1)
|
|
.subtract(1, "day")
|
|
.toDate()
|
|
const yesterday = dt(currentDate).subtract(1, "day").toDate()
|
|
|
|
// Max future date allowed to book kept same as of existing prod.
|
|
const endDate = dt(currentDate).add(395, "day").toDate()
|
|
const endOfLastMonth = dt(endDate).endOf("month").toDate()
|
|
|
|
function handleMonthChange(selected: Date) {
|
|
setMonth(selected)
|
|
}
|
|
return (
|
|
<DayPicker
|
|
classNames={{
|
|
...classNames,
|
|
caption_label: `${classNames.caption_label} ${styles.captionLabel}`,
|
|
day: `${classNames.day} ${styles.day}`,
|
|
day_button: `${classNames.day_button} ${styles.dayButton}`,
|
|
footer: styles.footer,
|
|
month_caption: `${classNames.month_caption} ${styles.monthCaption}`,
|
|
months: `${classNames.months} ${styles.months}`,
|
|
range_end: styles.rangeEnd,
|
|
range_middle: styles.rangeMiddle,
|
|
range_start: styles.rangeStart,
|
|
root: `${classNames.root} ${styles.container}`,
|
|
week: styles.week,
|
|
weekday: `${classNames.weekday} ${styles.weekDay}`,
|
|
nav: `${classNames.nav} ${styles.nav}`,
|
|
button_next: `${classNames.button_next} ${styles.button_next}`,
|
|
button_previous: `${classNames.button_previous} ${styles.button_previous}`,
|
|
}}
|
|
disabled={[
|
|
{ from: lastDayOfPreviousMonth, to: yesterday },
|
|
{ from: endDate, to: endOfLastMonth },
|
|
]}
|
|
excludeDisabled
|
|
footer
|
|
formatters={{
|
|
formatWeekdayName(weekday) {
|
|
return dt(weekday).locale(lang).format("ddd")
|
|
},
|
|
}}
|
|
lang={lang}
|
|
locale={locale}
|
|
mode="range"
|
|
month={month}
|
|
numberOfMonths={2}
|
|
onSelect={handleOnSelect}
|
|
onMonthChange={handleMonthChange}
|
|
required={false}
|
|
selected={selectedRange}
|
|
startMonth={currentDate}
|
|
endMonth={endDate}
|
|
weekStartsOn={1}
|
|
components={{
|
|
Chevron(props) {
|
|
return (
|
|
<MaterialIcon
|
|
icon="chevron_left"
|
|
className={props.className}
|
|
size={20}
|
|
/>
|
|
)
|
|
},
|
|
Footer(props) {
|
|
return (
|
|
<>
|
|
<Divider
|
|
className={styles.divider}
|
|
color="Border/Divider/Subtle"
|
|
/>
|
|
<footer className={props.className}>
|
|
<Button variant="Tertiary" onPress={close} size="sm">
|
|
{intl.formatMessage({
|
|
id: "datePicker.selectDates",
|
|
defaultMessage: "Select dates",
|
|
})}
|
|
</Button>
|
|
</footer>
|
|
</>
|
|
)
|
|
},
|
|
MonthCaption(props) {
|
|
return (
|
|
<div className={props.className}>
|
|
<Typography variant="Title/Subtitle/md">
|
|
<h3>{props.children}</h3>
|
|
</Typography>
|
|
</div>
|
|
)
|
|
},
|
|
}}
|
|
/>
|
|
)
|
|
}
|