refactor: Webhooks (#12487)
Closes #12303 ### What’s Changed - Replace auto‐save with explicit Save / Cancel Webhook forms now use manual “Save” and “Cancel” buttons instead of the old debounced auto‐save/update. - Separate “New” and “Detail” routes Two dedicated paths `/settings/webhooks/new` for creation and /`settings/webhooks/:webhookId` for editing, making the UX clearer. - URL hint & normalization If a user omits the http(s):// scheme, we display a “Will be saved as https://…” hint and automatically default to HTTPS. - Centralized validation with Zod Introduced a `webhookFormSchema` for client‐side URL, operations, and secret validation. - Storybook coverage Added stories for both “New Webhook” and “Webhook Detail” - Unit tests Added tests for the new `useWebhookForm` hook
This commit is contained in:
+31
@@ -0,0 +1,31 @@
|
||||
import { isValidUrl } from 'twenty-shared/utils';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const webhookFormSchema = z.object({
|
||||
targetUrl: z
|
||||
.string()
|
||||
.trim()
|
||||
.min(1, 'URL is required')
|
||||
.refine((url) => isValidUrl(url), {
|
||||
message: 'Please enter a valid URL',
|
||||
}),
|
||||
description: z.string().optional(),
|
||||
operations: z
|
||||
.array(
|
||||
z.object({
|
||||
object: z.string().nullable(),
|
||||
action: z.string(),
|
||||
}),
|
||||
)
|
||||
.min(1, 'At least one operation is required')
|
||||
.refine(
|
||||
(operations) =>
|
||||
operations.some((op) => op.object !== null && op.action !== null),
|
||||
{
|
||||
message: 'At least one complete operation is required',
|
||||
},
|
||||
),
|
||||
secret: z.string().optional(),
|
||||
});
|
||||
|
||||
export type WebhookFormValues = z.infer<typeof webhookFormSchema>;
|
||||
Reference in New Issue
Block a user