import {
ChevronDownIcon,
ChevronUpIcon,
PencilAltIcon,
SwitchHorizontalIcon,
TrashIcon,
} from "@heroicons/react/outline";
import { ClipboardIcon } from "@heroicons/react/solid";
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@radix-ui/react-collapsible";
import Image from "next/image";
import React, { useState } from "react";
import { Controller, useForm, useWatch } from "react-hook-form";
import { QueryCell } from "@lib/QueryCell";
import classNames from "@lib/classNames";
import { getErrorFromUnknown } from "@lib/errors";
import { useLocale } from "@lib/hooks/useLocale";
import showToast from "@lib/notification";
import { inferQueryOutput, trpc } from "@lib/trpc";
import { WEBHOOK_TRIGGER_EVENTS } from "@lib/webhooks/constants";
import { Dialog, DialogContent, DialogFooter, DialogTrigger } from "@components/Dialog";
import { List, ListItem, ListItemText, ListItemTitle } from "@components/List";
import Shell, { ShellSubHeading } from "@components/Shell";
import { Tooltip } from "@components/Tooltip";
import ConfirmationDialogContent from "@components/dialog/ConfirmationDialogContent";
import { FieldsetLegend, Form, InputGroupBox, TextField } from "@components/form/fields";
import CalendarsList from "@components/integrations/CalendarsList";
import ConnectIntegration from "@components/integrations/ConnectIntegrations";
import ConnectedCalendarsList from "@components/integrations/ConnectedCalendarsList";
import DisconnectIntegration from "@components/integrations/DisconnectIntegration";
import IntegrationListItem from "@components/integrations/IntegrationListItem";
import SubHeadingTitleWithConnections from "@components/integrations/SubHeadingTitleWithConnections";
import { Alert } from "@components/ui/Alert";
import Button from "@components/ui/Button";
import Switch from "@components/ui/Switch";
type TIntegrations = inferQueryOutput<"viewer.integrations">;
type TWebhook = TIntegrations["webhooks"][number];
function WebhookListItem(props: { webhook: TWebhook; onEditWebhook: () => void }) {
const { t } = useLocale();
const utils = trpc.useContext();
const deleteWebhook = trpc.useMutation("viewer.webhook.delete", {
async onSuccess() {
await utils.invalidateQueries(["viewer.integrations"]);
},
});
return (
{props.webhook.subscriberUrl}
{props.webhook.eventTriggers.map((eventTrigger, ind) => (
{t(`${eventTrigger.toLowerCase()}`)}
))}
);
}
function WebhookTestDisclosure() {
const subscriberUrl: string = useWatch({ name: "subscriberUrl" });
const { t } = useLocale();
const [open, setOpen] = useState(false);
const mutation = trpc.useMutation("viewer.webhook.testTrigger", {
onError(err) {
showToast(err.message, "error");
},
});
return (
setOpen(!open)}>
{t("webhook_test")}{" "}
{open ? (
) : (
)}
{t("webhook_response")}
{!mutation.data &&
{t("no_data_yet")}}
{mutation.status === "success" && (
<>
{mutation.data.status === 200 ? t("success") : t("failed")}
{JSON.stringify(mutation.data, null, 4)}
>
)}
);
}
function WebhookDialogForm(props: {
//
defaultValues?: TWebhook;
handleClose: () => void;
}) {
const { t } = useLocale();
const utils = trpc.useContext();
const {
defaultValues = {
id: "",
eventTriggers: WEBHOOK_TRIGGER_EVENTS,
subscriberUrl: "",
active: true,
},
} = props;
const form = useForm({
defaultValues,
});
return (
);
}
function WebhookEmbed(props: { webhooks: TWebhook[] }) {
const { t } = useLocale();
const user = trpc.useQuery(["viewer.me"]).data;
const iframeTemplate = ``;
const htmlTemplate = `${t(
"schedule_a_meeting"
)}${iframeTemplate}`;
const [newWebhookModal, setNewWebhookModal] = useState(false);
const [editModalOpen, setEditModalOpen] = useState(false);
const [editing, setEditing] = useState(null);
return (
<>
Webhooks
Automation
{props.webhooks.length ? (
{props.webhooks.map((item) => (
{
setEditing(item);
setEditModalOpen(true);
}}
/>
))}
) : null}
{/* {!!props.webhooks.length && (
{}}
onEditWebhook={editWebhook}>
)} */}
{/* New webhook dialog */}
{/* Edit webhook dialog */}
>
);
}
function ConnectOrDisconnectIntegrationButton(props: {
//
credentialIds: number[];
type: string;
installed: boolean;
}) {
const [credentialId] = props.credentialIds;
const utils = trpc.useContext();
const handleOpenChange = () => {
utils.invalidateQueries(["viewer.integrations"]);
};
if (credentialId) {
return (
(
)}
onOpenChange={handleOpenChange}
/>
);
}
if (!props.installed) {
return (
);
}
/** We don't need to "Connect", just show that it's installed */
if (props.type === "daily_video") {
return (
Installed
);
}
return (
(
)}
onOpenChange={handleOpenChange}
/>
);
}
export default function IntegrationsPage() {
const query = trpc.useQuery(["viewer.integrations"]);
const utils = trpc.useContext();
const handleOpenChange = () => {
utils.invalidateQueries(["viewer.integrations"]);
};
return (
{
return (
<>
}
/>
{data.conferencing.items.map((item) => (
}
/>
))}
}
/>
{data.payment.items.map((item) => (
}
/>
))}
}
subtitle={
<>
Configure how your links integrate with your calendars.
You can override these settings on a per event basis.
>
}
/>
{data.connectedCalendars.length > 0 && (
<>
}
/>
>
)}
>
);
}}
/>
);
}