Skip to content
This repository was archived by the owner on Mar 7, 2024. It is now read-only.

Commit 8bb179a

Browse files
authored
Rebased with development branch and added validation to form (#86)
* Rebased with development branch and added validation to form * Added country code dropdown for contact number
1 parent ee4f9a3 commit 8bb179a

File tree

1 file changed

+64
-25
lines changed

1 file changed

+64
-25
lines changed

src/views/pages/CLView/ApplyNowModal.js

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import {
66
DialogContentText,
77
DialogTitle,
88
Button,
9-
Typography
9+
Typography,
10+
MenuItem,
11+
Grid
1012
} from '@material-ui/core';
1113
import { makeStyles } from '@material-ui/core/styles';
1214
import CircularProgress from '@material-ui/core/CircularProgress';
13-
import { ValidatorForm, TextValidator } from 'react-material-ui-form-validator';
15+
import { ValidatorForm, TextValidator, SelectValidator } from 'react-material-ui-form-validator';
1416
import { useSnackbar } from 'notistack';
1517
import axios from 'axios';
1618

@@ -45,6 +47,8 @@ export default function ApplyNowModal() {
4547

4648
const handleClickOpen = () => {
4749
setOpen(true);
50+
formData.countryCode = '+91';
51+
formData.phone = '';
4852
};
4953

5054
const handleClose = () => {
@@ -59,6 +63,7 @@ export default function ApplyNowModal() {
5963
};
6064

6165
const handleSubmit = e => {
66+
formData.phone = `${formData.countryCode}-${formData.phone}`;
6267
setSubmitting(1);
6368
e.preventDefault();
6469
axios({
@@ -77,6 +82,11 @@ export default function ApplyNowModal() {
7782
});
7883
};
7984

85+
const countryCodes = Array(100)
86+
.fill(1)
87+
.map((x, y) => x + y)
88+
.reverse();
89+
8090
return (
8191
<div>
8292
<Button
@@ -123,22 +133,44 @@ export default function ApplyNowModal() {
123133
fullWidth
124134
name="email"
125135
onChange={handleChange}
126-
validators={['required']}
127-
errorMessages={['This is a required field']}
136+
validators={['required', 'isEmail']}
137+
errorMessages={['This is a required field', 'Please enter a valid email']}
128138
/>
129139

130-
<TextValidator
131-
key="contact"
132-
className={classes.textField}
133-
label="WhatsApp / Contact Number "
134-
variant="outlined"
135-
value={formData.phone}
136-
fullWidth
137-
name="phone"
138-
onChange={handleChange}
139-
validators={['required']}
140-
errorMessages={['This is a required field']}
141-
/>
140+
<Grid container spacing={2} justify="space-evenly">
141+
<Grid item xs={2}>
142+
<SelectValidator
143+
key="countryCode"
144+
className={classes.textField}
145+
value={formData.countryCode}
146+
onChange={handleChange}
147+
name="countryCode"
148+
variant="outlined"
149+
validators={['required']}
150+
errorMessages={['Please select a country code']}
151+
fullWidth
152+
>
153+
{countryCodes.map((code) => {
154+
return <MenuItem value={`+${code}`}>+{code}</MenuItem>;
155+
})}
156+
</SelectValidator>
157+
</Grid>
158+
159+
<Grid item xs={10}>
160+
<TextValidator
161+
key="contact"
162+
className={classes.textField}
163+
label="WhatsApp / Contact Number "
164+
variant="outlined"
165+
value={formData.phone}
166+
fullWidth
167+
name="phone"
168+
onChange={handleChange}
169+
validators={['required', 'matchRegexp:^[+]*[(]*[+]{0,1}[0-9]{1,3}[)]{0,1}[-s./0-9]*$']}
170+
errorMessages={['This is a required field', 'Please enter a valid contact number']}
171+
/>
172+
</Grid>
173+
</Grid>
142174

143175
<TextValidator
144176
key="linkedIn"
@@ -149,8 +181,8 @@ export default function ApplyNowModal() {
149181
fullWidth
150182
name="linkedIn"
151183
onChange={handleChange}
152-
validators={['required']}
153-
errorMessages={['This is a required field']}
184+
validators={['required', 'matchRegexp:^(http(s)?://)?([w]+.)?linkedin.com/(pub|in|profile)']}
185+
errorMessages={['This is a required field', 'Please enter a valid URL']}
154186
/>
155187

156188
<TextValidator
@@ -166,18 +198,25 @@ export default function ApplyNowModal() {
166198
errorMessages={['This is a required field']}
167199
/>
168200

169-
<TextValidator
201+
<SelectValidator
170202
key="year"
171203
className={classes.textField}
172-
label="Year"
173-
variant="outlined"
174204
value={formData.year}
175-
fullWidth
176-
name="year"
177205
onChange={handleChange}
206+
name="year"
207+
variant="outlined"
178208
validators={['required']}
179-
errorMessages={['This is a required field']}
180-
/>
209+
errorMessages={['Please select a year']}
210+
label="Year"
211+
fullWidth
212+
>
213+
<MenuItem value={1}>1st</MenuItem>
214+
<MenuItem value={2}>2nd</MenuItem>
215+
<MenuItem value={3}>3rd</MenuItem>
216+
<MenuItem value={4}>4th</MenuItem>
217+
<MenuItem value={5}>5th</MenuItem>
218+
<MenuItem value={6}>6th</MenuItem>
219+
</SelectValidator>
181220

182221
<TextValidator
183222
key="college"

0 commit comments

Comments
 (0)