From 01b1f5bcc827617d278155cf348961a124f870f1 Mon Sep 17 00:00:00 2001 From: Vincent Lam Date: Fri, 29 Nov 2024 11:14:01 -0800 Subject: [PATCH] =?UTF-8?q?fix:=20Added=20proper=20updates/interactivity?= =?UTF-8?q?=20on=20the=20"Getting=20started"=20app=20integ=E2=80=A6=20(#17?= =?UTF-8?q?903)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added proper updates/interactivity on the "Getting started" app integrations. - InstallAppButtonWithoutPlanCheck properly vends the mutation data in the render's props - Fixed the improper props wiring in the AppConnectionItem - Added a loading state for reactivity * -Added toaster for error/success confirmation --- .../components/AppConnectionItem.tsx | 16 ++++++++++++++-- .../[[...step]]/onboarding-view.tsx | 2 ++ packages/app-store/components.tsx | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/apps/web/components/getting-started/components/AppConnectionItem.tsx b/apps/web/components/getting-started/components/AppConnectionItem.tsx index 895eb0e36d..55f6464af5 100644 --- a/apps/web/components/getting-started/components/AppConnectionItem.tsx +++ b/apps/web/components/getting-started/components/AppConnectionItem.tsx @@ -1,4 +1,5 @@ import Link from "next/link"; +import { useState } from "react"; import type { TDependencyData } from "@calcom/app-store/_appRegistry"; import { InstallAppButtonWithoutPlanCheck } from "@calcom/app-store/components"; @@ -6,7 +7,7 @@ import { WEBAPP_URL } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import type { App } from "@calcom/types/App"; -import { Badge, Button, Icon } from "@calcom/ui"; +import { Badge, Button, Icon, showToast } from "@calcom/ui"; interface IAppConnectionItem { title: string; @@ -25,6 +26,10 @@ const AppConnectionItem = (props: IAppConnectionItem) => { const { t } = useLocale(); const setDefaultConferencingApp = trpc.viewer.appsRouter.setDefaultConferencingApp.useMutation(); const dependency = props.dependencyData?.find((data) => !data.installed); + + const [isInstalling, setInstalling] = useState(false); + const utils = trpc.useUtils(); + return (
@@ -39,6 +44,12 @@ const AppConnectionItem = (props: IAppConnectionItem) => { if (defaultInstall && slug) { setDefaultConferencingApp.mutate({ slug }); } + setInstalling(false); + utils.viewer.integrations.invalidate(); + showToast(t("app_successfully_installed"), "success"); + }, + onError: (error) => { + if (error instanceof Error) showToast(error.message || t("app_could_not_be_installed"), "error"); }, }} render={(buttonProps) => ( @@ -47,7 +58,7 @@ const AppConnectionItem = (props: IAppConnectionItem) => { color="secondary" disabled={installed || !!dependency} type="button" - loading={buttonProps?.isPending} + loading={isInstalling || buttonProps?.loading} tooltip={ dependency ? (
@@ -86,6 +97,7 @@ const AppConnectionItem = (props: IAppConnectionItem) => { // Save cookie key to return url step document.cookie = `return-to=${window.location.href};path=/;max-age=3600;SameSite=Lax`; buttonProps && buttonProps.onClick && buttonProps?.onClick(event); + setInstalling(true); }}> {installed ? t("installed") : t("connect")} diff --git a/apps/web/modules/getting-started/[[...step]]/onboarding-view.tsx b/apps/web/modules/getting-started/[[...step]]/onboarding-view.tsx index 3bb63630a2..9abf762cef 100644 --- a/apps/web/modules/getting-started/[[...step]]/onboarding-view.tsx +++ b/apps/web/modules/getting-started/[[...step]]/onboarding-view.tsx @@ -4,6 +4,7 @@ import { signOut } from "next-auth/react"; import Head from "next/head"; import { usePathname, useRouter } from "next/navigation"; import { Suspense } from "react"; +import { Toaster } from "react-hot-toast"; import { z } from "zod"; import { classNames } from "@calcom/lib"; @@ -185,6 +186,7 @@ const OnboardingPage = (props: PageProps) => {
+ ); }; diff --git a/packages/app-store/components.tsx b/packages/app-store/components.tsx index 472b2ad10a..fa704b98e4 100644 --- a/packages/app-store/components.tsx +++ b/packages/app-store/components.tsx @@ -37,7 +37,7 @@ export const InstallAppButtonWithoutPlanCheck = ( onClick: () => { mutation.mutate({ type: props.type }); }, - loading: mutation.isPending, + loading: mutation.data?.setupPending, })} );