refactor: Enabling typescript 5.3.3 in @calcom/trpc (#19394)
* Refactors related to enabling typescript 5.3.3 in @calcom/trpc * Also skip respective tests (obviously logic is broken) * This causes problems for some reason, revert * Bring back QueryCell as it's used by atoms
This commit is contained in:
1 parent
46f73e79c1
commit
07accf700e
22 files changed
+884
-373
No files matched your search
+116
-96
@@ -1,12 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { useReducer } from "react";
|
||||
import { useReducer, Suspense } from "react";
|
||||
|
||||
import { AppList } from "@calcom/features/apps/components/AppList";
|
||||
import DisconnectIntegrationModal from "@calcom/features/apps/components/DisconnectIntegrationModal";
|
||||
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { QueryCell } from "@calcom/trpc/components/QueryCell";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Button, EmptyScreen, showToast, SkeletonContainer, SkeletonText } from "@calcom/ui";
|
||||
|
||||
@@ -37,44 +36,16 @@ const SkeletonLoader = () => {
|
||||
);
|
||||
};
|
||||
|
||||
type ModalState = {
|
||||
isOpen: boolean;
|
||||
credentialId: null | number;
|
||||
};
|
||||
|
||||
export const ConferencingAppsViewWebWrapper = ({
|
||||
title,
|
||||
description,
|
||||
add,
|
||||
}: ConferencingAppsViewWebWrapperProps) => {
|
||||
const InstalledConferencingApps = ({
|
||||
disconnectIntegrationModalCtrl,
|
||||
}: {
|
||||
disconnectIntegrationModalCtrl: ReturnType<typeof useDisconnectIntegrationModalController>;
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useUtils();
|
||||
|
||||
const [modal, updateModal] = useReducer(
|
||||
(data: ModalState, partialData: Partial<ModalState>) => ({ ...data, ...partialData }),
|
||||
{
|
||||
isOpen: false,
|
||||
credentialId: null,
|
||||
}
|
||||
);
|
||||
|
||||
const handleModelClose = () => {
|
||||
updateModal({ isOpen: false, credentialId: null });
|
||||
};
|
||||
|
||||
const handleDisconnect = (credentialId: number) => {
|
||||
updateModal({ isOpen: true, credentialId });
|
||||
};
|
||||
|
||||
const installedIntegrationsQuery = trpc.viewer.integrations.useQuery({
|
||||
variant: "conferencing",
|
||||
onlyInstalled: true,
|
||||
});
|
||||
|
||||
const { data: defaultConferencingApp } = trpc.viewer.getUsersDefaultConferencingApp.useQuery();
|
||||
|
||||
const deleteCredentialMutation = trpc.viewer.deleteCredential.useMutation();
|
||||
|
||||
const updateDefaultAppMutation = trpc.viewer.updateUserDefaultConferencingApp.useMutation();
|
||||
|
||||
const updateLocationsMutation = trpc.viewer.eventTypes.bulkUpdateToDefaultLocation.useMutation();
|
||||
@@ -82,23 +53,10 @@ export const ConferencingAppsViewWebWrapper = ({
|
||||
const { data: eventTypesQueryData, isFetching: isEventTypesFetching } =
|
||||
trpc.viewer.eventTypes.bulkEventFetch.useQuery();
|
||||
|
||||
const handleRemoveApp = ({ credentialId, teamId, callback }: RemoveAppParams) => {
|
||||
deleteCredentialMutation.mutate(
|
||||
{ id: credentialId, teamId },
|
||||
{
|
||||
onSuccess: () => {
|
||||
showToast(t("app_removed_successfully"), "success");
|
||||
callback();
|
||||
utils.viewer.integrations.invalidate();
|
||||
utils.viewer.connectedCalendars.invalidate();
|
||||
},
|
||||
onError: () => {
|
||||
showToast(t("error_removing_app"), "error");
|
||||
callback();
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
const [result] = trpc.viewer.integrations.useSuspenseQuery({
|
||||
variant: "conferencing",
|
||||
onlyInstalled: true,
|
||||
});
|
||||
|
||||
const handleConnectDisconnectIntegrationMenuToggle = () => {
|
||||
utils.viewer.integrations.invalidate();
|
||||
@@ -144,6 +102,104 @@ export const ConferencingAppsViewWebWrapper = ({
|
||||
);
|
||||
};
|
||||
|
||||
if (result.items.length === 0) {
|
||||
return (
|
||||
<EmptyScreen
|
||||
Icon="calendar"
|
||||
headline={t("no_category_apps", {
|
||||
category: t("conferencing").toLowerCase(),
|
||||
})}
|
||||
description={t("no_category_apps_description_conferencing")}
|
||||
buttonRaw={
|
||||
<Button
|
||||
color="secondary"
|
||||
data-testid="connect-conferencing-apps"
|
||||
href="/apps/categories/conferencing">
|
||||
{t("connect_conference_apps")}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<AppList
|
||||
listClassName="rounded-lg rounded-t-none border-t-0 max-w-full"
|
||||
handleDisconnect={disconnectIntegrationModalCtrl.disconnect}
|
||||
data={result}
|
||||
variant="conferencing"
|
||||
defaultConferencingApp={defaultConferencingApp}
|
||||
handleUpdateUserDefaultConferencingApp={handleUpdateUserDefaultConferencingApp}
|
||||
handleBulkUpdateDefaultLocation={handleBulkUpdateDefaultLocation}
|
||||
isBulkUpdateDefaultLocationPending={updateDefaultAppMutation.isPending}
|
||||
eventTypes={eventTypesQueryData?.eventTypes}
|
||||
isEventTypesFetching={isEventTypesFetching}
|
||||
handleConnectDisconnectIntegrationMenuToggle={handleConnectDisconnectIntegrationMenuToggle}
|
||||
handleBulkEditDialogToggle={handleBulkEditDialogToggle}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
type ModalState = {
|
||||
isOpen: boolean;
|
||||
credentialId: null | number;
|
||||
};
|
||||
|
||||
const useDisconnectIntegrationModalController = () => {
|
||||
const [modal, updateModal] = useReducer(
|
||||
(data: ModalState, partialData: Partial<ModalState>) => ({ ...data, ...partialData }),
|
||||
{
|
||||
isOpen: false,
|
||||
credentialId: null,
|
||||
}
|
||||
);
|
||||
|
||||
const handleModelClose = () => {
|
||||
updateModal({ isOpen: false, credentialId: null });
|
||||
};
|
||||
|
||||
const handleDisconnect = (credentialId: number) => {
|
||||
updateModal({ isOpen: true, credentialId });
|
||||
};
|
||||
|
||||
const isModalOpen = () => modal.isOpen;
|
||||
|
||||
return {
|
||||
isModalOpen,
|
||||
credentialId: modal.credentialId,
|
||||
close: handleModelClose,
|
||||
disconnect: handleDisconnect,
|
||||
};
|
||||
};
|
||||
|
||||
export const ConferencingAppsViewWebWrapper = ({
|
||||
title,
|
||||
description,
|
||||
add,
|
||||
}: ConferencingAppsViewWebWrapperProps) => {
|
||||
const { t } = useLocale();
|
||||
const utils = trpc.useUtils();
|
||||
|
||||
const deleteCredentialMutation = trpc.viewer.deleteCredential.useMutation();
|
||||
|
||||
const handleRemoveApp = ({ credentialId, teamId, callback }: RemoveAppParams) => {
|
||||
deleteCredentialMutation.mutate(
|
||||
{ id: credentialId, teamId },
|
||||
{
|
||||
onSuccess: () => {
|
||||
showToast(t("app_removed_successfully"), "success");
|
||||
callback();
|
||||
utils.viewer.integrations.invalidate();
|
||||
utils.viewer.connectedCalendars.invalidate();
|
||||
},
|
||||
onError: () => {
|
||||
showToast(t("error_removing_app"), "error");
|
||||
callback();
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const AddConferencingButton = () => {
|
||||
return (
|
||||
<Button color="secondary" StartIcon="plus" href="/apps/categories/conferencing">
|
||||
@@ -152,6 +208,8 @@ export const ConferencingAppsViewWebWrapper = ({
|
||||
);
|
||||
};
|
||||
|
||||
const disconnectIntegrationModalCtrl = useDisconnectIntegrationModalController();
|
||||
|
||||
return (
|
||||
<SettingsHeader
|
||||
title={title}
|
||||
@@ -160,52 +218,14 @@ export const ConferencingAppsViewWebWrapper = ({
|
||||
borderInShellHeader={true}>
|
||||
<>
|
||||
<div className="bg-default w-full sm:mx-0 xl:mt-0">
|
||||
<QueryCell
|
||||
query={installedIntegrationsQuery}
|
||||
customLoader={<SkeletonLoader />}
|
||||
success={({ data }) => {
|
||||
if (!data.items.length) {
|
||||
return (
|
||||
<EmptyScreen
|
||||
Icon="calendar"
|
||||
headline={t("no_category_apps", {
|
||||
category: t("conferencing").toLowerCase(),
|
||||
})}
|
||||
description={t("no_category_apps_description_conferencing")}
|
||||
buttonRaw={
|
||||
<Button
|
||||
color="secondary"
|
||||
data-testid="connect-conferencing-apps"
|
||||
href="/apps/categories/conferencing">
|
||||
{t("connect_conference_apps")}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<AppList
|
||||
listClassName="rounded-lg rounded-t-none border-t-0 max-w-full"
|
||||
handleDisconnect={handleDisconnect}
|
||||
data={data}
|
||||
variant="conferencing"
|
||||
defaultConferencingApp={defaultConferencingApp}
|
||||
handleUpdateUserDefaultConferencingApp={handleUpdateUserDefaultConferencingApp}
|
||||
handleBulkUpdateDefaultLocation={handleBulkUpdateDefaultLocation}
|
||||
isBulkUpdateDefaultLocationPending={updateDefaultAppMutation.isPending}
|
||||
eventTypes={eventTypesQueryData?.eventTypes}
|
||||
isEventTypesFetching={isEventTypesFetching}
|
||||
handleConnectDisconnectIntegrationMenuToggle={handleConnectDisconnectIntegrationMenuToggle}
|
||||
handleBulkEditDialogToggle={handleBulkEditDialogToggle}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<Suspense fallback={<SkeletonLoader />}>
|
||||
<InstalledConferencingApps disconnectIntegrationModalCtrl={disconnectIntegrationModalCtrl} />
|
||||
</Suspense>
|
||||
</div>
|
||||
<DisconnectIntegrationModal
|
||||
handleModelClose={handleModelClose}
|
||||
isOpen={modal.isOpen}
|
||||
credentialId={modal.credentialId}
|
||||
handleModelClose={disconnectIntegrationModalCtrl.close}
|
||||
isOpen={disconnectIntegrationModalCtrl.isModalOpen()}
|
||||
credentialId={disconnectIntegrationModalCtrl.credentialId}
|
||||
handleRemoveApp={handleRemoveApp}
|
||||
/>
|
||||
</>
|
||||
|
||||
+116
-97
@@ -5,7 +5,7 @@ import AppListCard from "@calcom/features/apps/components/AppListCard";
|
||||
import DisconnectIntegration from "@calcom/features/apps/components/DisconnectIntegration";
|
||||
import { CalendarSwitch } from "@calcom/features/calendars/CalendarSwitch";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { QueryCell } from "@calcom/trpc/components/QueryCell";
|
||||
import type { RouterOutputs } from "@calcom/trpc/react";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { Alert, Select, List } from "@calcom/ui";
|
||||
import AdditionalCalendarSelector from "@calcom/web/components/apps/AdditionalCalendarSelector";
|
||||
@@ -30,8 +30,110 @@ type SelectedCalendarsSettingsWebWrapperProps = {
|
||||
disableConnectionModification?: boolean;
|
||||
};
|
||||
|
||||
export const SelectedCalendarsSettingsWebWrapper = (props: SelectedCalendarsSettingsWebWrapperProps) => {
|
||||
const ConnectedCalendarList = ({
|
||||
fromOnboarding = false,
|
||||
scope,
|
||||
items,
|
||||
disableConnectionModification,
|
||||
eventTypeId,
|
||||
onChanged,
|
||||
destinationCalendarId,
|
||||
isDisabled,
|
||||
}: {
|
||||
fromOnboarding?: boolean;
|
||||
scope: SelectedCalendarSettingsScope;
|
||||
items: RouterOutputs["viewer"]["connectedCalendars"]["connectedCalendars"];
|
||||
disableConnectionModification?: boolean;
|
||||
eventTypeId: number | null;
|
||||
onChanged?: () => unknown | Promise<unknown>;
|
||||
destinationCalendarId?: string;
|
||||
isDisabled: boolean;
|
||||
}) => {
|
||||
const { t } = useLocale();
|
||||
const shouldUseEventTypeScope = scope === SelectedCalendarSettingsScope.EventType;
|
||||
return (
|
||||
<List noBorderTreatment className="p-6 pt-2">
|
||||
{items.map((connectedCalendar) => {
|
||||
if (!!connectedCalendar.calendars && connectedCalendar.calendars.length > 0) {
|
||||
return (
|
||||
<AppListCard
|
||||
key={`list-${connectedCalendar.credentialId}-${scope}`}
|
||||
shouldHighlight
|
||||
slug={connectedCalendar.integration.slug}
|
||||
title={connectedCalendar.integration.name}
|
||||
logo={connectedCalendar.integration.logo}
|
||||
description={connectedCalendar.primary?.email ?? connectedCalendar.integration.description}
|
||||
className="border-subtle mt-4 rounded-lg border"
|
||||
actions={
|
||||
!disableConnectionModification && (
|
||||
<div className="flex w-32 justify-end">
|
||||
<DisconnectIntegration
|
||||
credentialId={connectedCalendar.credentialId}
|
||||
trashIcon
|
||||
onSuccess={onChanged}
|
||||
buttonProps={{ className: "border border-default" }}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}>
|
||||
<div className="border-subtle border-t">
|
||||
{!fromOnboarding && (
|
||||
<>
|
||||
<p className="text-subtle px-5 pt-4 text-sm">{t("toggle_calendars_conflict")}</p>
|
||||
<ul className="space-y-4 px-5 py-4">
|
||||
{connectedCalendar.calendars?.map((cal) => (
|
||||
<CalendarSwitch
|
||||
disabled={isDisabled}
|
||||
key={cal.externalId}
|
||||
externalId={cal.externalId}
|
||||
title={cal.name || "Nameless calendar"}
|
||||
name={cal.name || "Nameless calendar"}
|
||||
type={connectedCalendar.integration.type}
|
||||
isChecked={cal.isSelected}
|
||||
destination={cal.externalId === destinationCalendarId}
|
||||
credentialId={cal.credentialId}
|
||||
eventTypeId={shouldUseEventTypeScope ? eventTypeId : null}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</AppListCard>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Alert
|
||||
key={`alert-${connectedCalendar.credentialId}`}
|
||||
severity="warning"
|
||||
title={t("something_went_wrong")}
|
||||
message={
|
||||
<span>
|
||||
<Link href={`/apps/${connectedCalendar.integration.slug}`}>
|
||||
{connectedCalendar.integration.name}
|
||||
</Link>
|
||||
: {t("calendar_error")}
|
||||
</span>
|
||||
}
|
||||
iconClassName="h-10 w-10 ml-2 mr-1 mt-0.5"
|
||||
actions={
|
||||
<div className="flex w-32 justify-end">
|
||||
<DisconnectIntegration
|
||||
credentialId={connectedCalendar.credentialId}
|
||||
trashIcon
|
||||
onSuccess={onChanged}
|
||||
buttonProps={{ className: "border border-default" }}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</List>
|
||||
);
|
||||
};
|
||||
|
||||
export const SelectedCalendarsSettingsWebWrapper = (props: SelectedCalendarsSettingsWebWrapperProps) => {
|
||||
const {
|
||||
scope = SelectedCalendarSettingsScope.User,
|
||||
setScope = () => {
|
||||
@@ -52,9 +154,8 @@ export const SelectedCalendarsSettingsWebWrapper = (props: SelectedCalendarsSett
|
||||
refetchOnWindowFocus: false,
|
||||
}
|
||||
);
|
||||
const { fromOnboarding, isPending } = props;
|
||||
const { isPending } = props;
|
||||
const showScopeSelector = !!props.eventTypeId;
|
||||
const shouldUseEventTypeScope = scope === SelectedCalendarSettingsScope.EventType;
|
||||
const isDisabled = disabledScope ? disabledScope === scope : false;
|
||||
const shouldDisableConnectionModification = isDisabled || disableConnectionModification;
|
||||
return (
|
||||
@@ -68,99 +169,17 @@ export const SelectedCalendarsSettingsWebWrapper = (props: SelectedCalendarsSett
|
||||
scope={scope}
|
||||
shouldDisableConnectionModification={shouldDisableConnectionModification}
|
||||
/>
|
||||
<QueryCell
|
||||
query={query}
|
||||
success={({ data }) => {
|
||||
if (!data.connectedCalendars.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<List noBorderTreatment className="p-6 pt-2">
|
||||
{data.connectedCalendars.map((connectedCalendar) => {
|
||||
if (!!connectedCalendar.calendars && connectedCalendar.calendars.length > 0) {
|
||||
return (
|
||||
<AppListCard
|
||||
key={`list-${connectedCalendar.credentialId}-${scope}`}
|
||||
shouldHighlight
|
||||
slug={connectedCalendar.integration.slug}
|
||||
title={connectedCalendar.integration.name}
|
||||
logo={connectedCalendar.integration.logo}
|
||||
description={
|
||||
connectedCalendar.primary?.email ?? connectedCalendar.integration.description
|
||||
}
|
||||
className="border-subtle mt-4 rounded-lg border"
|
||||
actions={
|
||||
!disableConnectionModification && (
|
||||
<div className="flex w-32 justify-end">
|
||||
<DisconnectIntegration
|
||||
credentialId={connectedCalendar.credentialId}
|
||||
trashIcon
|
||||
onSuccess={props.onChanged}
|
||||
buttonProps={{ className: "border border-default" }}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}>
|
||||
<div className="border-subtle border-t">
|
||||
{!fromOnboarding && (
|
||||
<>
|
||||
<p className="text-subtle px-5 pt-4 text-sm">
|
||||
{t("toggle_calendars_conflict")}
|
||||
</p>
|
||||
<ul className="space-y-4 px-5 py-4">
|
||||
{connectedCalendar.calendars?.map((cal) => (
|
||||
<CalendarSwitch
|
||||
disabled={isDisabled}
|
||||
key={cal.externalId}
|
||||
externalId={cal.externalId}
|
||||
title={cal.name || "Nameless calendar"}
|
||||
name={cal.name || "Nameless calendar"}
|
||||
type={connectedCalendar.integration.type}
|
||||
isChecked={cal.isSelected}
|
||||
destination={cal.externalId === props.destinationCalendarId}
|
||||
credentialId={cal.credentialId}
|
||||
eventTypeId={shouldUseEventTypeScope ? eventTypeId : null}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</AppListCard>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Alert
|
||||
key={`alert-${connectedCalendar.credentialId}`}
|
||||
severity="warning"
|
||||
title={t("something_went_wrong")}
|
||||
message={
|
||||
<span>
|
||||
<Link href={`/apps/${connectedCalendar.integration.slug}`}>
|
||||
{connectedCalendar.integration.name}
|
||||
</Link>
|
||||
: {t("calendar_error")}
|
||||
</span>
|
||||
}
|
||||
iconClassName="h-10 w-10 ml-2 mr-1 mt-0.5"
|
||||
actions={
|
||||
<div className="flex w-32 justify-end">
|
||||
<DisconnectIntegration
|
||||
credentialId={connectedCalendar.credentialId}
|
||||
trashIcon
|
||||
onSuccess={props.onChanged}
|
||||
buttonProps={{ className: "border border-default" }}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</List>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{query.data?.connectedCalendars && query.data?.connectedCalendars.length > 0 ? (
|
||||
<ConnectedCalendarList
|
||||
fromOnboarding={props.fromOnboarding}
|
||||
scope={scope}
|
||||
disableConnectionModification={disableConnectionModification}
|
||||
onChanged={props.onChanged}
|
||||
eventTypeId={eventTypeId}
|
||||
items={query.data.connectedCalendars}
|
||||
isDisabled={isDisabled}
|
||||
/>
|
||||
) : null}
|
||||
</SelectedCalendarsSettings>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user