Files
calendar/packages/app-store/_components/OmniInstallAppButton.tsx
T
Benny JooandGitHub eba0635a07 refactor: eliminate all @calcom/trpc/react imports and tRPC hooks from @calcom/features (#27728)
* migrate booker layout selector

* move schedule hooks and types

* migrate feature opt in components

* migrate feedback dialog

* update

* migrate schedule hooks

* migrate useSegments

* update

* update import paths

* fix import paths

* mv useTimesForSchedule back to features

* fix

* add useEvent to web

* remove the old file

* update imports

* clean up

* migrate Segment

* update imports

* update imports

* fix name

* fix tests

* fix

* fix

* update imports

* remove trpc/react

* remove trpc dependency from package.json

* rm

* wip

* wip

* fix types

* fix

* migrate PhoneInput

* mv LocationInput

* remove dead file

* update import paths

* rm dead import

* rm useApp hook

* cleanup

* wip

* restore

* wip

* remove dead code

* fix

* simplify

* fix

* fix

* fix

* fix

* fix

* fix

* format

* format

* restore

* remove prop
2026-02-09 08:39:28 -03:00

79 lines
2.3 KiB
TypeScript

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 useAddAppMutation from "../_utils/useAddAppMutation";
import { InstallAppButton } from "../InstallAppButton";
import type { AppCardApp } from "../types";
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.
*
* The `app` prop must be provided with the necessary app data.
* This avoids redundant API calls and prevents the app-store package from depending on the features package.
*/
export default function OmniInstallAppButton({
app,
className,
returnTo,
teamId,
onAppInstallSuccess,
}: {
app: AppData;
className: string;
onAppInstallSuccess: () => void;
returnTo?: string;
teamId?: number;
}) {
const { t } = useLocale();
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");
},
});
return (
<InstallAppButton
type={app.type}
teamsPlanRequired={app.teamsPlanRequired}
wrapperClassName={classNames("[@media(max-width:260px)]:w-full", className)}
render={({ useDefaultComponent, ...props }) => {
if (useDefaultComponent) {
props = {
...props,
onClick: () => {
mutation.mutate({
type: app.type,
variant: app.variant,
slug: app.slug,
...(teamId && { teamId }),
});
},
};
}
return (
<Button
loading={mutation.isPending}
color="secondary"
className="[@media(max-width:260px)]:w-full [@media(max-width:260px)]:justify-center"
StartIcon="plus"
{...props}>
{t("add")}
</Button>
);
}}
/>
);
}