fix: Duplicate calls syncing Calendar integrations (#26858)
* fix: Duplicate calls syncing Calendar integrations * fix: TS error in handler * Minor fixup * Set cacheUpdatedAt at correct depth of array * Import RouterOutputs
This commit is contained in:
1 parent
a708e088c9
commit
1dd2652080
8 files changed
+164
-133
No files matched your search
@@ -1,8 +1,4 @@
|
||||
import Link from "next/link";
|
||||
import React from "react";
|
||||
|
||||
import AppListCard from "@calcom/web/modules/apps/components/AppListCard";
|
||||
import CredentialActionsDropdown from "@calcom/web/modules/apps/components/CredentialActionsDropdown";
|
||||
import { SelectedCalendarsSettings } from "@calcom/atoms/selected-calendars/SelectedCalendarsSettings";
|
||||
import AdditionalCalendarSelector from "@calcom/features/calendars/AdditionalCalendarSelector";
|
||||
import { CalendarSwitch } from "@calcom/features/calendars/CalendarSwitch";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
@@ -11,8 +7,10 @@ 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 { SelectedCalendarsSettings } from "@calcom/atoms/selected-calendars/SelectedCalendarsSettings";
|
||||
import AppListCard from "@calcom/web/modules/apps/components/AppListCard";
|
||||
import CredentialActionsDropdown from "@calcom/web/modules/apps/components/CredentialActionsDropdown";
|
||||
import Link from "next/link";
|
||||
import React from "react";
|
||||
|
||||
export enum SelectedCalendarSettingsScope {
|
||||
User = "user",
|
||||
@@ -30,6 +28,7 @@ type SelectedCalendarsSettingsWebWrapperProps = {
|
||||
scope?: SelectedCalendarSettingsScope;
|
||||
setScope?: (scope: SelectedCalendarSettingsScope) => void;
|
||||
disableConnectionModification?: boolean;
|
||||
connectedCalendars?: RouterOutputs["viewer"]["calendars"]["connectedCalendars"];
|
||||
};
|
||||
|
||||
const ConnectedCalendarList = ({
|
||||
@@ -92,7 +91,12 @@ const ConnectedCalendarList = ({
|
||||
isChecked={cal.isSelected}
|
||||
destination={cal.externalId === destinationCalendarId}
|
||||
credentialId={cal.credentialId}
|
||||
eventTypeId={shouldUseEventTypeScope ? eventTypeId : null}
|
||||
eventTypeId={(() => {
|
||||
if (shouldUseEventTypeScope) {
|
||||
return eventTypeId;
|
||||
}
|
||||
return null;
|
||||
})()}
|
||||
delegationCredentialId={connectedCalendar.delegationCredentialId || null}
|
||||
/>
|
||||
))}
|
||||
@@ -145,19 +149,30 @@ export const SelectedCalendarsSettingsWebWrapper = (props: SelectedCalendarsSett
|
||||
eventTypeId = null,
|
||||
} = props;
|
||||
|
||||
const query = trpc.viewer.calendars.connectedCalendars.useQuery(
|
||||
{
|
||||
eventTypeId: scope === SelectedCalendarSettingsScope.EventType ? eventTypeId! : null,
|
||||
},
|
||||
{
|
||||
suspense: true,
|
||||
refetchOnWindowFocus: false,
|
||||
}
|
||||
);
|
||||
let queryInput: { eventTypeId: number } | undefined;
|
||||
if (scope === SelectedCalendarSettingsScope.EventType) {
|
||||
queryInput = { eventTypeId: eventTypeId! };
|
||||
}
|
||||
|
||||
const { isPending } = props;
|
||||
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;
|
||||
const isDisabled = disabledScope ? disabledScope === scope : false;
|
||||
|
||||
let isDisabled = false;
|
||||
if (disabledScope) {
|
||||
isDisabled = disabledScope === scope;
|
||||
}
|
||||
|
||||
const shouldDisableConnectionModification = isDisabled || disableConnectionModification;
|
||||
return (
|
||||
<div>
|
||||
@@ -170,7 +185,7 @@ export const SelectedCalendarsSettingsWebWrapper = (props: SelectedCalendarsSett
|
||||
scope={scope}
|
||||
shouldDisableConnectionModification={shouldDisableConnectionModification}
|
||||
/>
|
||||
{query.data?.connectedCalendars && query.data?.connectedCalendars.length > 0 ? (
|
||||
{!!(query.data?.connectedCalendars && query.data?.connectedCalendars.length > 0) && (
|
||||
<ConnectedCalendarList
|
||||
fromOnboarding={props.fromOnboarding}
|
||||
scope={scope}
|
||||
@@ -180,7 +195,7 @@ export const SelectedCalendarsSettingsWebWrapper = (props: SelectedCalendarsSett
|
||||
items={query.data.connectedCalendars}
|
||||
isDisabled={isDisabled}
|
||||
/>
|
||||
) : null}
|
||||
)}
|
||||
</SelectedCalendarsSettings>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user