From a69dd959927d4420ed7dc765a89f73f977b331f2 Mon Sep 17 00:00:00 2001 From: anik-ghosh-au7 Date: Sat, 16 Jul 2022 15:59:21 +0530 Subject: [PATCH] update: webhooks --- .../src/components/DeleteWebhookModal.tsx | 106 ++++++++++++++++++ dashboard/src/graphql/mutation/index.ts | 8 ++ dashboard/src/pages/Webhooks.tsx | 7 +- 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 dashboard/src/components/DeleteWebhookModal.tsx diff --git a/dashboard/src/components/DeleteWebhookModal.tsx b/dashboard/src/components/DeleteWebhookModal.tsx new file mode 100644 index 0000000..49e1443 --- /dev/null +++ b/dashboard/src/components/DeleteWebhookModal.tsx @@ -0,0 +1,106 @@ +import React from 'react'; +import { + Button, + Center, + Flex, + MenuItem, + Modal, + ModalBody, + ModalCloseButton, + ModalContent, + ModalFooter, + ModalHeader, + ModalOverlay, + useDisclosure, + Text, + useToast, +} from '@chakra-ui/react'; +import { useClient } from 'urql'; +import { FaRegTrashAlt } from 'react-icons/fa'; +import { DeleteWebhook } from '../graphql/mutation'; +import { capitalizeFirstLetter } from '../utils'; + +interface deleteWebhookModalInputPropTypes { + webhookId: string; + eventName: string; + fetchWebookData: Function; +} + +const DeleteWebhookModal = ({ + webhookId, + eventName, + fetchWebookData, +}: deleteWebhookModalInputPropTypes) => { + const client = useClient(); + const toast = useToast(); + const { isOpen, onOpen, onClose } = useDisclosure(); + + const deleteHandler = async () => { + const res = await client + .mutation(DeleteWebhook, { params: { id: webhookId } }) + .toPromise(); + if (res.error) { + toast({ + title: capitalizeFirstLetter(res.error.message), + isClosable: true, + status: 'error', + position: 'bottom-right', + }); + + return; + } else if (res.data?._delete_webhook) { + toast({ + title: capitalizeFirstLetter(res.data?._delete_webhook.message), + isClosable: true, + status: 'success', + position: 'bottom-right', + }); + } + onClose(); + fetchWebookData(); + }; + return ( + <> + Delete + + + + Delete Webhook + + + Are you sure? + + + Webhook for event {eventName} will be deleted + permanently! + + + + + + + + + + + ); +}; + +export default DeleteWebhookModal; diff --git a/dashboard/src/graphql/mutation/index.ts b/dashboard/src/graphql/mutation/index.ts index ebb7d48..ee7ade3 100644 --- a/dashboard/src/graphql/mutation/index.ts +++ b/dashboard/src/graphql/mutation/index.ts @@ -95,3 +95,11 @@ export const EditWebhook = ` } } `; + +export const DeleteWebhook = ` + mutation deleteWebhook($params: WebhookRequest!) { + _delete_webhook(params: $params) { + message + } + } +`; diff --git a/dashboard/src/pages/Webhooks.tsx b/dashboard/src/pages/Webhooks.tsx index 5c81cb2..ed1f9fa 100644 --- a/dashboard/src/pages/Webhooks.tsx +++ b/dashboard/src/pages/Webhooks.tsx @@ -43,6 +43,7 @@ import { UpdateWebhookModalViews, } from '../constants'; import { WebhooksDataQuery } from '../graphql/queries'; +import DeleteWebhookModal from '../components/DeleteWebhookModal'; interface paginationPropTypes { limit: number; @@ -209,7 +210,11 @@ const Webhooks = () => { selectedWebhook={webhook} fetchWebookData={fetchWebookData} /> - {}}>Delete + {}}>View Logs