* feature for team ooo crud and past records * added tests for ooo handler, combined list components for mine,team * nit: removed commented code * added current-previous tab , not to show TeamOOO tab for nonadmin * update for type checks * updated tests after merge * updated outofoffice handler after merge * for alignment with outofoffice header column * update after resolving merge conflicts * nit/chore: spacing * update after changes in router migration * ui improvements rounded corner * updated props * Update apps/web/public/static/locales/en/common.json Co-authored-by: Carina Wollendorfer <[email protected]> * Update apps/web/public/static/locales/en/common.json Co-authored-by: Carina Wollendorfer <[email protected]> * updated dialog subtitles, review comments * Update packages/features/settings/outOfOffice/CreateOrEditOutOfOfficeModal.tsx Co-authored-by: Amit Sharma <[email protected]> * Update packages/trpc/server/routers/loggedInViewer/outOfOffice.schema.ts Co-authored-by: Amit Sharma <[email protected]> * refactored to split ooo handlers, review comments * updated test.utils * chore * chore: unrelated changes may be merge * optimized query * update due to latest changes and merge conflicts * updates to changes in people filter * chore * as now taken care in DataTable * updates after merge * updates after merge due tp changes in datatable and others * update import due to file splitting and new name * update for typecheck * update for new add button when empty entries * nit * replace tests with e2e tests * chore * include only manage team ooo * fix type check * Update safe-parse.ts * use invalidate instead of props, leaving main server components as it is * nit * update forMember div ht in edit mode --------- Co-authored-by: Carina Wollendorfer <[email protected]> Co-authored-by: Amit Sharma <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]> Co-authored-by: Tushar Bhatt <[email protected]>
97 lines
2.8 KiB
TypeScript
97 lines
2.8 KiB
TypeScript
"use client";
|
|
|
|
import * as Popover from "@radix-ui/react-popover";
|
|
import { format } from "date-fns";
|
|
import * as React from "react";
|
|
|
|
import { classNames as cn } from "@calcom/lib";
|
|
|
|
import { Button } from "../../button";
|
|
import { Calendar } from "./Calendar";
|
|
|
|
type DatePickerWithRangeProps = {
|
|
dates: { startDate?: Date; endDate?: Date };
|
|
onDatesChange: ({ startDate, endDate }: { startDate?: Date; endDate?: Date }) => void;
|
|
disabled?: boolean;
|
|
minDate?: Date | null;
|
|
maxDate?: Date;
|
|
withoutPopover?: boolean;
|
|
"data-testid"?: string;
|
|
};
|
|
|
|
export function DatePickerWithRange({
|
|
className,
|
|
dates,
|
|
minDate,
|
|
maxDate,
|
|
onDatesChange,
|
|
disabled,
|
|
withoutPopover,
|
|
"data-testid": testId,
|
|
}: React.HTMLAttributes<HTMLDivElement> & DatePickerWithRangeProps) {
|
|
function handleDayClick(date: Date) {
|
|
if (dates?.endDate) {
|
|
onDatesChange({ startDate: date, endDate: undefined });
|
|
} else {
|
|
const startDate = dates.startDate ? (date < dates.startDate ? date : dates.startDate) : date;
|
|
const endDate = dates.startDate ? (date < dates.startDate ? dates.startDate : date) : undefined;
|
|
onDatesChange({ startDate, endDate });
|
|
}
|
|
}
|
|
const fromDate = minDate ?? new Date();
|
|
|
|
const calendar = (
|
|
<Calendar
|
|
initialFocus
|
|
//When explicitly null, we want past dates to be shown as well, otherwise show only dates passed or from current date
|
|
fromDate={minDate === null ? undefined : fromDate}
|
|
toDate={maxDate}
|
|
mode="range"
|
|
defaultMonth={dates?.startDate}
|
|
selected={{ from: dates?.startDate, to: dates?.endDate }}
|
|
onDayClick={(day) => handleDayClick(day)}
|
|
numberOfMonths={1}
|
|
disabled={disabled}
|
|
data-testid={testId}
|
|
/>
|
|
);
|
|
|
|
if (withoutPopover) {
|
|
return calendar;
|
|
}
|
|
|
|
return (
|
|
<div className={cn("grid gap-2", className)}>
|
|
<Popover.Root>
|
|
<Popover.Trigger asChild>
|
|
<Button
|
|
data-testid="date-range"
|
|
color="secondary"
|
|
EndIcon="calendar"
|
|
className={cn("justify-between text-left font-normal", !dates && "text-subtle")}>
|
|
{dates?.startDate ? (
|
|
dates?.endDate ? (
|
|
<>
|
|
{format(dates.startDate, "LLL dd, y")} - {format(dates.endDate, "LLL dd, y")}
|
|
</>
|
|
) : (
|
|
<>{format(dates.startDate, "LLL dd, y")} - End</>
|
|
)
|
|
) : (
|
|
<span>Pick a date</span>
|
|
)}
|
|
</Button>
|
|
</Popover.Trigger>
|
|
<Popover.Content
|
|
className="bg-default text-emphasis z-50 w-auto rounded-md border p-0 outline-none"
|
|
align="start"
|
|
sideOffset={4}
|
|
side="bottom"
|
|
avoidCollisions={false}>
|
|
{calendar}
|
|
</Popover.Content>
|
|
</Popover.Root>
|
|
</div>
|
|
);
|
|
}
|