Files
calendar/packages/features/webhooks/components/WebhookListItem.tsx
T
Hariom BalharaGitHubkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
ce41397517 Routing Forms Improvements - Rename routing_forms to routing-forms (#4546)
* Animate fields list and routes list

* Rename routing_forms slug to routing-forms

* Add comments

* Fixtypo

* Add dropdown separator for consistency

* Fix missing occurences of routing_forms and improve types for webhooks

* Fix weird error about title child is an array

* Fix webhook issues

* Fix webhook tests and issues found during fixing them

* Fix lint errors and warnings

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-09-22 22:53:43 +05:30

77 lines
2.6 KiB
TypeScript

import classNames from "@calcom/lib/classNames";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { inferQueryOutput, trpc } from "@calcom/trpc/react";
import { Icon } from "@calcom/ui/Icon";
import Badge from "@calcom/ui/v2/core/Badge";
import Button from "@calcom/ui/v2/core/Button";
import Switch from "@calcom/ui/v2/core/Switch";
import { Tooltip } from "@calcom/ui/v2/core/Tooltip";
import showToast from "@calcom/ui/v2/core/notifications";
export type TWebhook = inferQueryOutput<"viewer.webhook.list">[number];
export default function WebhookListItem(props: {
webhook: TWebhook;
onEditWebhook: () => void;
lastItem: boolean;
}) {
const { t } = useLocale();
const utils = trpc.useContext();
const { webhook } = props;
const deleteWebhook = trpc.useMutation("viewer.webhook.delete", {
async onSuccess() {
await utils.invalidateQueries(["viewer.webhook.list"]);
showToast(t("webhook_removed_successfully"), "success");
},
});
const toggleWebhook = trpc.useMutation("viewer.webhook.edit", {
async onSuccess(data) {
console.log("data", data);
await utils.invalidateQueries(["viewer.webhook.list"]);
// TODO: Better success message
showToast(t(data?.active ? "enabled" : "disabled"), "success");
},
});
return (
<div className={classNames("flex w-full justify-between p-4", props.lastItem ? "" : "border-b")}>
<div>
<p className="text-sm font-medium text-gray-900">{webhook.subscriberUrl}</p>
<Tooltip content={t("triggers_when")}>
<div className="mt-2.5 w-4/5">
{webhook.eventTriggers.map((trigger) => (
<Badge key={trigger} className="mr-2" variant="gray" bold StartIcon={Icon.FiAlertCircle}>
{t(`${trigger.toLowerCase()}`)}
</Badge>
))}
</div>
</Tooltip>
</div>
<div className="flex items-center space-x-4">
<Switch
defaultChecked={webhook.active}
onCheckedChange={() =>
toggleWebhook.mutate({
id: webhook.id,
active: !webhook.active,
payloadTemplate: webhook.payloadTemplate,
})
}
/>
<Button color="secondary" onClick={props.onEditWebhook}>
{t("edit")}
</Button>
<Button
color="destructive"
StartIcon={Icon.FiTrash}
size="icon"
onClick={() => {
// TODO: Confimation dialog before deleting
deleteWebhook.mutate({ id: webhook.id });
}}
/>
</div>
</div>
);
}