2021-10-19 10:35:52 +00:00
|
|
|
import { ClipboardIcon } from "@heroicons/react/solid";
|
2021-10-12 09:35:44 +00:00
|
|
|
import Image from "next/image";
|
2022-02-01 21:48:40 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
import { JSONObject } from "superjson/dist/types";
|
2021-10-12 09:35:44 +00:00
|
|
|
|
2022-03-16 23:36:43 +00:00
|
|
|
import showToast from "@calcom/lib/notification";
|
|
|
|
import { Alert } from "@calcom/ui/Alert";
|
|
|
|
import Button from "@calcom/ui/Button";
|
|
|
|
|
2021-10-12 09:35:44 +00:00
|
|
|
import { QueryCell } from "@lib/QueryCell";
|
|
|
|
import classNames from "@lib/classNames";
|
2022-02-01 21:48:40 +00:00
|
|
|
import { HttpError } from "@lib/core/http/error";
|
2021-10-18 07:02:25 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
2022-03-02 16:24:57 +00:00
|
|
|
import { trpc } from "@lib/trpc";
|
2021-10-12 09:35:44 +00:00
|
|
|
|
2021-10-30 15:54:21 +00:00
|
|
|
import { ClientSuspense } from "@components/ClientSuspense";
|
2021-10-12 09:35:44 +00:00
|
|
|
import { List, ListItem, ListItemText, ListItemTitle } from "@components/List";
|
2021-10-30 15:54:21 +00:00
|
|
|
import Loader from "@components/Loader";
|
2021-10-12 09:35:44 +00:00
|
|
|
import Shell, { ShellSubHeading } from "@components/Shell";
|
2021-10-30 15:54:21 +00:00
|
|
|
import { CalendarListContainer } from "@components/integrations/CalendarListContainer";
|
2021-10-20 15:42:40 +00:00
|
|
|
import ConnectIntegration from "@components/integrations/ConnectIntegrations";
|
|
|
|
import DisconnectIntegration from "@components/integrations/DisconnectIntegration";
|
|
|
|
import IntegrationListItem from "@components/integrations/IntegrationListItem";
|
|
|
|
import SubHeadingTitleWithConnections from "@components/integrations/SubHeadingTitleWithConnections";
|
2022-03-02 16:24:57 +00:00
|
|
|
import WebhookListContainer from "@components/webhook/WebhookListContainer";
|
2021-10-30 15:54:21 +00:00
|
|
|
|
|
|
|
function IframeEmbedContainer() {
|
|
|
|
const { t } = useLocale();
|
|
|
|
// doesn't need suspense as it should already be loaded
|
2021-10-18 07:02:25 +00:00
|
|
|
const user = trpc.useQuery(["viewer.me"]).data;
|
|
|
|
|
|
|
|
const iframeTemplate = `<iframe src="${process.env.NEXT_PUBLIC_BASE_URL}/${user?.username}" frameborder="0" allowfullscreen></iframe>`;
|
|
|
|
const htmlTemplate = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>${t(
|
|
|
|
"schedule_a_meeting"
|
|
|
|
)}</title><style>body {margin: 0;}iframe {height: calc(100vh - 4px);width: calc(100vw - 4px);box-sizing: border-box;}</style></head><body>${iframeTemplate}</body></html>`;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2021-10-30 15:54:21 +00:00
|
|
|
<ShellSubHeading title={t("iframe_embed")} subtitle={t("embed_calcom")} className="mt-10" />
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="lg:col-span-9 lg:pb-8">
|
2021-10-19 10:35:52 +00:00
|
|
|
<List>
|
|
|
|
<ListItem className={classNames("flex-col")}>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className={classNames("flex w-full flex-1 items-center space-x-2 p-3 rtl:space-x-reverse")}>
|
2021-10-19 10:35:52 +00:00
|
|
|
<Image width={40} height={40} src="/integrations/embed.svg" alt="Embed" />
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="flex-grow truncate pl-2">
|
2021-10-19 10:35:52 +00:00
|
|
|
<ListItemTitle component="h3">{t("standard_iframe")}</ListItemTitle>
|
2021-11-07 15:52:48 +00:00
|
|
|
<ListItemText component="p">{t("embed_your_calendar")}</ListItemText>
|
2021-10-19 10:35:52 +00:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<input
|
|
|
|
id="iframe"
|
2022-02-09 22:32:31 +00:00
|
|
|
className="focus:border-brand px-2 py-1 text-sm text-gray-500 focus:ring-black"
|
2021-10-19 10:35:52 +00:00
|
|
|
placeholder={t("loading")}
|
|
|
|
defaultValue={iframeTemplate}
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
navigator.clipboard.writeText(iframeTemplate);
|
|
|
|
showToast("Copied to clipboard", "success");
|
|
|
|
}}>
|
2022-02-09 00:05:13 +00:00
|
|
|
<ClipboardIcon className="-mb-0.5 h-4 w-4 text-gray-800 ltr:mr-2 rtl:ml-2" />
|
2021-10-19 10:35:52 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ListItem>
|
|
|
|
<ListItem className={classNames("flex-col")}>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className={classNames("flex w-full flex-1 items-center space-x-2 p-3 rtl:space-x-reverse")}>
|
2021-10-19 10:35:52 +00:00
|
|
|
<Image width={40} height={40} src="/integrations/embed.svg" alt="Embed" />
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="flex-grow truncate pl-2">
|
2021-10-19 10:35:52 +00:00
|
|
|
<ListItemTitle component="h3">{t("responsive_fullscreen_iframe")}</ListItemTitle>
|
|
|
|
<ListItemText component="p">A fullscreen scheduling experience on your website</ListItemText>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<input
|
|
|
|
id="fullscreen"
|
2022-02-09 22:32:31 +00:00
|
|
|
className="focus:border-brand px-2 py-1 text-sm text-gray-500 focus:ring-black"
|
2021-10-19 10:35:52 +00:00
|
|
|
placeholder={t("loading")}
|
|
|
|
defaultValue={htmlTemplate}
|
|
|
|
readOnly
|
|
|
|
/>
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
navigator.clipboard.writeText(htmlTemplate);
|
|
|
|
showToast("Copied to clipboard", "success");
|
|
|
|
}}>
|
2022-02-09 00:05:13 +00:00
|
|
|
<ClipboardIcon className="-mb-0.5 h-4 w-4 text-gray-800 ltr:mr-2 rtl:ml-2" />
|
2021-10-19 10:35:52 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ListItem>
|
|
|
|
</List>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="grid grid-cols-2 space-x-4 rtl:space-x-reverse">
|
2021-10-18 07:02:25 +00:00
|
|
|
<div>
|
2021-10-19 10:35:52 +00:00
|
|
|
<label htmlFor="iframe" className="block text-sm font-medium text-gray-700"></label>
|
|
|
|
<div className="mt-1"></div>
|
2021-10-18 07:02:25 +00:00
|
|
|
</div>
|
|
|
|
<div>
|
2021-10-19 10:35:52 +00:00
|
|
|
<label htmlFor="fullscreen" className="block text-sm font-medium text-gray-700"></label>
|
|
|
|
<div className="mt-1"></div>
|
2021-10-18 07:02:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-12 09:35:44 +00:00
|
|
|
function ConnectOrDisconnectIntegrationButton(props: {
|
|
|
|
//
|
2021-10-13 11:35:25 +00:00
|
|
|
credentialIds: number[];
|
|
|
|
type: string;
|
2021-10-12 09:35:44 +00:00
|
|
|
installed: boolean;
|
|
|
|
}) {
|
2021-11-07 15:52:48 +00:00
|
|
|
const { t } = useLocale();
|
2021-10-13 11:35:25 +00:00
|
|
|
const [credentialId] = props.credentialIds;
|
2021-10-20 15:42:40 +00:00
|
|
|
const utils = trpc.useContext();
|
|
|
|
const handleOpenChange = () => {
|
|
|
|
utils.invalidateQueries(["viewer.integrations"]);
|
|
|
|
};
|
|
|
|
|
2021-10-13 11:35:25 +00:00
|
|
|
if (credentialId) {
|
2021-10-12 09:35:44 +00:00
|
|
|
return (
|
|
|
|
<DisconnectIntegration
|
2021-10-13 11:35:25 +00:00
|
|
|
id={credentialId}
|
2021-10-12 09:35:44 +00:00
|
|
|
render={(btnProps) => (
|
2021-12-17 16:58:23 +00:00
|
|
|
<Button {...btnProps} color="warn" data-testid="integration-connection-button">
|
2021-11-07 15:52:48 +00:00
|
|
|
{t("disconnect")}
|
2021-10-12 09:35:44 +00:00
|
|
|
</Button>
|
|
|
|
)}
|
2021-10-20 15:42:40 +00:00
|
|
|
onOpenChange={handleOpenChange}
|
2021-10-12 09:35:44 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (!props.installed) {
|
2021-10-12 11:39:02 +00:00
|
|
|
return (
|
2021-10-15 10:01:49 +00:00
|
|
|
<div className="flex items-center truncate">
|
2021-11-07 15:52:48 +00:00
|
|
|
<Alert severity="warning" title={t("not_installed")} />
|
2021-10-12 11:39:02 +00:00
|
|
|
</div>
|
|
|
|
);
|
2021-10-12 09:35:44 +00:00
|
|
|
}
|
2021-10-13 11:35:25 +00:00
|
|
|
/** We don't need to "Connect", just show that it's installed */
|
2022-02-08 22:12:28 +00:00
|
|
|
if (["daily_video", "huddle01_video", "jitsi_video"].includes(props.type)) {
|
2021-10-13 11:35:25 +00:00
|
|
|
return (
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="truncate px-3 py-2">
|
2021-11-07 15:52:48 +00:00
|
|
|
<h3 className="text-sm font-medium text-gray-700">{t("installed")}</h3>
|
2021-10-13 11:35:25 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2021-10-12 09:35:44 +00:00
|
|
|
return (
|
2021-10-15 10:01:49 +00:00
|
|
|
<ConnectIntegration
|
|
|
|
type={props.type}
|
|
|
|
render={(btnProps) => (
|
2021-12-17 16:58:23 +00:00
|
|
|
<Button color="secondary" {...btnProps} data-testid="integration-connection-button">
|
2021-11-07 15:52:48 +00:00
|
|
|
{t("connect")}
|
2021-10-15 10:01:49 +00:00
|
|
|
</Button>
|
|
|
|
)}
|
2021-10-20 15:42:40 +00:00
|
|
|
onOpenChange={handleOpenChange}
|
2021-10-15 10:01:49 +00:00
|
|
|
/>
|
2021-10-12 09:35:44 +00:00
|
|
|
);
|
|
|
|
}
|
2021-09-11 07:54:13 +00:00
|
|
|
|
2021-10-30 15:54:21 +00:00
|
|
|
function IntegrationsContainer() {
|
2021-11-07 15:52:48 +00:00
|
|
|
const { t } = useLocale();
|
2021-10-30 15:54:21 +00:00
|
|
|
const query = trpc.useQuery(["viewer.integrations"], { suspense: true });
|
2021-07-20 18:18:26 +00:00
|
|
|
return (
|
2021-10-30 15:54:21 +00:00
|
|
|
<QueryCell
|
|
|
|
query={query}
|
|
|
|
success={({ data }) => (
|
|
|
|
<>
|
|
|
|
<ShellSubHeading
|
|
|
|
title={
|
|
|
|
<SubHeadingTitleWithConnections
|
2021-11-07 15:52:48 +00:00
|
|
|
title={t("conferencing")}
|
2021-10-30 15:54:21 +00:00
|
|
|
numConnections={data.conferencing.numActive}
|
2021-10-12 09:35:44 +00:00
|
|
|
/>
|
2021-10-30 15:54:21 +00:00
|
|
|
}
|
|
|
|
/>
|
|
|
|
<List>
|
|
|
|
{data.conferencing.items.map((item) => (
|
|
|
|
<IntegrationListItem
|
|
|
|
key={item.title}
|
|
|
|
{...item}
|
|
|
|
actions={<ConnectOrDisconnectIntegrationButton {...item} />}
|
2021-10-12 09:35:44 +00:00
|
|
|
/>
|
2021-10-30 15:54:21 +00:00
|
|
|
))}
|
|
|
|
</List>
|
2021-10-12 09:35:44 +00:00
|
|
|
|
2021-10-30 15:54:21 +00:00
|
|
|
<ShellSubHeading
|
|
|
|
className="mt-10"
|
2021-11-07 15:52:48 +00:00
|
|
|
title={
|
|
|
|
<SubHeadingTitleWithConnections title={t("payment")} numConnections={data.payment.numActive} />
|
|
|
|
}
|
2021-10-30 15:54:21 +00:00
|
|
|
/>
|
|
|
|
<List>
|
|
|
|
{data.payment.items.map((item) => (
|
|
|
|
<IntegrationListItem
|
|
|
|
key={item.title}
|
|
|
|
{...item}
|
|
|
|
actions={<ConnectOrDisconnectIntegrationButton {...item} />}
|
2021-10-12 09:35:44 +00:00
|
|
|
/>
|
2021-10-30 15:54:21 +00:00
|
|
|
))}
|
|
|
|
</List>
|
|
|
|
</>
|
|
|
|
)}></QueryCell>
|
|
|
|
);
|
|
|
|
}
|
2021-10-12 09:35:44 +00:00
|
|
|
|
2022-02-01 21:48:40 +00:00
|
|
|
function Web3Container() {
|
|
|
|
const { t } = useLocale();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ShellSubHeading title="Web3" subtitle={t("meet_people_with_the_same_tokens")} />
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="lg:col-span-9 lg:pb-8">
|
2022-02-01 21:48:40 +00:00
|
|
|
<List>
|
|
|
|
<ListItem className={classNames("flex-col")}>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className={classNames("flex w-full flex-1 items-center space-x-2 p-3")}>
|
2022-02-01 21:48:40 +00:00
|
|
|
<Image width={40} height={40} src="/integrations/metamask.svg" alt="Embed" />
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="flex-grow truncate pl-2">
|
2022-02-01 21:48:40 +00:00
|
|
|
<ListItemTitle component="h3">
|
|
|
|
MetaMask (
|
|
|
|
<a className="text-blue-500" target="_blank" href="https://cal.com/web3" rel="noreferrer">
|
|
|
|
Read more
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
</ListItemTitle>
|
|
|
|
<ListItemText component="p">{t("only_book_people_and_allow")}</ListItemText>
|
|
|
|
</div>
|
|
|
|
<Web3ConnectBtn />
|
|
|
|
</div>
|
|
|
|
</ListItem>
|
|
|
|
</List>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function Web3ConnectBtn() {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
const [connectionBtn, setConnection] = useState(false);
|
|
|
|
const result = trpc.useQuery(["viewer.web3Integration"]);
|
|
|
|
const mutation = trpc.useMutation("viewer.enableOrDisableWeb3", {
|
|
|
|
onSuccess: async (result) => {
|
|
|
|
const { key = {} } = result as JSONObject;
|
|
|
|
|
|
|
|
if ((key as JSONObject).isWeb3Active) {
|
|
|
|
showToast(t("web3_metamask_added"), "success");
|
|
|
|
} else {
|
|
|
|
showToast(t("web3_metamask_disconnected"), "success");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onError: (err) => {
|
|
|
|
if (err instanceof HttpError) {
|
|
|
|
const message = `${err.statusCode}: ${err.message}`;
|
|
|
|
showToast(message, "error");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (result.data) {
|
|
|
|
setConnection(result.data.isWeb3Active as boolean);
|
|
|
|
}
|
|
|
|
}, [result]);
|
|
|
|
|
|
|
|
const enableOrDisableWeb3 = async (mutation: any) => {
|
|
|
|
const result = await mutation.mutateAsync({});
|
|
|
|
setConnection(result.key.isWeb3Active);
|
|
|
|
utils.invalidateQueries("viewer.web3Integration");
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
2022-02-01 21:52:54 +00:00
|
|
|
loading={mutation.isLoading}
|
2022-02-01 21:48:40 +00:00
|
|
|
color={connectionBtn ? "warn" : "secondary"}
|
|
|
|
disabled={result.isLoading || mutation.isLoading}
|
|
|
|
onClick={async () => await enableOrDisableWeb3(mutation)}
|
|
|
|
data-testid="metamask">
|
|
|
|
{connectionBtn ? t("remove") : t("add")}
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-30 15:54:21 +00:00
|
|
|
export default function IntegrationsPage() {
|
2021-11-07 15:52:48 +00:00
|
|
|
const { t } = useLocale();
|
|
|
|
|
2021-10-30 15:54:21 +00:00
|
|
|
return (
|
2021-11-07 15:52:48 +00:00
|
|
|
<Shell heading={t("integrations")} subtitle={t("connect_your_favourite_apps")}>
|
2021-10-30 15:54:21 +00:00
|
|
|
<ClientSuspense fallback={<Loader />}>
|
|
|
|
<IntegrationsContainer />
|
|
|
|
<CalendarListContainer />
|
2022-03-03 14:16:07 +00:00
|
|
|
<WebhookListContainer title={t("webhooks")} subtitle={t("receive_cal_meeting_data")} />
|
2021-10-30 15:54:21 +00:00
|
|
|
<IframeEmbedContainer />
|
2022-02-01 21:48:40 +00:00
|
|
|
<Web3Container />
|
2021-10-30 15:54:21 +00:00
|
|
|
</ClientSuspense>
|
2021-10-12 09:35:44 +00:00
|
|
|
</Shell>
|
2021-07-20 18:18:26 +00:00
|
|
|
);
|
2021-03-30 13:23:51 +00:00
|
|
|
}
|