Add checking for the emptiness of event types

This commit is contained in:
Hongbo Wu
2023-03-09 15:06:28 +08:00
parent 104da191d2
commit 2c10068c2a

View File

@ -62,6 +62,14 @@ export default function Webhooks(): JSX.Element {
applyStoredTheme(false)
function validateEventTypes(eventTypes: WebhookEvent[]): boolean {
if (eventTypes.length > 0) return true
showErrorToast('Please select at least one event type', {
position: 'bottom-right',
})
return false
}
async function onDelete(id: string): Promise<void> {
const result = await deleteWebhookMutation(id)
if (result) {
@ -73,6 +81,7 @@ export default function Webhooks(): JSX.Element {
}
async function onCreate(): Promise<void> {
if (!validateEventTypes(eventTypes)) return
const result = await setWebhookMutation({ url, eventTypes })
if (result) {
showSuccessToast('Webhook created', { position: 'bottom-right' })
@ -83,6 +92,7 @@ export default function Webhooks(): JSX.Element {
}
async function onUpdate(): Promise<void> {
if (!validateEventTypes(eventTypes)) return
const result = await setWebhookMutation({
id: onEditWebhook?.id,
url,