Skip to content

Commit

Permalink
chore: split superrefine itno diff schema
Browse files Browse the repository at this point in the history
  • Loading branch information
seaerchin committed Aug 12, 2024
1 parent 18d0b58 commit 37f80d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { BiLink } from "react-icons/bi"
import { generateResourceUrl } from "~/features/editing-experience/components/utils"
import { useZodForm } from "~/lib/form"
import {
editFolderSchema,
baseEditFolderSchema,
MAX_FOLDER_PERMALINK_LENGTH,
MAX_FOLDER_TITLE_LENGTH,
} from "~/schemas/folder"
Expand Down Expand Up @@ -71,7 +71,7 @@ const SuspendableModalContent = ({
title: originalTitle,
permalink: originalPermalink,
},
schema: editFolderSchema.omit({ siteId: true, resourceId: true }),
schema: baseEditFolderSchema.omit({ siteId: true, resourceId: true }),
})
const { errors, isValid } = formState
const utils = trpc.useUtils()
Expand Down
20 changes: 11 additions & 9 deletions apps/studio/src/schemas/folder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ export const readFolderSchema = z.object({
resourceId: z.number().min(1),
})

export const editFolderSchema = z
.object({
resourceId: z.string(),
permalink: z.optional(z.string()),
title: z.optional(z.string()),
siteId: z.string(),
})
.superRefine(({ permalink, title }, ctx) => {
export const baseEditFolderSchema = z.object({
resourceId: z.string(),
permalink: z.optional(z.string()),
title: z.optional(z.string()),
siteId: z.string(),
})

export const editFolderSchema = baseEditFolderSchema.superRefine(
({ permalink, title }, ctx) => {
if (!permalink && !title) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
Expand All @@ -47,4 +48,5 @@ export const editFolderSchema = z
message: "Either permalink or title must be provided.",
})
}
})
},
)

0 comments on commit 37f80d5

Please sign in to comment.