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.
This commit is contained in:
David Nguyen
2024-02-12 15:23:15 +11:00
committed by GitHub
parent 3a32bc62c5
commit b1bb345929
2 changed files with 2 additions and 2 deletions

View File

@ -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',
}),
}),

View File

@ -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',
}),
}),