2022-03-23 22:00:30 +00:00
|
|
|
import Link from "next/link";
|
2022-09-15 19:53:09 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import React, { useState } from "react";
|
2022-03-23 22:00:30 +00:00
|
|
|
|
2022-07-14 12:40:53 +00:00
|
|
|
import useAddAppMutation from "@calcom/app-store/_utils/useAddAppMutation";
|
2022-03-23 22:00:30 +00:00
|
|
|
import { InstallAppButton } from "@calcom/app-store/components";
|
2022-07-28 19:58:26 +00:00
|
|
|
import LicenseRequired from "@calcom/features/ee/common/components/LicenseRequired";
|
2022-03-23 22:00:30 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-07-14 12:40:53 +00:00
|
|
|
import showToast from "@calcom/lib/notification";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-03-23 22:00:30 +00:00
|
|
|
import { App as AppType } from "@calcom/types/App";
|
2022-06-01 17:24:41 +00:00
|
|
|
import { Button, SkeletonButton } from "@calcom/ui";
|
2022-07-27 02:24:00 +00:00
|
|
|
import { Icon } from "@calcom/ui/Icon";
|
2022-07-28 19:58:26 +00:00
|
|
|
import Shell from "@calcom/ui/Shell";
|
2022-09-03 17:14:02 +00:00
|
|
|
import Badge from "@calcom/ui/v2/core/Badge";
|
2022-03-23 22:00:30 +00:00
|
|
|
|
2022-09-15 19:53:09 +00:00
|
|
|
import DisconnectIntegration from "@components/integrations/DisconnectIntegration";
|
|
|
|
|
2022-07-14 12:40:53 +00:00
|
|
|
const Component = ({
|
2022-03-23 22:00:30 +00:00
|
|
|
name,
|
|
|
|
type,
|
|
|
|
logo,
|
|
|
|
body,
|
|
|
|
categories,
|
|
|
|
author,
|
|
|
|
price = 0,
|
|
|
|
commission,
|
|
|
|
isGlobal = false,
|
|
|
|
feeType,
|
|
|
|
docs,
|
|
|
|
website,
|
|
|
|
email,
|
|
|
|
tos,
|
|
|
|
privacy,
|
2022-07-14 12:40:53 +00:00
|
|
|
isProOnly,
|
|
|
|
}: Parameters<typeof App>[0]) => {
|
2022-03-23 22:00:30 +00:00
|
|
|
const { t } = useLocale();
|
2022-09-15 19:53:09 +00:00
|
|
|
const router = useRouter();
|
2022-07-14 12:40:53 +00:00
|
|
|
const { data: user } = trpc.useQuery(["viewer.me"]);
|
|
|
|
|
2022-09-15 19:53:09 +00:00
|
|
|
const utils = trpc.useContext();
|
|
|
|
const handleOpenChange = () => {
|
|
|
|
utils.invalidateQueries(["viewer.integrations"]);
|
|
|
|
router.replace("/apps/installed");
|
|
|
|
};
|
|
|
|
|
2022-07-14 12:40:53 +00:00
|
|
|
const mutation = useAddAppMutation(null, {
|
|
|
|
onSuccess: () => {
|
|
|
|
showToast("App successfully installed", "success");
|
|
|
|
},
|
|
|
|
onError: (error) => {
|
|
|
|
if (error instanceof Error) showToast(error.message || "App could not be installed", "error");
|
|
|
|
},
|
|
|
|
});
|
2022-03-23 22:00:30 +00:00
|
|
|
|
|
|
|
const priceInDollar = Intl.NumberFormat("en-US", {
|
|
|
|
style: "currency",
|
|
|
|
currency: "USD",
|
|
|
|
useGrouping: false,
|
|
|
|
}).format(price);
|
2022-09-15 19:53:09 +00:00
|
|
|
|
|
|
|
const [existingCredentials, setExistingCredentials] = useState<number[]>([]);
|
|
|
|
const appCredentials = trpc.useQuery(["viewer.appCredentialsByType", { appType: type }], {
|
|
|
|
onSuccess(data) {
|
|
|
|
setExistingCredentials(data);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-06-13 21:06:12 +00:00
|
|
|
const allowedMultipleInstalls = categories.indexOf("calendar") > -1;
|
2022-07-14 12:40:53 +00:00
|
|
|
|
2022-03-23 22:00:30 +00:00
|
|
|
return (
|
2022-07-14 12:40:53 +00:00
|
|
|
<div className="-mx-4 md:-mx-8">
|
2022-09-02 19:00:41 +00:00
|
|
|
<div className="px-8">
|
2022-07-14 12:40:53 +00:00
|
|
|
<Link href="/apps">
|
|
|
|
<a className="mt-2 inline-flex px-1 py-2 text-sm text-gray-500 hover:bg-gray-100 hover:text-gray-800">
|
2022-08-03 16:01:29 +00:00
|
|
|
<Icon.FiChevronLeft className="h-5 w-5" /> {t("browse_apps")}
|
2022-07-14 12:40:53 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
<div className="items-center justify-between py-4 sm:flex sm:py-8">
|
|
|
|
<div className="flex">
|
|
|
|
<img className="h-16 w-16 rounded-sm" src={logo} alt={name} />
|
|
|
|
<header className="px-4 py-2">
|
|
|
|
<div className="flex items-center">
|
|
|
|
<h1 className="font-cal text-xl text-gray-900">{name}</h1>
|
2022-03-23 22:00:30 +00:00
|
|
|
</div>
|
2022-07-14 12:40:53 +00:00
|
|
|
<h2 className="text-sm text-gray-500">
|
|
|
|
<span className="capitalize">{categories[0]}</span> • {t("published_by", { author })}
|
|
|
|
</h2>
|
|
|
|
</header>
|
|
|
|
</div>
|
2022-03-23 22:00:30 +00:00
|
|
|
|
2022-07-14 12:40:53 +00:00
|
|
|
<div className="mt-4 sm:mt-0 sm:text-right">
|
2022-09-15 19:53:09 +00:00
|
|
|
{!appCredentials.isLoading ? (
|
|
|
|
isGlobal ||
|
|
|
|
(existingCredentials.length > 0 && allowedMultipleInstalls ? (
|
2022-07-19 09:33:29 +00:00
|
|
|
<div className="flex space-x-3">
|
2022-08-03 16:01:29 +00:00
|
|
|
<Button StartIcon={Icon.FiCheck} color="secondary" disabled>
|
2022-09-15 19:53:09 +00:00
|
|
|
{existingCredentials.length > 0
|
|
|
|
? t("active_install", { count: existingCredentials.length })
|
2022-07-14 12:40:53 +00:00
|
|
|
: t("globally_install")}
|
|
|
|
</Button>
|
2022-07-19 09:33:29 +00:00
|
|
|
{!isGlobal && (
|
|
|
|
<InstallAppButton
|
|
|
|
type={type}
|
|
|
|
isProOnly={isProOnly}
|
|
|
|
render={({ useDefaultComponent, ...props }) => {
|
|
|
|
if (useDefaultComponent) {
|
|
|
|
props = {
|
|
|
|
onClick: () => {
|
|
|
|
mutation.mutate({ type });
|
|
|
|
},
|
|
|
|
loading: mutation.isLoading,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return (
|
2022-08-03 16:01:29 +00:00
|
|
|
<Button StartIcon={Icon.FiPlus} {...props} data-testid="install-app-button">
|
2022-07-19 09:33:29 +00:00
|
|
|
{t("add_another")}
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2022-07-14 12:40:53 +00:00
|
|
|
</div>
|
2022-09-15 19:53:09 +00:00
|
|
|
) : existingCredentials.length > 0 ? (
|
|
|
|
<DisconnectIntegration
|
|
|
|
id={existingCredentials[0]}
|
|
|
|
render={(btnProps) => (
|
|
|
|
<Button {...btnProps} color="warn" data-testid={type + "-integration-disconnect-button"}>
|
|
|
|
{t("disconnect")}
|
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
onOpenChange={handleOpenChange}
|
|
|
|
/>
|
2022-07-14 12:40:53 +00:00
|
|
|
) : (
|
|
|
|
<InstallAppButton
|
|
|
|
type={type}
|
|
|
|
isProOnly={isProOnly}
|
|
|
|
render={({ useDefaultComponent, ...props }) => {
|
|
|
|
if (useDefaultComponent) {
|
|
|
|
props = {
|
|
|
|
onClick: () => {
|
|
|
|
mutation.mutate({ type });
|
|
|
|
},
|
|
|
|
loading: mutation.isLoading,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Button data-testid="install-app-button" {...props}>
|
|
|
|
{t("install_app")}
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
2022-09-15 19:53:09 +00:00
|
|
|
))
|
2022-07-14 12:40:53 +00:00
|
|
|
) : (
|
|
|
|
<SkeletonButton width="24" height="10" />
|
|
|
|
)}
|
|
|
|
{price !== 0 && (
|
|
|
|
<small className="block text-right">
|
|
|
|
{feeType === "usage-based" ? commission + "% + " + priceInDollar + "/booking" : priceInDollar}
|
|
|
|
{feeType === "monthly" && "/" + t("month")}
|
|
|
|
</small>
|
|
|
|
)}
|
2022-03-23 22:00:30 +00:00
|
|
|
</div>
|
2022-07-14 12:40:53 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-23 22:00:30 +00:00
|
|
|
|
2022-07-14 12:40:53 +00:00
|
|
|
<div className="justify-between px-8 py-10 md:flex">
|
|
|
|
<div className="prose-sm prose mb-6">{body}</div>
|
|
|
|
<div className="md:max-w-80 flex-1 md:ml-8">
|
|
|
|
<h4 className="font-medium text-gray-900 ">{t("categories")}</h4>
|
|
|
|
<div className="space-x-2">
|
|
|
|
{categories.map((category) => (
|
|
|
|
<Link href={"/apps/categories/" + category} key={category}>
|
|
|
|
<a>
|
|
|
|
<Badge variant="success">{category}</Badge>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
))}
|
2022-03-23 22:00:30 +00:00
|
|
|
</div>
|
2022-07-14 12:40:53 +00:00
|
|
|
<h4 className="mt-8 font-medium text-gray-900 ">{t("pricing")}</h4>
|
|
|
|
<small>
|
|
|
|
{price === 0 ? (
|
|
|
|
"Free"
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
{Intl.NumberFormat("en-US", {
|
|
|
|
style: "currency",
|
|
|
|
currency: "USD",
|
|
|
|
useGrouping: false,
|
|
|
|
}).format(price)}
|
|
|
|
{feeType === "monthly" && "/" + t("month")}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</small>
|
|
|
|
<h4 className="mt-8 mb-2 font-medium text-gray-900 ">{t("learn_more")}</h4>
|
|
|
|
<ul className="prose -ml-1 -mr-1 text-xs leading-5">
|
|
|
|
{docs && (
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
className="text-blue-500 no-underline hover:underline"
|
|
|
|
href={docs}>
|
2022-08-03 16:01:29 +00:00
|
|
|
<Icon.FiBookOpen className="mr-1 -mt-1 inline h-4 w-4" />
|
2022-07-14 12:40:53 +00:00
|
|
|
{t("documentation")}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
{website && (
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
className="text-blue-500 no-underline hover:underline"
|
|
|
|
href={website}>
|
2022-08-03 16:01:29 +00:00
|
|
|
<Icon.FiExternalLink className="mr-1 -mt-px inline h-4 w-4" />
|
2022-07-14 12:40:53 +00:00
|
|
|
{website.replace("https://", "")}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
{email && (
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
className="text-blue-500 no-underline hover:underline"
|
|
|
|
href={"mailto:" + email}>
|
2022-08-03 16:01:29 +00:00
|
|
|
<Icon.FiMail className="mr-1 -mt-px inline h-4 w-4" />
|
2022-07-27 02:24:00 +00:00
|
|
|
|
2022-07-14 12:40:53 +00:00
|
|
|
{email}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
{tos && (
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
className="text-blue-500 no-underline hover:underline"
|
|
|
|
href={tos}>
|
2022-08-03 16:01:29 +00:00
|
|
|
<Icon.FiFile className="mr-1 -mt-px inline h-4 w-4" />
|
2022-07-14 12:40:53 +00:00
|
|
|
{t("terms_of_service")}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
{privacy && (
|
|
|
|
<li>
|
|
|
|
<a
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
className="text-blue-500 no-underline hover:underline"
|
|
|
|
href={privacy}>
|
2022-08-03 16:01:29 +00:00
|
|
|
<Icon.FiShield className="mr-1 -mt-px inline h-4 w-4" />
|
2022-07-14 12:40:53 +00:00
|
|
|
{t("privacy_policy")}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
)}
|
|
|
|
</ul>
|
|
|
|
<hr className="my-6" />
|
|
|
|
<small className="leading-1 block text-gray-500">
|
|
|
|
Every app published on the Cal.com App Store is open source and thoroughly tested via peer
|
|
|
|
reviews. Nevertheless, Cal.com, Inc. does not endorse or certify these apps unless they are
|
|
|
|
published by Cal.com. If you encounter inappropriate content or behaviour please report it.
|
|
|
|
</small>
|
2022-09-21 16:07:48 +00:00
|
|
|
<a className="mt-2 block text-xs text-red-500" href="mailto:help@cal.com">
|
2022-08-03 16:01:29 +00:00
|
|
|
<Icon.FiFlag className="inline h-3 w-3" /> Report App
|
2022-07-14 12:40:53 +00:00
|
|
|
</a>
|
2022-03-23 22:00:30 +00:00
|
|
|
</div>
|
2022-07-14 12:40:53 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function App(props: {
|
|
|
|
name: string;
|
|
|
|
type: AppType["type"];
|
|
|
|
isGlobal?: AppType["isGlobal"];
|
|
|
|
logo: string;
|
|
|
|
body: React.ReactNode;
|
|
|
|
categories: string[];
|
|
|
|
author: string;
|
|
|
|
pro?: boolean;
|
|
|
|
price?: number;
|
|
|
|
commission?: number;
|
|
|
|
feeType?: AppType["feeType"];
|
|
|
|
docs?: string;
|
|
|
|
website?: string;
|
|
|
|
email: string; // required
|
|
|
|
tos?: string;
|
|
|
|
privacy?: string;
|
|
|
|
licenseRequired: AppType["licenseRequired"];
|
|
|
|
isProOnly: AppType["isProOnly"];
|
|
|
|
}) {
|
|
|
|
return (
|
|
|
|
<Shell large isPublic>
|
|
|
|
{props.licenseRequired ? (
|
|
|
|
<LicenseRequired>
|
|
|
|
<Component {...props} />
|
|
|
|
</LicenseRequired>
|
|
|
|
) : (
|
|
|
|
<Component {...props} />
|
|
|
|
)}
|
|
|
|
</Shell>
|
2022-03-23 22:00:30 +00:00
|
|
|
);
|
|
|
|
}
|