Skip to content

Commit 27b1d25

Browse files
committed
🐛 Allow null in workbook schema (#2020)
1 parent 5f80796 commit 27b1d25

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/lib/zod/schema.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,24 @@ export const workBookSchema = z.object({
7272
workBookType: z.nativeEnum(WorkBookType),
7373
urlSlug: z
7474
.string()
75-
.min(0, { message: '' })
76-
.max(30, { message: '30文字になるまで削除してください' }) // 問題集(カリキュラムと解法別)をURLで識別するためのオプション。a-z、0-9、(-)ハイフンのみ使用可能。例: bfs、dfs、dp、union-find、2-sat。
77-
.transform((value) => (value === '' ? undefined : value.toLowerCase()))
75+
.nullable()
76+
.optional()
77+
.refine(
78+
(value) => {
79+
// Allow empty string, null, or undefined
80+
if (value === '' || value === null || value === undefined) {
81+
return true;
82+
}
83+
return value.length <= 30;
84+
},
85+
{ message: '30文字以下になるまで削除してください' },
86+
)
87+
.transform((value) =>
88+
value === '' || value === null || value === undefined ? undefined : value.toLowerCase(),
89+
)
7890
.refine((value) => value === undefined || isValidUrlSlug(value), {
7991
message: '半角英小文字、数字、ハイフンのみ使用可能です',
80-
})
81-
.optional(),
92+
}),
8293
workBookTasks: z
8394
.array(workBookTaskSchema)
8495
.min(1, { message: '1問以上登録してください' })

0 commit comments

Comments
 (0)