2022-07-30 03:01:13 +00:00
|
|
|
import { useRouter } from "next/router";
|
2022-03-02 16:24:57 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
|
2022-07-22 17:27:06 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-03-16 23:36:43 +00:00
|
|
|
import Button from "@calcom/ui/Button";
|
|
|
|
import { Dialog, DialogContent } from "@calcom/ui/Dialog";
|
2022-07-27 02:24:00 +00:00
|
|
|
import { Icon } from "@calcom/ui/Icon";
|
2022-07-28 19:58:26 +00:00
|
|
|
import { List } from "@calcom/ui/List";
|
|
|
|
import { ShellSubHeading } from "@calcom/ui/Shell";
|
|
|
|
import SkeletonLoader from "@calcom/ui/apps/SkeletonLoader";
|
2022-03-16 23:36:43 +00:00
|
|
|
|
2022-03-02 16:24:57 +00:00
|
|
|
import { QueryCell } from "@lib/QueryCell";
|
|
|
|
|
|
|
|
import WebhookDialogForm from "@components/webhook/WebhookDialogForm";
|
|
|
|
import WebhookListItem, { TWebhook } from "@components/webhook/WebhookListItem";
|
|
|
|
|
|
|
|
export type WebhookListContainerType = {
|
2022-03-03 14:16:07 +00:00
|
|
|
title: string;
|
|
|
|
subtitle: string;
|
2022-03-02 16:24:57 +00:00
|
|
|
eventTypeId?: number;
|
2022-07-20 18:30:57 +00:00
|
|
|
appId?: string;
|
2022-03-02 16:24:57 +00:00
|
|
|
};
|
|
|
|
|
2022-09-12 19:07:52 +00:00
|
|
|
/** @deprecated Moved to `packages/features/webhooks` */
|
2022-03-02 16:24:57 +00:00
|
|
|
export default function WebhookListContainer(props: WebhookListContainerType) {
|
2022-07-30 03:01:13 +00:00
|
|
|
const router = useRouter();
|
2022-07-20 18:30:57 +00:00
|
|
|
const query = trpc.useQuery(
|
|
|
|
["viewer.webhook.list", { eventTypeId: props.eventTypeId, appId: props.appId }],
|
|
|
|
{
|
|
|
|
suspense: true,
|
2022-07-30 03:01:13 +00:00
|
|
|
enabled: router.isReady,
|
2022-07-20 18:30:57 +00:00
|
|
|
}
|
|
|
|
);
|
2022-03-02 16:24:57 +00:00
|
|
|
const [newWebhookModal, setNewWebhookModal] = useState(false);
|
|
|
|
const [editModalOpen, setEditModalOpen] = useState(false);
|
|
|
|
const [editing, setEditing] = useState<TWebhook | null>(null);
|
|
|
|
return (
|
|
|
|
<QueryCell
|
|
|
|
query={query}
|
2022-06-01 17:24:41 +00:00
|
|
|
customLoader={<SkeletonLoader />}
|
2022-03-02 16:24:57 +00:00
|
|
|
success={({ data }) => (
|
2022-06-01 17:24:41 +00:00
|
|
|
<div className="border-b border-gray-200 py-8 pl-2 pr-1">
|
|
|
|
<ShellSubHeading
|
|
|
|
className="mt-2"
|
|
|
|
title={props.title}
|
|
|
|
subtitle={props.subtitle}
|
|
|
|
actions={
|
|
|
|
<Button
|
2022-07-27 02:24:00 +00:00
|
|
|
color="minimal"
|
2022-06-01 17:24:41 +00:00
|
|
|
size="icon"
|
2022-08-03 16:01:29 +00:00
|
|
|
StartIcon={Icon.FiPlus}
|
2022-06-01 17:24:41 +00:00
|
|
|
onClick={() => setNewWebhookModal(true)}
|
|
|
|
data-testid="new_webhook"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
/>
|
2022-03-02 16:24:57 +00:00
|
|
|
|
|
|
|
{data.length ? (
|
2022-06-01 17:24:41 +00:00
|
|
|
<List className="mt-6">
|
2022-03-02 16:24:57 +00:00
|
|
|
{data.map((item) => (
|
|
|
|
<WebhookListItem
|
|
|
|
key={item.id}
|
|
|
|
webhook={item}
|
|
|
|
onEditWebhook={() => {
|
|
|
|
setEditing(item);
|
|
|
|
setEditModalOpen(true);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</List>
|
|
|
|
) : null}
|
|
|
|
|
|
|
|
{/* New webhook dialog */}
|
|
|
|
<Dialog open={newWebhookModal} onOpenChange={(isOpen) => !isOpen && setNewWebhookModal(false)}>
|
|
|
|
<DialogContent>
|
|
|
|
<WebhookDialogForm
|
2022-07-20 18:30:57 +00:00
|
|
|
app={props.appId}
|
2022-08-31 03:41:23 +00:00
|
|
|
webhooks={data}
|
2022-03-02 16:24:57 +00:00
|
|
|
eventTypeId={props.eventTypeId}
|
|
|
|
handleClose={() => setNewWebhookModal(false)}
|
|
|
|
/>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
{/* Edit webhook dialog */}
|
|
|
|
<Dialog open={editModalOpen} onOpenChange={(isOpen) => !isOpen && setEditModalOpen(false)}>
|
|
|
|
<DialogContent>
|
|
|
|
{editing && (
|
|
|
|
<WebhookDialogForm
|
2022-07-20 18:30:57 +00:00
|
|
|
app={props.appId}
|
2022-03-02 16:24:57 +00:00
|
|
|
key={editing.id}
|
2022-08-31 03:41:23 +00:00
|
|
|
webhooks={data}
|
2022-03-02 16:24:57 +00:00
|
|
|
eventTypeId={props.eventTypeId || undefined}
|
|
|
|
handleClose={() => setEditModalOpen(false)}
|
|
|
|
defaultValues={editing}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
2022-06-01 17:24:41 +00:00
|
|
|
</div>
|
2022-03-02 16:24:57 +00:00
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|