Skip to content

Commit af322ce

Browse files
fix-krishnaacharyaa#77: changed the traditional form to react hook form (krishnaacharyaa#407)
2 parents df4f098 + e3f4147 commit af322ce

File tree

4 files changed

+157
-146
lines changed

4 files changed

+157
-146
lines changed

Diff for: frontend/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@
2020
]
2121
},
2222
"dependencies": {
23-
"@hookform/resolvers": "^3.3.4",
23+
"@hookform/resolvers": "^3.5.0",
2424
"@tsparticles/react": "^3.0.0",
2525
"axios": "^1.6.1",
2626
"class-variance-authority": "^0.7.0",
2727
"clsx": "^2.0.0",
2828
"lucide-react": "^0.292.0",
2929
"react": "^18.2.0",
3030
"react-dom": "^18.2.0",
31-
"react-hook-form": "^7.51.2",
31+
"react-hook-form": "^7.51.5",
3232
"react-router-dom": "^6.18.0",
3333
"react-tag-input": "^6.8.1",
3434
"react-toastify": "^9.1.3",
3535
"tailwind-merge": "^2.0.0",
3636
"tailwindcss-animate": "^1.0.7",
3737
"tsparticles": "^3.4.0",
38-
"zod": "^3.22.4"
38+
"zod": "^3.23.8"
3939
},
4040
"devDependencies": {
4141
"@babel/preset-env": "^7.23.6",

Diff for: frontend/src/lib/types.ts

+33
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,38 @@ export const signUpSchema = z
2828
message: 'Confirm Password do not match',
2929
path: ['confirmPassword'],
3030
});
31+
const isValidImageLink = (value: string) => {
32+
const imageLinkRegex = /\.(jpg|jpeg|png|webp)$/i;
33+
return imageLinkRegex.test(value);
34+
};
35+
export const addBlogSchema = z.object({
36+
title: z.string().refine((value) => value.trim().split(/\s+/).length >= 3, {
37+
message: 'Oops! Title needs more spice. Give it at least 3 words.',
38+
}),
39+
isFeaturedPost: z.boolean(),
40+
description: z.string().refine((value) => value.trim().split(/\s+/).length >= 10, {
41+
message: 'Oops! Description needs more detail. Give it at least 10 words',
42+
}),
43+
authorName: z
44+
.string()
45+
.min(3, {
46+
message: "C'ome on! Your name cannot be less than 3 characters.",
47+
})
48+
.max(15, {
49+
message: "Hey isn't it too big of a name, can you limit it to 15 characters",
50+
}),
51+
imageLink: z.string().refine((value) => isValidImageLink(value), {
52+
message: 'Hmm... Image link should end with .jpg, .jpeg, .webp, or .png.',
53+
}),
54+
categories: z
55+
.array(z.string())
56+
.min(1, {
57+
message: 'Easy there! Select at least one category.',
58+
})
59+
.max(3, {
60+
message: 'Easy there! Not more than 3 categories.',
61+
}),
62+
});
3163

3264
export interface AuthData {
3365
_id: string;
@@ -38,3 +70,4 @@ export interface AuthData {
3870

3971
export type TSignInSchema = z.infer<typeof signInSchema>;
4072
export type TSignUpSchema = z.infer<typeof signUpSchema>;
73+
export type TAddBlogScheme = z.infer<typeof addBlogSchema>;

0 commit comments

Comments
 (0)