From b1bb345929340105b5bc9f0b56ba312a620613df Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Mon, 12 Feb 2024 15:23:15 +1100 Subject: [PATCH] fix: redirect URL preventing document flow (#925) ## Description Currently the document redirect URL feature is preventing documents from being created unless a redirect URL is provided. During the document edit flow, the redirect URL is hidden in an advanced tab with the value of an empty string, which will always fail the current Zod validation since `optional` requires undefined to pass. There are multiple ways to fix this, but I think this is the easiest method where we can assume an empty string is valid. --- packages/trpc/server/document-router/schema.ts | 2 +- packages/ui/primitives/document-flow/add-subject.types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/trpc/server/document-router/schema.ts b/packages/trpc/server/document-router/schema.ts index fceb6413f..899baa41f 100644 --- a/packages/trpc/server/document-router/schema.ts +++ b/packages/trpc/server/document-router/schema.ts @@ -77,7 +77,7 @@ export const ZSendDocumentMutationSchema = z.object({ redirectUrl: z .string() .optional() - .refine((value) => value === undefined || URL_REGEX.test(value), { + .refine((value) => value === undefined || value === '' || URL_REGEX.test(value), { message: 'Please enter a valid URL', }), }), diff --git a/packages/ui/primitives/document-flow/add-subject.types.ts b/packages/ui/primitives/document-flow/add-subject.types.ts index fd4175368..c9027c2a3 100644 --- a/packages/ui/primitives/document-flow/add-subject.types.ts +++ b/packages/ui/primitives/document-flow/add-subject.types.ts @@ -13,7 +13,7 @@ export const ZAddSubjectFormSchema = z.object({ redirectUrl: z .string() .optional() - .refine((value) => value === undefined || URL_REGEX.test(value), { + .refine((value) => value === undefined || value === '' || URL_REGEX.test(value), { message: 'Please enter a valid URL', }), }),