import type { Credential } from "@prisma/client"; import useAddAppMutation from "@calcom/app-store/_utils/useAddAppMutation"; import { InstallAppButton } from "@calcom/app-store/components"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import showToast from "@calcom/lib/notification"; import { trpc } from "@calcom/trpc/react"; import { App } from "@calcom/types/App"; import { Icon } from "@calcom/ui/Icon"; import Button from "@calcom/ui/v2/core/Button"; interface AppCardProps { app: App; credentials?: Credential[]; } export default function AppCard({ app, credentials }: AppCardProps) { const { t } = useLocale(); const { data: user } = trpc.useQuery(["viewer.me"]); const mutation = useAddAppMutation(null, { onSuccess: () => { showToast(t("app_successfully_installed"), "success"); }, onError: (error) => { if (error instanceof Error) showToast(error.message || t("app_could_not_be_installed"), "error"); }, }); const allowedMultipleInstalls = app.categories && app.categories.indexOf("calendar") > -1; const appAdded = (credentials && credentials.length) || 0; return (
{app.name

{app.name}

{/* TODO: add reviews
{props.rating} stars {props.reviews} reviews
*/}

{app.description}

{app.isGlobal || (credentials && credentials.length > 0 && allowedMultipleInstalls) ? !app.isGlobal && ( { if (useDefaultComponent) { props = { onClick: () => { mutation.mutate({ type: app.type }); }, }; } return ( ); }} /> ) : credentials && credentials.length === 0 && ( { if (useDefaultComponent) { props = { onClick: () => { mutation.mutate({ type: app.type }); }, }; } return ( ); }} /> )}
{appAdded > 0 && ( {t("installed", { count: appAdded })} )} {app.isGlobal && ( {t("default")} )} {app.isProOnly && user?.plan === "FREE" && ( {t("pro")} )}
); }