@@ -13,21 +13,22 @@ export const fieldNames = {
13
13
ORGANIZATION_LONG_DESCRIPTION : "organizationLongDescription" ,
14
14
DESIGNATION : "designation" ,
15
15
TWITTER : "twitter" ,
16
+ MESSAGE_DESCRIPTION : "messageDescription" ,
16
17
} ;
17
18
Object . freeze ( fieldNames ) ;
18
19
19
20
export const checkFieldValidation = ( fieldName , fieldValue , repeatFieldValue = null ) => {
20
21
switch ( fieldName ) {
21
22
case fieldNames . FIRSTNAME : {
22
- if ( fieldValue . trim ( ) . length == 0 ) {
23
+ if ( fieldValue . trim ( ) . length === 0 ) {
23
24
return {
24
25
firstNameError : "Enter first name" ,
25
26
} ;
26
27
}
27
28
return { firstNameError : null } ;
28
29
}
29
30
case fieldNames . LASTNAME : {
30
- if ( fieldValue . trim ( ) . length == 0 ) {
31
+ if ( fieldValue . trim ( ) . length === 0 ) {
31
32
return {
32
33
lastNameError : "Enter last name" ,
33
34
} ;
@@ -54,23 +55,23 @@ export const checkFieldValidation = (fieldName, fieldValue, repeatFieldValue=nul
54
55
return { passwordError : null } ;
55
56
}
56
57
case fieldNames . VERIFY_PASSWORD : {
57
- if ( fieldValue != repeatFieldValue ) {
58
+ if ( fieldValue !== repeatFieldValue ) {
58
59
return {
59
60
verifyPasswordError : "Passwords don't match" ,
60
61
} ;
61
62
}
62
63
return { verifyPasswordError : null } ;
63
64
}
64
65
case fieldNames . PHONE : {
65
- if ( fieldValue . trim ( ) . length != 10 ) {
66
+ if ( fieldValue . trim ( ) . length !== 10 ) {
66
67
return {
67
68
phoneError : "Enter a valid phone number" ,
68
69
} ;
69
70
}
70
71
return { phoneError : null } ;
71
72
}
72
73
case fieldNames . USER_SHORT_DESCRIPTION : {
73
- if ( fieldValue . trim ( ) . length == 0 ) {
74
+ if ( fieldValue . trim ( ) . length === 0 ) {
74
75
return {
75
76
userShortDescriptionError : "Enter short description" ,
76
77
} ;
@@ -95,7 +96,7 @@ export const checkFieldValidation = (fieldName, fieldValue, repeatFieldValue=nul
95
96
}
96
97
case fieldNames . WEBSITE : {
97
98
if (
98
- //regex to be added
99
+ //TBD: Regex
99
100
fieldValue . match ( )
100
101
) {
101
102
return {
@@ -126,7 +127,7 @@ export const checkFieldValidation = (fieldName, fieldValue, repeatFieldValue=nul
126
127
return { organizationLongDescriptionError : null } ;
127
128
}
128
129
case fieldNames . DESIGNATION : {
129
- if ( fieldValue . trim ( ) . length < 2 && fieldValue . trim ( ) . length != 0 ) {
130
+ if ( fieldValue . trim ( ) . length < 2 && fieldValue . trim ( ) . length !== 0 ) {
130
131
return {
131
132
designationError : "Use 2 characters or more for designation" ,
132
133
} ;
@@ -136,8 +137,9 @@ export const checkFieldValidation = (fieldName, fieldValue, repeatFieldValue=nul
136
137
case fieldNames . TWITTER : {
137
138
if (
138
139
fieldValue . match (
139
- `http(?:s)?:\/\/(?:www\.)?twitter\.com\/([a-zA-Z0-9_]{1,15}$)`
140
- ) || fieldValue . length == 0
140
+ `http(?:s)?://(?:www.)?twitter.com/([a-zA-Z0-9_]{1,15}$)`
141
+ ) ||
142
+ fieldValue . length === 0
141
143
) {
142
144
return {
143
145
twitterError : null ,
@@ -148,5 +150,17 @@ export const checkFieldValidation = (fieldName, fieldValue, repeatFieldValue=nul
148
150
} ;
149
151
}
150
152
}
153
+ case fieldNames . MESSAGE_DESCRIPTION : {
154
+ if ( fieldValue . trim ( ) . length === 0 ) {
155
+ return {
156
+ messageDescriptionError : "Enter message" ,
157
+ } ;
158
+ }
159
+ return { messageDescriptionError : null } ;
160
+ }
161
+ default : {
162
+ console . log ( `Validation not defined for: ${ fieldName } ` ) ;
163
+ return ;
164
+ }
151
165
}
152
166
} ;
0 commit comments