Migrate to a monorepo setup - step 1 * Move web to subfolder /apps/scandic-web * Yarn + transitive deps - Move to yarn - design-system package removed for now since yarn doesn't support the parameter for token (ie project currently broken) - Add missing transitive dependencies as Yarn otherwise prevents these imports - VS Code doesn't pick up TS path aliases unless you open /apps/scandic-web instead of root (will be fixed with monorepo) * Pin framer-motion to temporarily fix typing issue https://github.com/adobe/react-spectrum/issues/7494 * Pin zod to avoid typ error There seems to have been a breaking change in the types returned by zod where error is now returned as undefined instead of missing in the type. We should just handle this but to avoid merge conflicts just pin the dependency for now. * Pin react-intl version Pin version of react-intl to avoid tiny type issue where formatMessage does not accept a generic any more. This will be fixed in a future commit, but to avoid merge conflicts just pin for now. * Pin typescript version Temporarily pin version as newer versions as stricter and results in a type error. Will be fixed in future commit after merge. * Setup workspaces * Add design-system as a monorepo package * Remove unused env var DESIGN_SYSTEM_ACCESS_TOKEN * Fix husky for monorepo setup * Update netlify.toml * Add lint script to root package.json * Add stub readme * Fix react-intl formatMessage types * Test netlify.toml in root * Remove root toml * Update netlify.toml publish path * Remove package-lock.json * Update build for branch/preview builds Approved-by: Linus Flood
150 lines
4.5 KiB
TypeScript
150 lines
4.5 KiB
TypeScript
"use client"
|
|
|
|
import { useState } from "react"
|
|
import { DayPicker } from "react-day-picker"
|
|
import { useIntl } from "react-intl"
|
|
|
|
import { Lang } from "@/constants/languages"
|
|
import { dt } from "@/lib/dt"
|
|
|
|
import { ChevronLeftIcon } from "@/components/Icons"
|
|
import Button from "@/components/TempDesignSystem/Button"
|
|
import Divider from "@/components/TempDesignSystem/Divider"
|
|
import Caption from "@/components/TempDesignSystem/Text/Caption"
|
|
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
|
|
import useLang from "@/hooks/useLang"
|
|
|
|
import styles from "./desktop.module.css"
|
|
import classNames from "react-day-picker/style.module.css"
|
|
|
|
import type { DatePickerProps } from "@/types/components/datepicker"
|
|
|
|
export default function DatePickerDesktop({
|
|
close,
|
|
handleOnSelect,
|
|
locales,
|
|
selectedDate,
|
|
}: DatePickerProps) {
|
|
const lang = useLang()
|
|
const intl = useIntl()
|
|
const [month, setMonth] = useState(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 startOfMonth = dt(currentDate).set("date", 1).toDate()
|
|
const yesterday = dt(currentDate).subtract(1, "day").toDate()
|
|
|
|
// Max future date allowed to book kept same as of existing prod.
|
|
const endDate = dt().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}`,
|
|
}}
|
|
disabled={[
|
|
{ from: startOfMonth, 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}
|
|
onDayClick={handleOnSelect}
|
|
onMonthChange={handleMonthChange}
|
|
required={false}
|
|
selected={selectedDate}
|
|
startMonth={currentDate}
|
|
endMonth={endDate}
|
|
weekStartsOn={1}
|
|
components={{
|
|
Chevron(props) {
|
|
return (
|
|
<ChevronLeftIcon
|
|
className={props.className}
|
|
height={20}
|
|
width={20}
|
|
/>
|
|
)
|
|
},
|
|
Footer(props) {
|
|
return (
|
|
<>
|
|
<Divider className={styles.divider} color="primaryLightSubtle" />
|
|
<footer className={props.className}>
|
|
<Button
|
|
intent="tertiary"
|
|
onPress={close}
|
|
size="small"
|
|
theme="base"
|
|
>
|
|
<Caption color="white" type="bold" asChild>
|
|
<span>{intl.formatMessage({ id: "Select dates" })}</span>
|
|
</Caption>
|
|
</Button>
|
|
</footer>
|
|
</>
|
|
)
|
|
},
|
|
MonthCaption(props) {
|
|
return (
|
|
<div className={props.className}>
|
|
<Subtitle asChild type="two">
|
|
{props.children}
|
|
</Subtitle>
|
|
</div>
|
|
)
|
|
},
|
|
Nav(props) {
|
|
if (Array.isArray(props.children)) {
|
|
const prevButton = props.children?.[0]
|
|
const nextButton = props.children?.[1]
|
|
return (
|
|
<>
|
|
{prevButton ? (
|
|
<nav
|
|
className={`${props.className} ${styles.previousButton}`}
|
|
>
|
|
{prevButton}
|
|
</nav>
|
|
) : null}
|
|
{nextButton ? (
|
|
<nav className={`${props.className} ${styles.nextButton}`}>
|
|
{nextButton}
|
|
</nav>
|
|
) : null}
|
|
</>
|
|
)
|
|
}
|
|
return <></>
|
|
},
|
|
}}
|
|
/>
|
|
)
|
|
}
|