@@ -28,6 +28,38 @@ export const signUpSchema = z
28
28
message : 'Confirm Password do not match' ,
29
29
path : [ 'confirmPassword' ] ,
30
30
} ) ;
31
+ const isValidImageLink = ( value : string ) => {
32
+ const imageLinkRegex = / \. ( j p g | j p e g | p n g | w e b p ) $ / 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
+ } ) ;
31
63
32
64
export interface AuthData {
33
65
_id : string ;
@@ -38,3 +70,4 @@ export interface AuthData {
38
70
39
71
export type TSignInSchema = z . infer < typeof signInSchema > ;
40
72
export type TSignUpSchema = z . infer < typeof signUpSchema > ;
73
+ export type TAddBlogScheme = z . infer < typeof addBlogSchema > ;
0 commit comments