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 { App } from "@calcom/types/App"; import { Icon } from "@calcom/ui/Icon"; import { showToast } from "@calcom/ui/v2"; 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 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, variant: app.variant, slug: app.slug }); }, }; } return ( ); }} /> ) : credentials && credentials.length === 0 && ( { if (useDefaultComponent) { props = { onClick: () => { mutation.mutate({ type: app.type, variant: app.variant, slug: app.slug }); }, }; } return ( ); }} /> )}
{appAdded > 0 && ( {t("installed", { count: appAdded })} )} {app.isGlobal && ( {t("default")} )}
); }