/availability - Add ability to set as default in the dropdown (#5717)
Co-authored-by: Nitesh Singh <[email protected]> Co-authored-by: gitstart <[email protected]> Co-authored-by: Matheus Benini Ferreira <[email protected]> Co-authored-by: Rafael Toledo <[email protected]> Co-authored-by: niteshsingh1357 <[email protected]> Co-authored-by: gitstart-app[bot] <57568882+gitstart-app[bot]@users.noreply.github.com> Co-authored-by: gitstart <[email protected]> Co-authored-by: gGh00sTt <[email protected]> Co-authored-by: Thiago Nascimbeni <[email protected]> Co-authored-by: Matheus Muniz <[email protected]> Co-authored-by: gitstart <[email protected]> Co-authored-by: Nitesh Singh <[email protected]> Co-authored-by: Matheus Benini Ferreira <[email protected]> Co-authored-by: Rafael Toledo <[email protected]> Co-authored-by: niteshsingh1357 <[email protected]> Co-authored-by: gitstart-app[bot] <57568882+gitstart-app[bot]@users.noreply.github.com> Co-authored-by: gitstart <[email protected]> Co-authored-by: gGh00sTt <[email protected]> Co-authored-by: Thiago Nascimbeni <[email protected]> Co-authored-by: Matheus Muniz <[email protected]> Co-authored-by: Omar López <[email protected]>
This commit is contained in:
3 files changed
+74
-17
No files matched your search
@@ -2,9 +2,12 @@ import Link from "next/link";
|
||||
import { Fragment } from "react";
|
||||
|
||||
import { availabilityAsString } from "@calcom/lib/availability";
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Availability } from "@calcom/prisma/client";
|
||||
import { RouterOutputs } from "@calcom/trpc/react";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Schedule } from "@calcom/types/schedule";
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
@@ -19,6 +22,7 @@ export function ScheduleListItem({
|
||||
schedule,
|
||||
deleteFunction,
|
||||
displayOptions,
|
||||
updateDefault,
|
||||
}: {
|
||||
schedule: RouterOutputs["viewer"]["availability"]["list"]["schedules"][number];
|
||||
deleteFunction: ({ scheduleId }: { scheduleId: number }) => void;
|
||||
@@ -26,9 +30,20 @@ export function ScheduleListItem({
|
||||
timeZone?: string;
|
||||
hour12?: boolean;
|
||||
};
|
||||
updateDefault: ({
|
||||
scheduleId,
|
||||
isDefault,
|
||||
schedule,
|
||||
}: {
|
||||
scheduleId: number;
|
||||
isDefault: boolean;
|
||||
schedule: Schedule;
|
||||
}) => void;
|
||||
}) {
|
||||
const { t, i18n } = useLocale();
|
||||
|
||||
const { data, isLoading } = trpc.viewer.availability.schedule.get.useQuery({ scheduleId: schedule.id });
|
||||
|
||||
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">
|
||||
@@ -67,22 +82,44 @@ export function ScheduleListItem({
|
||||
<DropdownMenuTrigger asChild className="mr-5">
|
||||
<Button type="button" size="icon" color="secondary" StartIcon={Icon.FiMoreHorizontal} />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem>
|
||||
<Button
|
||||
onClick={() => {
|
||||
deleteFunction({
|
||||
scheduleId: schedule.id,
|
||||
});
|
||||
}}
|
||||
type="button"
|
||||
color="destructive"
|
||||
className="w-full font-normal"
|
||||
StartIcon={Icon.FiTrash}>
|
||||
{t("delete_schedule")}
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
{!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>
|
||||
)}
|
||||
</Dropdown>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
Reference in new issue
Block a user