2022-08-24 20:18:42 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
import { Fragment } from "react";
|
|
|
|
|
|
|
|
import { availabilityAsString } from "@calcom/lib/availability";
|
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-02-24 14:21:31 +00:00
|
|
|
import type { RouterOutputs } from "@calcom/trpc/react";
|
2022-12-07 19:35:55 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import {
|
|
|
|
Badge,
|
|
|
|
Button,
|
|
|
|
Dropdown,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuItem,
|
2023-01-15 11:40:40 +00:00
|
|
|
DropdownItem,
|
2022-11-23 02:55:25 +00:00
|
|
|
DropdownMenuTrigger,
|
|
|
|
} from "@calcom/ui";
|
2023-03-02 16:20:02 +00:00
|
|
|
import { FiGlobe, FiMoreHorizontal, FiTrash, FiClock } from "@calcom/ui/components/icon";
|
2022-08-24 20:18:42 +00:00
|
|
|
|
|
|
|
export function ScheduleListItem({
|
|
|
|
schedule,
|
|
|
|
deleteFunction,
|
2022-09-06 18:34:29 +00:00
|
|
|
displayOptions,
|
2022-12-07 19:35:55 +00:00
|
|
|
updateDefault,
|
2022-08-24 20:18:42 +00:00
|
|
|
}: {
|
2022-11-10 23:40:01 +00:00
|
|
|
schedule: RouterOutputs["viewer"]["availability"]["list"]["schedules"][number];
|
2022-08-24 20:18:42 +00:00
|
|
|
deleteFunction: ({ scheduleId }: { scheduleId: number }) => void;
|
2022-09-06 18:34:29 +00:00
|
|
|
displayOptions?: {
|
|
|
|
timeZone?: string;
|
|
|
|
hour12?: boolean;
|
|
|
|
};
|
2022-12-14 17:30:55 +00:00
|
|
|
updateDefault: ({ scheduleId, isDefault }: { scheduleId: number; isDefault: boolean }) => void;
|
2022-08-24 20:18:42 +00:00
|
|
|
}) {
|
|
|
|
const { t, i18n } = useLocale();
|
|
|
|
|
2022-12-07 19:35:55 +00:00
|
|
|
const { data, isLoading } = trpc.viewer.availability.schedule.get.useQuery({ scheduleId: schedule.id });
|
|
|
|
|
2022-08-24 20:18:42 +00:00
|
|
|
return (
|
|
|
|
<li key={schedule.id}>
|
|
|
|
<div className="flex items-center justify-between py-5 hover:bg-neutral-50 ltr:pl-4 rtl:pr-4 sm:ltr:pl-0 sm:rtl:pr-0">
|
|
|
|
<div className="group flex w-full items-center justify-between hover:bg-neutral-50 sm:px-6">
|
2023-01-06 12:13:56 +00:00
|
|
|
<Link
|
|
|
|
href={"/availability/" + schedule.id}
|
|
|
|
className="flex-grow truncate text-sm"
|
|
|
|
title={schedule.name}>
|
|
|
|
<div className="space-x-2 rtl:space-x-reverse">
|
2023-01-12 16:57:43 +00:00
|
|
|
<span className="truncate font-medium text-gray-900">{schedule.name}</span>
|
2023-01-06 12:13:56 +00:00
|
|
|
{schedule.isDefault && (
|
|
|
|
<Badge variant="success" className="text-xs">
|
|
|
|
{t("default")}
|
|
|
|
</Badge>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-02-24 14:21:31 +00:00
|
|
|
<p className="mt-1 text-gray-500">
|
2023-01-06 12:13:56 +00:00
|
|
|
{schedule.availability
|
|
|
|
.filter((availability) => !!availability.days.length)
|
|
|
|
.map((availability) => (
|
|
|
|
<Fragment key={availability.id}>
|
|
|
|
{availabilityAsString(availability, {
|
|
|
|
locale: i18n.language,
|
|
|
|
hour12: displayOptions?.hour12,
|
|
|
|
})}
|
|
|
|
<br />
|
|
|
|
</Fragment>
|
|
|
|
))}
|
2023-02-24 14:21:31 +00:00
|
|
|
{(schedule.timeZone || displayOptions?.timeZone) && (
|
|
|
|
<p className="my-1 flex items-center first-letter:text-xs">
|
|
|
|
<FiGlobe />
|
|
|
|
{schedule.timeZone ?? displayOptions?.timeZone}
|
|
|
|
</p>
|
|
|
|
)}
|
2023-01-06 12:13:56 +00:00
|
|
|
</p>
|
2022-08-24 20:18:42 +00:00
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
<Dropdown>
|
2023-01-22 00:03:59 +00:00
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
<Button
|
|
|
|
className="mx-5"
|
|
|
|
type="button"
|
|
|
|
variant="icon"
|
|
|
|
color="secondary"
|
2023-01-23 23:08:01 +00:00
|
|
|
StartIcon={FiMoreHorizontal}
|
2023-01-22 00:03:59 +00:00
|
|
|
/>
|
2022-08-24 20:18:42 +00:00
|
|
|
</DropdownMenuTrigger>
|
2022-12-07 19:35:55 +00:00
|
|
|
{!isLoading && data && (
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuItem className="min-w-40 focus:ring-gray-100">
|
|
|
|
{!schedule.isDefault && (
|
2023-01-15 11:40:40 +00:00
|
|
|
<DropdownItem
|
2022-12-07 19:35:55 +00:00
|
|
|
type="button"
|
2023-03-02 16:20:02 +00:00
|
|
|
StartIcon={FiClock}
|
2022-12-07 19:35:55 +00:00
|
|
|
onClick={() => {
|
|
|
|
updateDefault({
|
|
|
|
scheduleId: schedule.id,
|
|
|
|
isDefault: true,
|
|
|
|
});
|
|
|
|
}}>
|
|
|
|
{t("set_as_default")}
|
2023-01-15 11:40:40 +00:00
|
|
|
</DropdownItem>
|
2022-12-07 19:35:55 +00:00
|
|
|
)}
|
|
|
|
</DropdownMenuItem>
|
|
|
|
<DropdownMenuItem className="min-w-40 focus:ring-gray-100">
|
2023-01-15 11:40:40 +00:00
|
|
|
<DropdownItem
|
|
|
|
type="button"
|
|
|
|
color="destructive"
|
2023-01-23 23:08:01 +00:00
|
|
|
StartIcon={FiTrash}
|
2022-12-07 19:35:55 +00:00
|
|
|
onClick={() => {
|
|
|
|
deleteFunction({
|
|
|
|
scheduleId: schedule.id,
|
|
|
|
});
|
2023-01-15 11:40:40 +00:00
|
|
|
}}>
|
2022-12-07 19:35:55 +00:00
|
|
|
{t("delete")}
|
2023-01-15 11:40:40 +00:00
|
|
|
</DropdownItem>
|
2022-12-07 19:35:55 +00:00
|
|
|
</DropdownMenuItem>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
)}
|
2022-08-24 20:18:42 +00:00
|
|
|
</Dropdown>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|