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";
|
|
|
|
import { Availability } from "@calcom/prisma/client";
|
|
|
|
import { inferQueryOutput } from "@calcom/trpc/react";
|
2022-09-06 18:34:29 +00:00
|
|
|
import Dropdown, { DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@calcom/ui/Dropdown";
|
|
|
|
import { Icon } from "@calcom/ui/Icon";
|
2022-09-05 16:16:42 +00:00
|
|
|
import Badge from "@calcom/ui/v2/core/Badge";
|
2022-09-08 14:21:46 +00:00
|
|
|
import Button from "@calcom/ui/v2/core/Button";
|
2022-08-24 20:18:42 +00:00
|
|
|
|
|
|
|
export function ScheduleListItem({
|
|
|
|
schedule,
|
|
|
|
deleteFunction,
|
2022-09-06 18:34:29 +00:00
|
|
|
displayOptions,
|
2022-08-24 20:18:42 +00:00
|
|
|
}: {
|
|
|
|
schedule: inferQueryOutput<"viewer.availability.list">["schedules"][number];
|
|
|
|
deleteFunction: ({ scheduleId }: { scheduleId: number }) => void;
|
2022-09-06 18:34:29 +00:00
|
|
|
displayOptions?: {
|
|
|
|
timeZone?: string;
|
|
|
|
hour12?: boolean;
|
|
|
|
};
|
2022-08-24 20:18:42 +00:00
|
|
|
}) {
|
|
|
|
const { t, i18n } = useLocale();
|
|
|
|
|
|
|
|
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">
|
|
|
|
<Link href={"/availability/" + schedule.id}>
|
|
|
|
<a className="flex-grow truncate text-sm" title={schedule.name}>
|
2022-09-06 18:34:29 +00:00
|
|
|
<div className="space-x-2">
|
|
|
|
<span className="truncate font-medium text-neutral-900">{schedule.name}</span>
|
|
|
|
{schedule.isDefault && (
|
|
|
|
<Badge variant="success" className="text-xs">
|
|
|
|
{t("default")}
|
|
|
|
</Badge>
|
|
|
|
)}
|
2022-08-24 20:18:42 +00:00
|
|
|
</div>
|
2022-09-06 18:34:29 +00:00
|
|
|
<p className="mt-1 text-xs text-neutral-500">
|
2022-08-24 20:18:42 +00:00
|
|
|
{schedule.availability.map((availability: Availability) => (
|
|
|
|
<Fragment key={availability.id}>
|
2022-09-06 18:34:29 +00:00
|
|
|
{availabilityAsString(availability, {
|
|
|
|
locale: i18n.language,
|
|
|
|
hour12: displayOptions?.hour12,
|
|
|
|
})}
|
2022-08-24 20:18:42 +00:00
|
|
|
<br />
|
|
|
|
</Fragment>
|
|
|
|
))}
|
2022-09-06 18:34:29 +00:00
|
|
|
{schedule.timeZone && schedule.timeZone !== displayOptions?.timeZone && (
|
|
|
|
<p className="my-1 flex items-center first-letter:text-xs">
|
|
|
|
<Icon.FiGlobe />
|
|
|
|
{schedule.timeZone}
|
|
|
|
</p>
|
|
|
|
)}
|
2022-08-24 20:18:42 +00:00
|
|
|
</p>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
<Dropdown>
|
2022-09-08 14:21:46 +00:00
|
|
|
<DropdownMenuTrigger asChild className="mr-5">
|
2022-09-09 10:53:02 +00:00
|
|
|
<Button type="button" size="icon" color="secondary" StartIcon={Icon.FiMoreHorizontal} />
|
2022-08-24 20:18:42 +00:00
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
deleteFunction({
|
|
|
|
scheduleId: schedule.id,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
type="button"
|
2022-09-08 14:21:46 +00:00
|
|
|
color="destructive"
|
2022-08-24 20:18:42 +00:00
|
|
|
className="w-full font-normal"
|
2022-09-21 21:04:21 +00:00
|
|
|
StartIcon={Icon.FiTrash}>
|
|
|
|
{t("delete_schedule")}
|
2022-08-24 20:18:42 +00:00
|
|
|
</Button>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|