2022-06-01 17:24:41 +00:00
|
|
|
import { PlusIcon } from "@heroicons/react/solid";
|
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-03-02 16:24:57 +00:00
|
|
|
import { QueryCell } from "@lib/QueryCell";
|
|
|
|
|
2022-06-01 17:24:41 +00:00
|
|
|
import { List } from "@components/List";
|
2022-03-02 16:24:57 +00:00
|
|
|
import { ShellSubHeading } from "@components/Shell";
|
2022-06-01 17:24:41 +00:00
|
|
|
import SkeletonLoader from "@components/apps/SkeletonLoader";
|
2022-03-02 16:24:57 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
export default function WebhookListContainer(props: WebhookListContainerType) {
|
2022-07-20 18:30:57 +00:00
|
|
|
const query = trpc.useQuery(
|
|
|
|
["viewer.webhook.list", { eventTypeId: props.eventTypeId, appId: props.appId }],
|
|
|
|
{
|
|
|
|
suspense: true,
|
|
|
|
}
|
|
|
|
);
|
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
|
|
|
|
color="secondary"
|
|
|
|
size="icon"
|
|
|
|
StartIcon={PlusIcon}
|
|
|
|
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-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}
|
|
|
|
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
|
|
|
)}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|