mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 12:55:06 +03:00
## Summary This PR fixes an issue when updating an existing webhook. I've also migrated the Webhooks form from Formik to React Hook Form, following the patterns established in `CreateCronJobSheet`. ## Test Plan - [x] Type check passes - [x] Create webhook with all fields - [x] Edit existing webhook - [x] Validate form errors (missing fields, invalid URL, etc.) - [x] Dirty state shows confirmation on close - [x] Edge function mode switches correctly - [x] Auth header auto-adds for JWT-enabled functions --- See CONTRIBUTING.md for more information. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Refactor** * Improved webhook editing form interface with enhanced validation and cleaner layout * Reorganized HTTP request configuration, parameter management, and header fields for better usability * Streamlined form structure for configuring webhook details, including method, timeout, and event selection <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
39 lines
1.4 KiB
TypeScript
39 lines
1.4 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
import { isValidHttpUrl } from '@/lib/helpers'
|
|
|
|
const httpRequestSchema = z.object({
|
|
function_type: z.literal('http_request'),
|
|
http_url: z
|
|
.string()
|
|
.min(1, 'Please provide a URL')
|
|
.refine((val) => val.startsWith('http'), 'Please prefix your URL with http or https')
|
|
.refine((val) => isValidHttpUrl(val), 'Please provide a valid URL'),
|
|
})
|
|
|
|
const supabaseFunctionSchema = z.object({
|
|
function_type: z.literal('supabase_function'),
|
|
http_url: z
|
|
.string()
|
|
.min(1, 'Please select an edge function')
|
|
.refine((val) => !val.includes('undefined'), 'No edge functions available for selection'),
|
|
})
|
|
|
|
export const FormSchema = z
|
|
.object({
|
|
name: z.string().min(1, 'Please provide a name for your webhook'),
|
|
table_id: z.string().min(1, 'Please select a table'),
|
|
http_method: z.enum(['GET', 'POST']),
|
|
timeout_ms: z.coerce
|
|
.number()
|
|
.int()
|
|
.gte(1000, 'Timeout should be at least 1000ms')
|
|
.lte(10000, 'Timeout should not exceed 10,000ms'),
|
|
events: z.array(z.string()).min(1, 'Please select at least one event'),
|
|
httpHeaders: z.array(z.object({ id: z.string(), name: z.string(), value: z.string() })),
|
|
httpParameters: z.array(z.object({ id: z.string(), name: z.string(), value: z.string() })),
|
|
})
|
|
.and(z.discriminatedUnion('function_type', [httpRequestSchema, supabaseFunctionSchema]))
|
|
|
|
export type WebhookFormValues = z.infer<typeof FormSchema>
|