diff --git a/apps/web/components/apps/CalendarListContainer.tsx b/apps/web/components/apps/CalendarListContainer.tsx index c66596f138..8afd92845e 100644 --- a/apps/web/components/apps/CalendarListContainer.tsx +++ b/apps/web/components/apps/CalendarListContainer.tsx @@ -1,9 +1,9 @@ -import { useMutation } from "@tanstack/react-query"; import Link from "next/link"; import { Fragment } from "react"; import { InstallAppButton } from "@calcom/app-store/components"; import DisconnectIntegration from "@calcom/features/apps/components/DisconnectIntegration"; +import { CalendarSwitch } from "@calcom/features/calendars/CalendarSwitch"; import DestinationCalendarSelector from "@calcom/features/calendars/DestinationCalendarSelector"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; @@ -12,12 +12,10 @@ import { Button, EmptyScreen, List, - showToast, AppSkeletonLoader as SkeletonLoader, - Switch, ShellSubHeading, } from "@calcom/ui"; -import { ArrowLeft, Calendar, Plus } from "@calcom/ui/components/icon"; +import { Calendar, Plus } from "@calcom/ui/components/icon"; import { QueryCell } from "@lib/QueryCell"; @@ -31,83 +29,6 @@ type Props = { destinationCalendarId?: string; }; -function CalendarSwitch(props: { - type: string; - externalId: string; - title: string; - defaultSelected: boolean; - destination?: boolean; -}) { - const { t } = useLocale(); - const utils = trpc.useContext(); - - const mutation = useMutation< - unknown, - unknown, - { - isOn: boolean; - } - >( - async ({ isOn }) => { - const body = { - integration: props.type, - externalId: props.externalId, - }; - if (isOn) { - const res = await fetch("/api/availability/calendar", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(body), - }); - if (!res.ok) { - throw new Error("Something went wrong"); - } - } else { - const res = await fetch("/api/availability/calendar", { - method: "DELETE", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(body), - }); - - if (!res.ok) { - throw new Error("Something went wrong"); - } - } - }, - { - async onSettled() { - await utils.viewer.integrations.invalidate(); - }, - onError() { - showToast(`Something went wrong when toggling "${props.title}""`, "error"); - }, - } - ); - return ( -
- { - mutation.mutate({ isOn }); - }} - /> - {!!props.destination && ( - - - {t("adding_events_to")} - - )} -
- ); -} - function CalendarList(props: Props) { const { t } = useLocale(); const query = trpc.viewer.integrations.useQuery({ variant: "calendar", onlyInstalled: false }); @@ -185,14 +106,15 @@ function ConnectedCalendarsList(props: Props) { {!fromOnboarding && ( <>

{t("toggle_calendars_conflict")}

-