1
- import React , { useState } from 'react' ;
1
+ import React , { useState , useEffect } from 'react' ;
2
2
import { makeStyles } from '@material-ui/core/styles' ;
3
3
import Stepper from '@material-ui/core/Stepper' ;
4
4
import Step from '@material-ui/core/Step' ;
@@ -13,6 +13,8 @@ import {
13
13
SelectValidator
14
14
} from 'react-material-ui-form-validator' ;
15
15
16
+ import { getStates , getDistrict , getColleges } from './helper' ;
17
+
16
18
// import axios from 'axios';
17
19
18
20
const useStyles = makeStyles ( theme => ( {
@@ -75,7 +77,7 @@ function getStepContent(step, setActiveStep, formData, setFormData) {
75
77
76
78
export function ApplicationSteps ( ) {
77
79
const classes = useStyles ( ) ;
78
- const [ activeStep , setActiveStep ] = React . useState ( 2 ) ;
80
+ const [ activeStep , setActiveStep ] = React . useState ( 1 ) ;
79
81
const [ formData , setFormData ] = React . useState ( {
80
82
personal : { } ,
81
83
education : { } ,
@@ -213,6 +215,9 @@ function FormPersonalInfo({ setActiveStep, data, setData }) {
213
215
function FormEducationInfo ( { setActiveStep, data, setData } ) {
214
216
const classes = useStyles ( ) ;
215
217
const [ formData , updateFormData ] = useState ( data . education ) ;
218
+ const [ districtToCollegePair , updateDistrictToCollegePair ] = useState ( { } ) ;
219
+ const [ districts , updateDistricts ] = useState ( [ ] ) ;
220
+ const [ collegeList , updateCollege ] = useState ( [ ] ) ;
216
221
217
222
const handleChange = event => {
218
223
updateFormData ( {
@@ -234,9 +239,40 @@ function FormEducationInfo({ setActiveStep, data, setData }) {
234
239
setActiveStep ( 2 ) ;
235
240
} ;
236
241
242
+ const handleStateFieldChange = event => {
243
+ updateFormData ( {
244
+ ...formData ,
245
+ [ event . target . name ] : event . target . value
246
+ } ) ;
247
+ updateDistrictToCollegePair ( getDistrict ( event . target . value ) ) ;
248
+ } ;
249
+
250
+ const handleDistrictFieldChange = event => {
251
+ updateFormData ( {
252
+ ...formData ,
253
+ [ event . target . name ] : event . target . value
254
+ } ) ;
255
+ updateCollege ( getColleges ( districtToCollegePair , event . target . value ) ) ;
256
+ } ;
257
+
258
+ const handleDistrictFocus = ( ) => {
259
+ if ( formData . state != undefined ) {
260
+ updateDistricts ( Object . keys ( districtToCollegePair ) ) ;
261
+ }
262
+ } ;
263
+
264
+ function notIndia ( ) {
265
+ return (
266
+ formData . country === undefined ||
267
+ formData . country . trim ( ) . toLowerCase ( ) !== 'india'
268
+ ) ;
269
+ }
270
+
237
271
const years = Array ( 25 )
238
- . fill ( 2000 )
239
- . map ( ( x , y ) => x + y ) ;
272
+ . fill ( 2024 )
273
+ . map ( ( x , y ) => x - y ) ;
274
+
275
+ const states = getStates ( ) ;
240
276
241
277
return (
242
278
< ValidatorForm onSubmit = { handleSubmit } >
@@ -256,7 +292,6 @@ function FormEducationInfo({ setActiveStep, data, setData }) {
256
292
return < MenuItem value = { year } > { year } </ MenuItem > ;
257
293
} ) }
258
294
</ SelectValidator >
259
-
260
295
< TextValidator
261
296
key = "college"
262
297
className = { classes . textField }
@@ -269,32 +304,114 @@ function FormEducationInfo({ setActiveStep, data, setData }) {
269
304
validators = { [ 'required' ] }
270
305
errorMessages = { [ 'College is a required field' ] }
271
306
/>
307
+ { notIndia ( ) ? (
308
+ < TextValidator
309
+ key = "state"
310
+ className = { classes . textField }
311
+ autoComplete = "true"
312
+ label = "State"
313
+ variant = "outlined"
314
+ value = { formData . state }
315
+ fullWidth
316
+ name = "state"
317
+ onChange = { handleChange }
318
+ validators = { [ 'required' ] }
319
+ errorMessages = { [ 'State is a required field' ] }
320
+ />
321
+ ) : (
322
+ < SelectValidator
323
+ key = "state"
324
+ className = { classes . textField }
325
+ autoComplete = "true"
326
+ label = "State"
327
+ variant = "outlined"
328
+ value = { formData . state }
329
+ fullWidth
330
+ name = "state"
331
+ onChange = { handleStateFieldChange }
332
+ validators = { [ 'required' ] }
333
+ errorMessages = { [ 'State is a required field' ] }
334
+ >
335
+ { states . sort ( ) . map ( state => {
336
+ return < MenuItem value = { state } > { state } </ MenuItem > ;
337
+ } ) }
338
+ </ SelectValidator >
339
+ ) }
272
340
273
- < TextValidator
274
- key = "state"
275
- className = { classes . textField }
276
- label = "State"
277
- variant = "outlined"
278
- value = { formData . state }
279
- fullWidth
280
- name = "state"
281
- onChange = { handleChange }
282
- validators = { [ 'required' ] }
283
- errorMessages = { [ 'State is a required field' ] }
284
- />
341
+ { notIndia ( ) ? (
342
+ < TextValidator
343
+ key = "district"
344
+ className = { classes . textField }
345
+ autoComplete = "true"
346
+ label = "District"
347
+ variant = "outlined"
348
+ value = { formData . district }
349
+ fullWidth
350
+ name = "district"
351
+ onChange = { handleChange }
352
+ validators = { [ 'required' ] }
353
+ errorMessages = { [ 'State is a required field' ] }
354
+ />
355
+ ) : (
356
+ < SelectValidator
357
+ key = "district"
358
+ className = { classes . textField }
359
+ autoComplete = "true"
360
+ label = "District"
361
+ variant = "outlined"
362
+ value = { formData . district }
363
+ fullWidth
364
+ onFocus = { handleDistrictFocus }
365
+ name = "district"
366
+ onChange = { handleDistrictFieldChange }
367
+ validators = { [ 'required' ] }
368
+ errorMessages = { [ 'State is a required field' ] }
369
+ >
370
+ { formData . state === undefined ? (
371
+ < MenuItem value = "undefined" > { 'Select State' } </ MenuItem >
372
+ ) : (
373
+ districts . sort ( ) . map ( dis => {
374
+ return < MenuItem value = { dis } > { dis } </ MenuItem > ;
375
+ } )
376
+ ) }
377
+ </ SelectValidator >
378
+ ) }
285
379
286
- < TextValidator
287
- key = "country"
288
- className = { classes . textField }
289
- label = "Country"
290
- variant = "outlined"
291
- value = { formData . country }
292
- fullWidth
293
- name = "country"
294
- onChange = { handleChange }
295
- validators = { [ 'required' ] }
296
- errorMessages = { [ 'Country is a required field' ] }
297
- />
380
+ { notIndia ( ) ? (
381
+ < TextValidator
382
+ key = "college"
383
+ className = { classes . textField }
384
+ label = "College"
385
+ variant = "outlined"
386
+ value = { formData . college }
387
+ onChange = { handleChange }
388
+ fullWidth
389
+ name = "college"
390
+ validators = { [ 'required' ] }
391
+ errorMessages = { [ 'College is a required field' ] }
392
+ />
393
+ ) : (
394
+ < SelectValidator
395
+ key = "college"
396
+ className = { classes . textField }
397
+ label = "College"
398
+ variant = "outlined"
399
+ value = { formData . college }
400
+ fullWidth
401
+ onChange = { handleChange }
402
+ name = "college"
403
+ validators = { [ 'required' ] }
404
+ errorMessages = { [ 'College is a required field' ] }
405
+ >
406
+ { formData . district === undefined ? (
407
+ < MenuItem value = "undefined" > { 'Select District' } </ MenuItem >
408
+ ) : (
409
+ collegeList . sort ( ) . map ( college => {
410
+ return < MenuItem value = { college } > { college } </ MenuItem > ;
411
+ } )
412
+ ) }
413
+ </ SelectValidator >
414
+ ) }
298
415
299
416
< Button variant = "outlined" onClick = { handlePrev } color = "secondary" >
300
417
Prev
0 commit comments