优化
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const accountValidator = z.object({
|
||||
name: z
|
||||
.string({
|
||||
error: 'Required.',
|
||||
})
|
||||
.min(2, {
|
||||
error: 'Name must be at least 2 characters.',
|
||||
})
|
||||
.max(30, {
|
||||
error: 'Name must not be longer than 30 characters.',
|
||||
}),
|
||||
dob: z
|
||||
.iso
|
||||
.datetime()
|
||||
.optional()
|
||||
.refine(date => date !== undefined, 'Please select a valid date.'),
|
||||
language: z
|
||||
.string()
|
||||
.min(1, 'Please select a language.'),
|
||||
})
|
||||
|
||||
export type AccountValidator = z.infer<typeof accountValidator>
|
||||
@@ -0,0 +1,14 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const appearanceValidator = z.object({
|
||||
theme: z
|
||||
.enum(['light', 'dark'], {
|
||||
error: 'Please select a theme.',
|
||||
}),
|
||||
font: z
|
||||
.enum(['inter', 'manrope', 'system'], {
|
||||
error: 'Please select a font.',
|
||||
}),
|
||||
})
|
||||
|
||||
export type AppearanceValidator = z.infer<typeof appearanceValidator>
|
||||
@@ -0,0 +1,11 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const displayValidator = z.object({
|
||||
items: z
|
||||
.array(z.string())
|
||||
.refine(value => value.some(item => item), {
|
||||
error: 'You have to select at least one item.',
|
||||
}),
|
||||
})
|
||||
|
||||
export type DisplayValidator = z.infer<typeof displayValidator>
|
||||
@@ -0,0 +1,28 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const notificationsValidator = z.object({
|
||||
type: z
|
||||
.enum(['all', 'mentions', 'none'], {
|
||||
error: 'You need to select a notification type.',
|
||||
}),
|
||||
mobile: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.optional(),
|
||||
communication_emails: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.optional(),
|
||||
social_emails: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.optional(),
|
||||
marketing_emails: z
|
||||
.boolean()
|
||||
.default(false)
|
||||
.optional(),
|
||||
security_emails: z
|
||||
.boolean(),
|
||||
})
|
||||
|
||||
export type NotificationsValidator = z.infer<typeof notificationsValidator>
|
||||
@@ -0,0 +1,29 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const profileValidator = z.object({
|
||||
username: z
|
||||
.string()
|
||||
.min(2, {
|
||||
error: 'Username must be at least 2 characters.',
|
||||
})
|
||||
.max(30, {
|
||||
error: 'Username must not be longer than 30 characters.',
|
||||
}),
|
||||
email: z
|
||||
.email({
|
||||
error: 'Please select an email to display.',
|
||||
}),
|
||||
bio: z
|
||||
.string()
|
||||
.max(160, { error: 'Bio must not be longer than 160 characters.' })
|
||||
.min(4, { error: 'Bio must be at least 2 characters.' }),
|
||||
urls: z
|
||||
.array(
|
||||
z.object({
|
||||
value: z.url({ error: 'Please enter a valid URL.' }),
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
})
|
||||
|
||||
export type ProfileValidator = z.infer<typeof profileValidator>
|
||||
Reference in New Issue
Block a user