diff --git a/packages/console/src/pages/WebhookDetails/WebhookSettings/components/TestWebhook/index.module.scss b/packages/console/src/pages/WebhookDetails/WebhookSettings/components/TestWebhook/index.module.scss new file mode 100644 index 000000000..b129fceec --- /dev/null +++ b/packages/console/src/pages/WebhookDetails/WebhookSettings/components/TestWebhook/index.module.scss @@ -0,0 +1,14 @@ +@use '@/scss/underscore' as _; + +.container { + display: flex; + align-items: center; + border: 1px solid var(--color-divider); + border-radius: _.unit(2); + padding: _.unit(4); +} + +.description { + font: var(--font-body-2); + margin-right: _.unit(3); +} diff --git a/packages/console/src/pages/WebhookDetails/WebhookSettings/components/TestWebhook/index.tsx b/packages/console/src/pages/WebhookDetails/WebhookSettings/components/TestWebhook/index.tsx new file mode 100644 index 000000000..110b4e9a3 --- /dev/null +++ b/packages/console/src/pages/WebhookDetails/WebhookSettings/components/TestWebhook/index.tsx @@ -0,0 +1,66 @@ +import { useState } from 'react'; +import { useFormContext } from 'react-hook-form'; +import { toast } from 'react-hot-toast'; +import { useTranslation } from 'react-i18next'; + +import Button from '@/components/Button'; +import DynamicT from '@/components/DynamicT'; +import FormField from '@/components/FormField'; +import useApi from '@/hooks/use-api'; +import { type WebhookDetailsFormType } from '@/pages/WebhookDetails/types'; +import { webhookDetailsParser } from '@/pages/WebhookDetails/utils'; + +import * as styles from './index.module.scss'; + +type Props = { + hookId: string; +}; + +function TestWebhook({ hookId }: Props) { + const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); + const { + getValues, + formState: { isValid }, + } = useFormContext(); + + const [isSendingPayload, setIsSendingPayload] = useState(false); + const api = useApi(); + + const sendTestPayload = async () => { + if (isSendingPayload) { + return; + } + + setIsSendingPayload(true); + + try { + const formData = getValues(); + const { events, config } = webhookDetailsParser.toRemoteModel(formData); + await api.post(`api/hooks/${hookId}/test`, { json: { events, config } }); + toast.success(t('webhook_details.settings.test_payload_sent')); + } finally { + setIsSendingPayload(false); + } + }; + + return ( + +
+
+ +
+
+
+ ); +} + +export default TestWebhook; diff --git a/packages/console/src/pages/WebhookDetails/WebhookSettings/index.tsx b/packages/console/src/pages/WebhookDetails/WebhookSettings/index.tsx index 613a48e2a..31ff33207 100644 --- a/packages/console/src/pages/WebhookDetails/WebhookSettings/index.tsx +++ b/packages/console/src/pages/WebhookDetails/WebhookSettings/index.tsx @@ -16,6 +16,7 @@ import { webhookDetailsParser } from '../utils'; import CustomHeaderField from './components/CustomHeaderField'; import SigningKeyField from './components/SigningKeyField'; +import TestWebhook from './components/TestWebhook'; function WebhookSettings() { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); @@ -50,11 +51,11 @@ function WebhookSettings() { onSubmit={onSubmit} onDiscard={reset} > - - + + - - + + + + +