import useApp from "@calcom/lib/hooks/useApp"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import classNames from "@calcom/ui/classNames"; import { Button } from "@calcom/ui/components/button"; import { showToast } from "@calcom/ui/components/toast"; import { InstallAppButton } from "../InstallAppButton"; import useAddAppMutation from "../_utils/useAddAppMutation"; /** * 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 */ export default function OmniInstallAppButton({ appId, className, returnTo, teamId, onAppInstallSuccess, }: { appId: string; className: string; onAppInstallSuccess: () => void; returnTo?: string; teamId?: number; }) { const { t } = useLocale(); const { data: app } = useApp(appId); const mutation = useAddAppMutation(null, { returnTo, onSuccess: (data) => { onAppInstallSuccess(); if (data?.setupPending) return; showToast(t("app_successfully_installed"), "success"); }, onError: (error) => { if (error instanceof Error) showToast(error.message || t("app_could_not_be_installed"), "error"); }, }); if (!app) { return null; } return ( { if (useDefaultComponent) { props = { ...props, onClick: () => { mutation.mutate({ type: app.type, variant: app.variant, slug: app.slug, ...(teamId && { teamId }), }); }, }; } return ( ); }} /> ); }