Skip to content

Commit 2689cdf

Browse files
authored
perf: pass app data to OmniInstallAppButton to avoid redundant API calls (calcom#26156)
* perf: pass app data to OmniInstallAppButton to avoid redundant API calls * Clean up comments in OmniInstallAppButton component Removed comment about pre-fetched app data and fetching logic.
1 parent efcf688 commit 2689cdf

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

packages/app-store/_components/AppCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ export default function AppCard({
116116
<OmniInstallAppButton
117117
className="ml-auto flex items-center"
118118
appId={app.slug}
119+
app={app}
119120
returnTo={returnTo}
120121
teamId={teamId}
121122
onAppInstallSuccess={onAppInstallSuccess}

packages/app-store/_components/OmniInstallAppButton.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,37 @@ import { Button } from "@calcom/ui/components/button";
55
import { showToast } from "@calcom/ui/components/toast";
66

77
import { InstallAppButton } from "../InstallAppButton";
8+
import type { AppCardApp } from "../types";
89
import useAddAppMutation from "../_utils/useAddAppMutation";
910

11+
type AppData = Pick<AppCardApp, "type" | "variant" | "slug" | "teamsPlanRequired">;
12+
1013
/**
1114
* Use this component to allow installing an app from anywhere on the app.
12-
* Use of this component requires you to remove custom InstallAppButtonComponent so that it can manage the redirection itself
15+
* Use of this component requires you to remove custom InstallAppButtonComponent so that it can manage the redirection itself.
16+
*
17+
* When `app` prop is provided, it will use that data directly instead of fetching via useApp.
18+
* This is useful when the app data is already available (e.g., from the integrations query)
19+
* to avoid redundant API calls that can cause URL length issues when batched.
1320
*/
1421
export default function OmniInstallAppButton({
1522
appId,
23+
app: appProp,
1624
className,
1725
returnTo,
1826
teamId,
1927
onAppInstallSuccess,
2028
}: {
2129
appId: string;
30+
app?: AppData;
2231
className: string;
2332
onAppInstallSuccess: () => void;
2433
returnTo?: string;
2534
teamId?: number;
2635
}) {
2736
const { t } = useLocale();
28-
const { data: app } = useApp(appId);
37+
const { data: fetchedApp } = useApp(appId, { enabled: !appProp });
38+
const app = appProp ?? fetchedApp;
2939

3040
const mutation = useAddAppMutation(null, {
3141
returnTo,

packages/features/apps/hooks/useApp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { useSession } from "next-auth/react";
22

33
import { trpc } from "@calcom/trpc/react";
44

5-
export default function useApp(appId: string) {
5+
export default function useApp(appId: string, options?: { enabled?: boolean }) {
66
const { status } = useSession();
77

88
return trpc.viewer.apps.appById.useQuery(
99
{ appId },
1010
{
11-
enabled: status === "authenticated",
11+
enabled: status === "authenticated" && (options?.enabled ?? true),
1212
}
1313
);
1414
}

0 commit comments

Comments
 (0)