BugFix: Link based Apps installation - Opens 2 tabs instead of 1 (#5859)

Co-authored-by: Bailey Pumfleet <bailey@pumfleet.co.uk>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Hariom Balhara 2022-12-05 18:43:01 +05:30 committed by GitHub
parent c37cddd0b7
commit 0930cf50b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 5 deletions

View File

@ -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) => {

View File

@ -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) => {

View File

@ -18,13 +18,14 @@ type CustomUseMutationOptions =
| Omit<UseMutationOptions<unknown, unknown, unknown, unknown>, "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") };

View File

@ -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) => {