2022-08-24 20:18:42 +00:00
|
|
|
import Link from "next/link";
|
|
|
|
import { Fragment } from "react";
|
|
|
|
|
|
|
|
import { availabilityAsString } from "@calcom/lib/availability";
|
2022-12-07 19:35:55 +00:00
|
|
|
import classNames from "@calcom/lib/classNames";
|
2022-08-24 20:18:42 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { Availability } from "@calcom/prisma/client";
|
2022-11-10 23:40:01 +00:00
|
|
|
import { RouterOutputs } from "@calcom/trpc/react";
|
2022-12-07 19:35:55 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
|
|
|
import { Schedule } from "@calcom/types/schedule";
|
2022-11-23 02:55:25 +00:00
|
|
|
import {
|
|
|
|
Badge,
|
|
|
|
Button,
|
|
|
|
Dropdown,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuItem,
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
Icon,
|
|
|
|
} from "@calcom/ui";
|
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-07 19:35:55 +00:00
|
|
|
updateDefault: ({
|
|
|
|
scheduleId,
|
|
|
|
isDefault,
|
|
|
|
schedule,
|
|
|
|
}: {
|
|
|
|
scheduleId: number;
|
|
|
|
isDefault: boolean;
|
|
|
|
schedule: Schedule;
|
|
|
|
}) => 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">
|
|
|
|
<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>
|
2022-12-07 19:35:55 +00:00
|
|
|
{!isLoading && data && (
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuItem className="min-w-40 focus:ring-gray-100">
|
|
|
|
{!schedule.isDefault && (
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
color="minimal"
|
|
|
|
className="w-full rounded-b-none border-none font-normal"
|
|
|
|
disabled={schedule.isDefault}
|
|
|
|
onClick={() => {
|
|
|
|
updateDefault({
|
|
|
|
scheduleId: schedule.id,
|
|
|
|
isDefault: true,
|
|
|
|
schedule: data.availability,
|
|
|
|
});
|
|
|
|
}}>
|
|
|
|
{t("set_as_default")}
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
</DropdownMenuItem>
|
|
|
|
<DropdownMenuItem className="min-w-40 focus:ring-gray-100">
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
deleteFunction({
|
|
|
|
scheduleId: schedule.id,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
color="destructive"
|
|
|
|
className={classNames(
|
|
|
|
"w-full border-none font-normal",
|
|
|
|
!schedule.isDefault && "rounded-t-none"
|
|
|
|
)}>
|
|
|
|
{t("delete")}
|
|
|
|
</Button>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
)}
|
2022-08-24 20:18:42 +00:00
|
|
|
</Dropdown>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|