Skip to content

Commit b463e96

Browse files
authored
build: zod v4 migration (#178)
* build: bump zod to v4 * refactor: migrate zod schemas to v4 syntax
1 parent d40cc1c commit b463e96

File tree

13 files changed

+108
-119
lines changed

13 files changed

+108
-119
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"tailwind-merge": "^3.3.1",
5757
"tailwindcss": "^4.1.11",
5858
"tw-animate-css": "^1.3.5",
59-
"zod": "^3.25.67",
59+
"zod": "^4.0.5",
6060
"zustand": "^5.0.6"
6161
},
6262
"devDependencies": {

pnpm-lock.yaml

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/features/auth/forgot-password/components/forgot-password-form.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ import { Input } from '@/components/ui/input'
1717
type ForgotFormProps = HTMLAttributes<HTMLFormElement>
1818

1919
const formSchema = z.object({
20-
email: z
21-
.string()
22-
.min(1, { message: 'Please enter your email' })
23-
.email({ message: 'Invalid email address' }),
20+
email: z.email({
21+
error: (iss) => (iss.input === '' ? 'Please enter your email' : undefined),
22+
}),
2423
})
2524

2625
export function ForgotPasswordForm({ className, ...props }: ForgotFormProps) {

src/features/auth/forgot-password/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function ForgotPassword() {
2727
<ForgotPasswordForm />
2828
</CardContent>
2929
<CardFooter>
30-
<p className='text-muted-foreground px-8 text-center text-sm'>
30+
<p className='text-muted-foreground mx-auto px-8 text-center text-sm text-balance'>
3131
Don't have an account?{' '}
3232
<Link
3333
to='/sign-up'

src/features/auth/otp/components/otp-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
type OtpFormProps = HTMLAttributes<HTMLFormElement>
2525

2626
const formSchema = z.object({
27-
otp: z.string().min(1, { message: 'Please enter your otp code.' }),
27+
otp: z.string().min(6, 'Please enter your otp code.'),
2828
})
2929

3030
export function OtpForm({ className, ...props }: OtpFormProps) {

src/features/auth/sign-in/components/user-auth-form.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,13 @@ import { PasswordInput } from '@/components/password-input'
2020
type UserAuthFormProps = HTMLAttributes<HTMLFormElement>
2121

2222
const formSchema = z.object({
23-
email: z
24-
.string()
25-
.min(1, { message: 'Please enter your email' })
26-
.email({ message: 'Invalid email address' }),
23+
email: z.email({
24+
error: (iss) => (iss.input === '' ? 'Please enter your email' : undefined),
25+
}),
2726
password: z
2827
.string()
29-
.min(1, {
30-
message: 'Please enter your password',
31-
})
32-
.min(7, {
33-
message: 'Password must be at least 7 characters long',
34-
}),
28+
.min(1, 'Please enter your password')
29+
.min(7, 'Password must be at least 7 characters long'),
3530
})
3631

3732
export function UserAuthForm({ className, ...props }: UserAuthFormProps) {

src/features/auth/sign-up/components/sign-up-form.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,15 @@ type SignUpFormProps = HTMLAttributes<HTMLFormElement>
2020

2121
const formSchema = z
2222
.object({
23-
email: z
24-
.string()
25-
.min(1, { message: 'Please enter your email' })
26-
.email({ message: 'Invalid email address' }),
23+
email: z.email({
24+
error: (iss) =>
25+
iss.input === '' ? 'Please enter your email' : undefined,
26+
}),
2727
password: z
2828
.string()
29-
.min(1, {
30-
message: 'Please enter your password',
31-
})
32-
.min(7, {
33-
message: 'Password must be at least 7 characters long',
34-
}),
35-
confirmPassword: z.string(),
29+
.min(1, 'Please enter your password')
30+
.min(7, 'Password must be at least 7 characters long'),
31+
confirmPassword: z.string().min(1, 'Please confirm your password'),
3632
})
3733
.refine((data) => data.password === data.confirmPassword, {
3834
message: "Passwords don't match.",

src/features/settings/account/account-form.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,11 @@ const languages = [
4545
const accountFormSchema = z.object({
4646
name: z
4747
.string()
48-
.min(2, {
49-
message: 'Name must be at least 2 characters.',
50-
})
51-
.max(30, {
52-
message: 'Name must not be longer than 30 characters.',
53-
}),
54-
dob: z.date({
55-
required_error: 'A date of birth is required.',
56-
}),
57-
language: z.string({
58-
required_error: 'Please select a language.',
59-
}),
48+
.min(1, 'Please enter your name.')
49+
.min(2, 'Name must be at least 2 characters.')
50+
.max(30, 'Name must not be longer than 30 characters.'),
51+
dob: z.date('Please select your date of birth.'),
52+
language: z.string('Please select a language.'),
6053
})
6154

6255
type AccountFormValues = z.infer<typeof accountFormSchema>

src/features/settings/appearance/appearance-form.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ import {
2020
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
2121

2222
const appearanceFormSchema = z.object({
23-
theme: z.enum(['light', 'dark'], {
24-
required_error: 'Please select a theme.',
25-
}),
26-
font: z.enum(fonts, {
27-
invalid_type_error: 'Select a font',
28-
required_error: 'Please select a font.',
29-
}),
23+
theme: z.enum(['light', 'dark']),
24+
font: z.enum(fonts),
3025
})
3126

3227
type AppearanceFormValues = z.infer<typeof appearanceFormSchema>

src/features/settings/notifications/notifications-form.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import { Switch } from '@/components/ui/switch'
1919

2020
const notificationsFormSchema = z.object({
2121
type: z.enum(['all', 'mentions', 'none'], {
22-
required_error: 'You need to select a notification type.',
22+
error: (iss) =>
23+
iss.input === undefined
24+
? 'Please select a notification type.'
25+
: undefined,
2326
}),
2427
mobile: z.boolean().default(false).optional(),
2528
communication_emails: z.boolean().default(false).optional(),

0 commit comments

Comments
 (0)