Scheduling infrastructure for absolutely everyone.
perf: pass app data to OmniInstallAppButton to avoid redundant API calls (#26156)
Anik Dhabal Babu2689cdfdff8c
diff --git a/packages/app-store/_components/AppCard.tsx b/packages/app-store/_components/AppCard.tsxindex 6e49da67ecf..a24a594f734 100644--- a/packages/app-store/_components/AppCard.tsx+++ b/packages/app-store/_components/AppCard.tsx@@ -116,6 +116,7 @@ export default function AppCard({<OmniInstallAppButtonclassName="ml-auto flex items-center"appId={app.slug}+ app={app}returnTo={returnTo}teamId={teamId}onAppInstallSuccess={onAppInstallSuccess}diff --git a/packages/app-store/_components/OmniInstallAppButton.tsx b/packages/app-store/_components/OmniInstallAppButton.tsxindex 95069fe7174..9d4cd207443 100644--- a/packages/app-store/_components/OmniInstallAppButton.tsx+++ b/packages/app-store/_components/OmniInstallAppButton.tsx@@ -5,27 +5,37 @@ import { Button } from "@calcom/ui/components/button";import { showToast } from "@calcom/ui/components/toast";import { InstallAppButton } from "../InstallAppButton";+import type { AppCardApp } from "../types";import useAddAppMutation from "../_utils/useAddAppMutation";+type AppData = Pick<AppCardApp, "type" | "variant" | "slug" | "teamsPlanRequired">;+/*** Use this component to allow installing an app from anywhere on the app.- * Use of this component requires you to remove custom InstallAppButtonComponent so that it can manage the redirection itself+ * Use of this component requires you to remove custom InstallAppButtonComponent so that it can manage the redirection itself.+ *+ * When `app` prop is provided, it will use that data directly instead of fetching via useApp.+ * This is useful when the app data is already available (e.g., from the integrations query)+ * to avoid redundant API calls that can cause URL length issues when batched.*/export default function OmniInstallAppButton({appId,+ app: appProp,className,returnTo,teamId,onAppInstallSuccess,}: {appId: string;+ app?: AppData;className: string;onAppInstallSuccess: () => void;returnTo?: string;teamId?: number;}) {const { t } = useLocale();- const { data: app } = useApp(appId);+ const { data: fetchedApp } = useApp(appId, { enabled: !appProp });+ const app = appProp ?? fetchedApp;const mutation = useAddAppMutation(null, {returnTo,diff --git a/packages/features/apps/hooks/useApp.ts b/packages/features/apps/hooks/useApp.tsindex f008eb72f66..bc58b48bb1c 100644--- a/packages/features/apps/hooks/useApp.ts+++ b/packages/features/apps/hooks/useApp.ts@@ -2,13 +2,13 @@ import { useSession } from "next-auth/react";import { trpc } from "@calcom/trpc/react";-export default function useApp(appId: string) {+export default function useApp(appId: string, options?: { enabled?: boolean }) {const { status } = useSession();return trpc.viewer.apps.appById.useQuery({ appId },{- enabled: status === "authenticated",+ enabled: status === "authenticated" && (options?.enabled ?? true),});}