Feature/date overrides (#5991)
* Initial incomplete (but mostly functional) push of date override functions * Fixed date shifting on load * Bring back minDate (automatically disable all dates before current date) * Fix type error * Supply working hours to render available dates * Converted to SSR * moving defaultValues to the backend * Improv. as filter can be achieved within the reduce Co-authored-by: Omar López <[email protected]> * Double inversion -> single, as it is an early return * uniq() exit - not needed anymore * Typefixes * It's overriding dates :D * Fixed duplication DateOverrides in list * Implemented changing the month * Make dateOverrides an optional param * Fixed test (which requires dateOverrides due to auto-typing) * Prevent a full update on set as default from list view * Added some extra keys to keep ts happy * Only allow a single date override per date * Disallow editing excludedDates to the same date * Bring back duplicate key ?.? Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: zomars <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
20 files changed
+707
-202
No files matched your search
@@ -17,7 +17,7 @@ export type DatePickerProps = {
|
||||
/** Fires when the month is changed. */
|
||||
onMonthChange?: (date: Dayjs) => void;
|
||||
/** which date is currently selected (not tracked from here) */
|
||||
selected?: Dayjs;
|
||||
selected?: Dayjs | null;
|
||||
/** defaults to current date. */
|
||||
minDate?: Dayjs;
|
||||
/** Furthest date selectable in the future, default = UNLIMITED */
|
||||
@@ -37,38 +37,41 @@ export type DatePickerProps = {
|
||||
export const Day = ({
|
||||
date,
|
||||
active,
|
||||
disabled,
|
||||
...props
|
||||
}: JSX.IntrinsicElements["button"] & { active: boolean; date: Dayjs }) => {
|
||||
}: JSX.IntrinsicElements["button"] & {
|
||||
active: boolean;
|
||||
date: Dayjs;
|
||||
}) => {
|
||||
const enabledDateButtonEmbedStyles = useEmbedStyles("enabledDateButton");
|
||||
const disabledDateButtonEmbedStyles = useEmbedStyles("disabledDateButton");
|
||||
return (
|
||||
<button
|
||||
style={props.disabled ? { ...disabledDateButtonEmbedStyles } : { ...enabledDateButtonEmbedStyles }}
|
||||
type="button"
|
||||
style={disabled ? { ...disabledDateButtonEmbedStyles } : { ...enabledDateButtonEmbedStyles }}
|
||||
className={classNames(
|
||||
"disabled:text-bookinglighter dark:hover:border-darkmodebrand absolute top-0 left-0 right-0 bottom-0 mx-auto w-full rounded-md border-2 border-transparent text-center font-medium disabled:cursor-default disabled:border-transparent disabled:font-light disabled:dark:border-transparent",
|
||||
active
|
||||
? "dark:bg-darkmodebrand dark:text-darkmodebrandcontrast bg-brand text-brandcontrast border-2"
|
||||
: !props.disabled
|
||||
: !disabled
|
||||
? "dark:bg-darkgray-200 bg-gray-100 hover:bg-gray-300 dark:text-white"
|
||||
: ""
|
||||
)}
|
||||
data-testid="day"
|
||||
data-disabled={props.disabled}
|
||||
data-disabled={disabled}
|
||||
disabled={disabled}
|
||||
{...props}>
|
||||
{date.date()}
|
||||
{date.isToday() && (
|
||||
<span className="absolute left-0 bottom-0 mx-auto -mb-px w-full text-4xl md:-bottom-1 lg:bottom-0">
|
||||
.
|
||||
</span>
|
||||
<span className="absolute left-0 right-0 bottom-0 h-2/5 align-middle text-4xl leading-[0rem]">.</span>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
const Days = ({
|
||||
// minDate,
|
||||
minDate = dayjs.utc(),
|
||||
excludedDates = [],
|
||||
includedDates,
|
||||
browsingDate,
|
||||
weekStart,
|
||||
DayComponent = Day,
|
||||
@@ -81,6 +84,28 @@ const Days = ({
|
||||
}) => {
|
||||
// Create placeholder elements for empty days in first week
|
||||
const weekdayOfFirst = browsingDate.day();
|
||||
const currentDate = minDate.utcOffset(browsingDate.utcOffset());
|
||||
|
||||
const availableDates = (includedDates: string[] | undefined) => {
|
||||
const dates = [];
|
||||
const lastDateOfMonth = browsingDate.date(daysInMonth(browsingDate));
|
||||
for (
|
||||
let date = currentDate;
|
||||
date.isBefore(lastDateOfMonth) || date.isSame(lastDateOfMonth, "day");
|
||||
date = date.add(1, "day")
|
||||
) {
|
||||
// even if availableDates is given, filter out the passed included dates
|
||||
if (includedDates && !includedDates.includes(yyyymmdd(date))) {
|
||||
continue;
|
||||
}
|
||||
dates.push(yyyymmdd(date));
|
||||
}
|
||||
return dates;
|
||||
};
|
||||
|
||||
const includedDates = currentDate.isSame(browsingDate, "month")
|
||||
? availableDates(props.includedDates)
|
||||
: props.includedDates;
|
||||
|
||||
const days: (Dayjs | null)[] = Array((weekdayOfFirst - weekStart + 7) % 7).fill(null);
|
||||
for (let day = 1, dayCount = daysInMonth(browsingDate); day <= dayCount; day++) {
|
||||
@@ -162,6 +187,7 @@ const DatePicker = ({
|
||||
</span>
|
||||
<div className="text-black dark:text-white">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => changeMonth(-1)}
|
||||
className={classNames(
|
||||
"group p-1 opacity-50 hover:opacity-100 ltr:mr-2 rtl:ml-2",
|
||||
@@ -172,6 +198,7 @@ const DatePicker = ({
|
||||
<ChevronLeftIcon className="h-5 w-5" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="group p-1 opacity-50 hover:opacity-100"
|
||||
onClick={() => changeMonth(+1)}
|
||||
data-testid="incrementMonth">
|
||||
|
||||
Reference in new issue
Block a user