From 0930cf50b62f723f4f108fb7d636482ec668b100 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Mon, 5 Dec 2022 18:43:01 +0530 Subject: [PATCH] BugFix: Link based Apps installation - Opens 2 tabs instead of 1 (#5859) Co-authored-by: Bailey Pumfleet Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- apps/web/components/apps/App.tsx | 2 +- packages/app-store/_components/OmniInstallAppButton.tsx | 2 +- packages/app-store/_utils/useAddAppMutation.ts | 7 +++++-- packages/ui/v2/core/apps/AppCard.tsx | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/web/components/apps/App.tsx b/apps/web/components/apps/App.tsx index 2d50a62002..e2ec06701e 100644 --- a/apps/web/components/apps/App.tsx +++ b/apps/web/components/apps/App.tsx @@ -42,7 +42,7 @@ const Component = ({ const mutation = useAddAppMutation(null, { onSuccess: (data) => { - if (data.setupPending) return; + if (data?.setupPending) return; showToast(t("app_successfully_installed"), "success"); }, onError: (error) => { diff --git a/packages/app-store/_components/OmniInstallAppButton.tsx b/packages/app-store/_components/OmniInstallAppButton.tsx index 4e9a4e7fb9..3ed9f2243f 100644 --- a/packages/app-store/_components/OmniInstallAppButton.tsx +++ b/packages/app-store/_components/OmniInstallAppButton.tsx @@ -21,7 +21,7 @@ export default function OmniInstallAppButton({ appId, className }: { appId: stri //TODO: viewer.appById might be replaced with viewer.apps so that a single query needs to be invalidated. utils.viewer.appById.invalidate({ appId }); utils.viewer.apps.invalidate({ extendsFeature: "EventType" }); - if (data.setupPending) return; + if (data?.setupPending) return; showToast(t("app_successfully_installed"), "success"); }, onError: (error) => { diff --git a/packages/app-store/_utils/useAddAppMutation.ts b/packages/app-store/_utils/useAddAppMutation.ts index d2241dbac0..e7a5c52027 100644 --- a/packages/app-store/_utils/useAddAppMutation.ts +++ b/packages/app-store/_utils/useAddAppMutation.ts @@ -18,13 +18,14 @@ type CustomUseMutationOptions = | Omit, "mutationKey" | "mutationFn" | "onSuccess"> | undefined; +type AddAppMutationData = { setupPending: boolean } | void; type UseAddAppMutationOptions = CustomUseMutationOptions & { - onSuccess: (data: { setupPending: boolean }) => void; + onSuccess: (data: AddAppMutationData) => void; }; function useAddAppMutation(_type: App["type"] | null, options?: UseAddAppMutationOptions) { const mutation = useMutation< - { setupPending: boolean }, + AddAppMutationData, Error, { type?: App["type"]; variant?: string; slug?: string; isOmniInstall?: boolean } | "" >(async (variables) => { @@ -62,6 +63,7 @@ function useAddAppMutation(_type: App["type"] | null, options?: UseAddAppMutatio if (!isOmniInstall) { gotoUrl(json.url, json.newTab); + return; } // Skip redirection only if it is an OmniInstall and redirect URL isn't of some other origin @@ -71,6 +73,7 @@ function useAddAppMutation(_type: App["type"] | null, options?: UseAddAppMutatio if (externalUrl) { // TODO: For Omni installation to authenticate and come back to the page where installation was initiated, some changes need to be done in all apps' add callbacks gotoUrl(json.url, json.newTab); + return; } return { setupPending: externalUrl || json.url.endsWith("/setup") }; diff --git a/packages/ui/v2/core/apps/AppCard.tsx b/packages/ui/v2/core/apps/AppCard.tsx index 3fc81380df..c9f842ff8a 100644 --- a/packages/ui/v2/core/apps/AppCard.tsx +++ b/packages/ui/v2/core/apps/AppCard.tsx @@ -23,7 +23,7 @@ export default function AppCard({ app, credentials, searchText }: AppCardProps) onSuccess: (data) => { // Refresh SSR page content without actual reload router.replace(router.asPath); - if (data.setupPending) return; + if (data?.setupPending) return; showToast(t("app_successfully_installed"), "success"); }, onError: (error) => {