import { Trans } from "next-i18next";
import Link from "next/link";
import { useRouter } from "next/navigation";
import { Fragment, useState, useEffect } from "react";
import DisconnectIntegration from "@calcom/features/apps/components/DisconnectIntegration";
import { CalendarSwitch } from "@calcom/features/calendars/CalendarSwitch";
import DestinationCalendarSelector from "@calcom/features/calendars/DestinationCalendarSelector";
import SectionBottomActions from "@calcom/features/settings/SectionBottomActions";
import { getLayout } from "@calcom/features/settings/layouts/SettingsLayout";
import { classNames } from "@calcom/lib";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { trpc } from "@calcom/trpc/react";
import {
Alert,
Badge,
Button,
EmptyScreen,
List,
ListItem,
ListItemText,
ListItemTitle,
Meta,
SkeletonButton,
SkeletonContainer,
SkeletonText,
showToast,
} from "@calcom/ui";
import { Plus, Calendar } from "@calcom/ui/components/icon";
import { QueryCell } from "@lib/QueryCell";
import PageWrapper from "@components/PageWrapper";
const SkeletonLoader = () => {
return (
);
};
const AddCalendarButton = () => {
const { t } = useLocale();
return (
<>
>
);
};
const CalendarsView = () => {
const { t } = useLocale();
const router = useRouter();
const utils = trpc.useContext();
const query = trpc.viewer.connectedCalendars.useQuery();
const [selectedDestinationCalendarOption, setSelectedDestinationCalendar] = useState<{
integration: string;
externalId: string;
} | null>(null);
useEffect(() => {
if (query?.data?.destinationCalendar) {
setSelectedDestinationCalendar({
integration: query.data.destinationCalendar.integration,
externalId: query.data.destinationCalendar.externalId,
});
}
}, [query?.isLoading, query?.data?.destinationCalendar]);
const mutation = trpc.viewer.setDestinationCalendar.useMutation({
async onSettled() {
await utils.viewer.connectedCalendars.invalidate();
},
onSuccess: async () => {
showToast(t("calendar_updated_successfully"), "success");
},
onError: () => {
showToast(t("unexpected_error_try_again"), "error");
},
});
return (
<>
}
borderInShellHeader={false}
/>
}
success={({ data }) => {
const isDestinationUpdateBtnDisabled =
selectedDestinationCalendarOption?.externalId === query?.data?.destinationCalendar?.externalId;
return data.connectedCalendars.length ? (
{t("add_to_calendar")}
{t("add_to_calendar_description")}
{
setSelectedDestinationCalendar(option);
}}
isLoading={mutation.isLoading}
/>
{t("check_for_conflicts")}
{t("select_calendars")}
{data.connectedCalendars.map((item) => (
{item.error && item.error.message && (
{/* @TODO: add a reconnect button, that calls add api and delete old credential */}
query.refetch()}
buttonProps={{
className: "border border-default py-[2px]",
color: "secondary",
}}
/>
>
}
/>
)}
{item?.error === undefined && item.calendars && (
{
// eslint-disable-next-line @next/next/no-img-element
item.integration.logo && (
)
}
{item.integration.name || item.integration.title}
{data?.destinationCalendar?.credentialId === item.credentialId && (
Default
)}
{item.integration.description}
{t("toggle_calendars_conflict")}
{item.calendars.map((cal) => (
))}
)}
))}
) : (
router.push("/apps/categories/calendar")}
className="mt-6"
/>
);
}}
error={() => {
return (
An error ocurred while fetching your Calendars.
query.refetch()}>
try again
.
}
severity="error"
/>
);
}}
/>
>
);
};
CalendarsView.getLayout = getLayout;
CalendarsView.PageWrapper = PageWrapper;
export default CalendarsView;