diff --git a/packages/platform/atoms/availability/index.tsx b/packages/platform/atoms/availability/index.tsx index 6404fcbf36..f620140f2e 100644 --- a/packages/platform/atoms/availability/index.tsx +++ b/packages/platform/atoms/availability/index.tsx @@ -1,19 +1,21 @@ -import { LargeScreenCTA } from "availability/cta/large-screen"; -import { SmallScreenCTA } from "availability/cta/small-screen"; import { useClientSchedule } from "availability/hooks/useClientSchedule"; import { useProfileInfo } from "availability/hooks/useProfileInfo"; -import { Timezone } from "availability/timezone"; -import { Troubleshooter } from "availability/troubleshooter"; -import { useState } from "react"; -import { useForm, Controller } from "react-hook-form"; +import { Fragment } from "react"; -import Shell from "@calcom/features/shell/Shell"; import { availabilityAsString } from "@calcom/lib/availability"; import type { Schedule as ScheduleType, TimeRange } from "@calcom/types/schedule"; -import { SkeletonText, VerticalDivider, Button, Form } from "@calcom/ui"; -import { MoreVertical } from "@calcom/ui/components/icon"; +import { + Badge, + Button, + Dropdown, + DropdownMenuContent, + DropdownMenuItem, + DropdownItem, + DropdownMenuTrigger, + showToast, +} from "@calcom/ui"; +import { Globe, MoreHorizontal, Star, Copy, Trash } from "@calcom/ui/components/icon"; -import EditableHeading from "../../../../apps/web/components/ui/EditableHeading"; import { useApiKey } from "../cal-provider"; export type AvailabilityFormValues = { @@ -26,24 +28,20 @@ export type AvailabilityFormValues = { type AvailabilityProps = { id?: string; + isDeletable?: boolean; }; -export function Availability({ id }: AvailabilityProps) { +export function Availability({ id, isDeletable = true }: AvailabilityProps) { const { key, error } = useApiKey(); // if user doesnt provide a scheduleId we use the default schedule id // since we know there will always be one default schedule so schedule cant be empty const { isLoading, data: schedule } = useClientSchedule(id ? id : "1", key); const user = useProfileInfo(key); - const { timeFormat } = user.data || { timeFormat: null }; - const [openSidebar, setOpenSidebar] = useState(false); - - const form = useForm({ - values: schedule && { - ...schedule, - schedule: schedule?.availability || [], - }, - }); + const displayOptions = { + hour12: user.data?.timeFormat ? user.data.timeFormat === 12 : undefined, + timeZone: user.data?.timeZone, + }; if (error === "no_key") return <>You havent entered a key; @@ -52,67 +50,90 @@ export function Availability({ id }: AvailabilityProps) { if (isLoading) return <>Loading...; return ( - ( - +
+
+
+ {schedule.name} + {schedule.isDefault && ( + + Default + )} - /> - } - subtitle={ - schedule ? ( - schedule.schedule +
+

+ {schedule.availability .filter((availability: any) => !!availability.days.length) .map((availability: any) => ( - - {availabilityAsString(availability, { hour12: timeFormat === 12 })} + + {availabilityAsString(availability, { + hour12: displayOptions?.hour12, + })}
-
- )) - ) : ( - - ) - } - CTA={ -

- { - form.setValue("isDefault", e); - }} - /> - - setOpenSidebar(false)} /> -
- + + ))} + {(schedule.timeZone || displayOptions?.timeZone) && ( +

+ +  {schedule.timeZone ?? displayOptions?.timeZone} +

+ )} +

+
+ +
- }> -
-
-
-
-
- -
- -
-
- -
- + + {!isLoading && schedule && ( + + + {!schedule.isDefault && ( + { + // set to default function goes here + }}> + Set as default + + )} + + + { + // duplication function goes here + }}> + Duplicate + + + + { + if (!isDeletable) { + showToast("You are required to have at least one schedule", "error"); + } else { + // deletion function goes here + } + }}> + Delete + + + + )} + +
); }