import { SelectedCalendarsSettings } from "@calcom/atoms/selected-calendars/SelectedCalendarsSettings"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import type { RouterOutputs } from "@calcom/trpc/react"; import { trpc } from "@calcom/trpc/react"; import { Alert } from "@calcom/ui/components/alert"; import { Select } from "@calcom/ui/components/form"; import { List } from "@calcom/ui/components/list"; import AppListCardWebWrapper from "@calcom/web/modules/apps/components/AppListCardWebWrapper"; import CredentialActionsDropdown from "@calcom/web/modules/apps/components/CredentialActionsDropdown"; import AdditionalCalendarSelector from "@calcom/web/modules/calendars/components/AdditionalCalendarSelector"; import { CalendarSwitch } from "@calcom/web/modules/calendars/components/CalendarSwitch"; import Link from "next/link"; import React from "react"; export enum SelectedCalendarSettingsScope { User = "user", EventType = "eventType", } type SelectedCalendarsSettingsWebWrapperProps = { onChanged?: () => unknown | Promise; fromOnboarding?: boolean; destinationCalendarId?: string; isPending?: boolean; classNames?: string; eventTypeId?: number; disabledScope?: SelectedCalendarSettingsScope; scope?: SelectedCalendarSettingsScope; setScope?: (scope: SelectedCalendarSettingsScope) => void; disableConnectionModification?: boolean; connectedCalendars?: RouterOutputs["viewer"]["calendars"]["connectedCalendars"]; }; const ConnectedCalendarList = ({ fromOnboarding = false, scope, items, disableConnectionModification, eventTypeId, onChanged, destinationCalendarId, isDisabled, }: { fromOnboarding?: boolean; scope: SelectedCalendarSettingsScope; items: RouterOutputs["viewer"]["calendars"]["connectedCalendars"]["connectedCalendars"]; disableConnectionModification?: boolean; eventTypeId: number | null; onChanged?: () => unknown | Promise; destinationCalendarId?: string; isDisabled: boolean; }) => { const { t } = useLocale(); const shouldUseEventTypeScope = scope === SelectedCalendarSettingsScope.EventType; return ( {items.map((connectedCalendar) => { if (!!connectedCalendar.calendars && connectedCalendar.calendars.length > 0) { return ( }>
{!fromOnboarding && ( <>

{t("toggle_calendars_conflict")}

    {connectedCalendar.calendars?.map((cal) => ( { if (shouldUseEventTypeScope) { return eventTypeId; } return null; })()} delegationCredentialId={connectedCalendar.delegationCredentialId || null} /> ))}
)}
); } return ( {connectedCalendar.integration.name} : {t("calendar_error")} } iconClassName="h-10 w-10 ml-2 mr-1 mt-0.5" actions={
} /> ); })}
); }; export const SelectedCalendarsSettingsWebWrapper = (props: SelectedCalendarsSettingsWebWrapperProps) => { const { scope = SelectedCalendarSettingsScope.User, setScope = () => { return; }, disabledScope, disableConnectionModification, eventTypeId = null, } = props; let queryInput: { eventTypeId: number } | undefined; if (scope === SelectedCalendarSettingsScope.EventType) { queryInput = { eventTypeId: eventTypeId! }; } let initialData: RouterOutputs["viewer"]["calendars"]["connectedCalendars"] | undefined; if (scope === SelectedCalendarSettingsScope.User && props.connectedCalendars) { initialData = props.connectedCalendars; } const query = trpc.viewer.calendars.connectedCalendars.useQuery(queryInput, { initialData, suspense: true, refetchOnWindowFocus: false, }); const isPending = props.isPending; const showScopeSelector = !!props.eventTypeId; let isDisabled = false; if (disabledScope) { isDisabled = disabledScope === scope; } const shouldDisableConnectionModification = isDisabled || disableConnectionModification; return (
{!!(query.data?.connectedCalendars && query.data?.connectedCalendars.length > 0) && ( )}
); }; export const SelectedCalendarsSettingsWebWrapperSkeleton = () => { return (
{[1, 2, 3].map((i) => (
))}
); }; const SelectedCalendarsSettingsHeading = (props: { isConnectedCalendarsPresent: boolean; isPending?: boolean; showScopeSelector: boolean; setScope: (scope: SelectedCalendarSettingsScope) => void; scope: SelectedCalendarSettingsScope; shouldDisableConnectionModification?: boolean; }) => { const { t } = useLocale(); const optionsToSwitchScope = [ { label: "User", value: SelectedCalendarSettingsScope.User }, { label: "Event Type", value: SelectedCalendarSettingsScope.EventType }, ]; const switchScopeSelectValue = optionsToSwitchScope.find((option) => option.value === props.scope); return (

{t("check_for_conflicts")}

{t("select_calendars")}

{!props.shouldDisableConnectionModification && (
{props.isConnectedCalendarsPresent && (
)}
)}
{props.showScopeSelector && (
Using