2022-03-02 16:24:57 +00:00
|
|
|
import { PencilAltIcon, TrashIcon } from "@heroicons/react/outline";
|
|
|
|
|
|
|
|
import classNames from "@calcom/lib/classNames";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { inferQueryOutput, trpc } from "@calcom/trpc/react";
|
2022-03-16 23:36:43 +00:00
|
|
|
import Button from "@calcom/ui/Button";
|
|
|
|
import { Dialog, DialogTrigger } from "@calcom/ui/Dialog";
|
2022-05-05 21:16:25 +00:00
|
|
|
import { Tooltip } from "@calcom/ui/Tooltip";
|
2022-03-02 16:24:57 +00:00
|
|
|
|
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
|
|
|
|
|
|
|
import { ListItem } from "@components/List";
|
|
|
|
import ConfirmationDialogContent from "@components/dialog/ConfirmationDialogContent";
|
|
|
|
|
|
|
|
export type TWebhook = inferQueryOutput<"viewer.webhook.list">[number];
|
|
|
|
|
|
|
|
export default 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.webhook.list"]);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
2022-06-01 17:24:41 +00:00
|
|
|
<ListItem className={classNames("flex w-full p-4", props.webhook.active ? "bg-white" : "bg-gray-100")}>
|
2022-03-02 16:24:57 +00:00
|
|
|
<div className="flex w-full justify-between">
|
|
|
|
<div className="flex max-w-full flex-col truncate">
|
|
|
|
<div className="flex space-y-1">
|
|
|
|
<span
|
|
|
|
className={classNames(
|
|
|
|
"truncate text-sm",
|
2022-06-01 17:24:41 +00:00
|
|
|
props.webhook.active ? "text-neutral-700" : "text-neutral-400"
|
2022-03-02 16:24:57 +00:00
|
|
|
)}>
|
|
|
|
{props.webhook.subscriberUrl}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div className="mt-2 flex">
|
|
|
|
<span className="flex flex-col space-x-2 space-y-1 text-xs sm:flex-row sm:space-y-0 sm:rtl:space-x-reverse">
|
|
|
|
{props.webhook.eventTriggers.map((eventTrigger, ind) => (
|
|
|
|
<span
|
|
|
|
key={ind}
|
|
|
|
className={classNames(
|
2022-06-01 17:24:41 +00:00
|
|
|
"w-max rounded-sm px-1 text-xs",
|
|
|
|
props.webhook.active ? "text-grey-200 bg-gray-200" : "bg-grey-50 text-neutral-400"
|
2022-03-02 16:24:57 +00:00
|
|
|
)}>
|
|
|
|
{t(`${eventTrigger.toLowerCase()}`)}
|
|
|
|
</span>
|
|
|
|
))}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="flex">
|
2022-07-14 11:32:28 +00:00
|
|
|
<Tooltip side="top" content={t("edit_webhook")}>
|
2022-03-02 16:24:57 +00:00
|
|
|
<Button
|
|
|
|
onClick={() => props.onEditWebhook()}
|
|
|
|
color="minimal"
|
|
|
|
size="icon"
|
|
|
|
StartIcon={PencilAltIcon}
|
2022-07-13 21:14:16 +00:00
|
|
|
className="ml-4 w-full self-center p-2"
|
|
|
|
/>
|
2022-03-02 16:24:57 +00:00
|
|
|
</Tooltip>
|
|
|
|
<Dialog>
|
2022-07-14 11:32:28 +00:00
|
|
|
<Tooltip side="top" content={t("delete_webhook")}>
|
2022-03-02 16:24:57 +00:00
|
|
|
<DialogTrigger asChild>
|
|
|
|
<Button
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
color="minimal"
|
|
|
|
size="icon"
|
|
|
|
StartIcon={TrashIcon}
|
2022-07-13 21:14:16 +00:00
|
|
|
className="ml-2 w-full self-center p-2"
|
|
|
|
/>
|
2022-03-02 16:24:57 +00:00
|
|
|
</DialogTrigger>
|
|
|
|
</Tooltip>
|
|
|
|
<ConfirmationDialogContent
|
|
|
|
variety="danger"
|
|
|
|
title={t("delete_webhook")}
|
|
|
|
confirmBtnText={t("confirm_delete_webhook")}
|
|
|
|
cancelBtnText={t("cancel")}
|
|
|
|
onConfirm={() =>
|
|
|
|
deleteWebhook.mutate({
|
|
|
|
id: props.webhook.id,
|
|
|
|
eventTypeId: props.webhook.eventTypeId || undefined,
|
|
|
|
})
|
|
|
|
}>
|
|
|
|
{t("delete_webhook_confirmation_message")}
|
|
|
|
</ConfirmationDialogContent>
|
|
|
|
</Dialog>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
}
|