Skip to content

Commit 7cc4045

Browse files
committed
refactor: update event handling and validation in UpsertWebhookDialog
- Changed the type of the event parameter in handleEventToggle to SandboxLifecycleEventType for improved type safety. - Updated the events prop in UpsertWebhookDialog to use safe parsing, ensuring better handling of webhook events. - Adjusted the Input component to require a minimum length of 32 characters for custom secrets, enhancing validation. These changes aim to strengthen the event handling logic and improve user feedback in the webhook management process.
1 parent 78094c5 commit 7cc4045

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/features/dashboard/settings/webhooks/upsert-webhook-dialog-steps.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type UpsertWebhookDialogStepsProps = {
3838
exampleEventType: SandboxLifecycleEventType
3939
allEventsSelected: boolean
4040
handleAllToggle: () => void
41-
handleEventToggle: (event: string) => void
41+
handleEventToggle: (event: SandboxLifecycleEventType) => void
4242
mode: 'create' | 'update'
4343
secretType: SecretType
4444
onSecretTypeChange: (value: SecretType) => void
@@ -365,7 +365,7 @@ export function UpsertWebhookDialogSteps({
365365
<Input
366366
placeholder="Enter your custom secret"
367367
disabled={isLoading}
368-
maxLength={32}
368+
minLength={32}
369369
className="min-w-0"
370370
{...field}
371371
ref={(el) => {

src/features/dashboard/settings/webhooks/upsert-webhook-dialog.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export function UpsertWebhookDialog({
8282
mode,
8383
name: webhook?.name || '',
8484
url: webhook?.url || '',
85-
events: webhook?.events || [],
85+
events:
86+
SandboxLifecycleEventTypeSchema.array().safeParse(webhook?.events).data ??
87+
[],
8688
...(isUpdateMode ? {} : { signatureSecret: '' }),
8789
}
8890

@@ -199,19 +201,16 @@ export function UpsertWebhookDialog({
199201
}
200202
}
201203

202-
const handleEventToggle = (event: string) => {
204+
const handleEventToggle = (event: SandboxLifecycleEventType) => {
203205
const currentEvents = form.getValues('events') || []
204206
if (currentEvents.includes(event)) {
205207
form.setValue(
206208
'events',
207-
currentEvents.filter((eventName: string) => eventName !== event)
209+
currentEvents.filter((eventName) => eventName !== event)
208210
)
209211
} else {
210212
form.setValue('events', [...currentEvents, event])
211-
const matched = SandboxLifecycleEventTypeSchema.options.find(
212-
(e) => e === event
213-
)
214-
if (matched) setLastSelectedEvent(matched)
213+
setLastSelectedEvent(event)
215214
}
216215
}
217216

0 commit comments

Comments
 (0)