From 5f2814fd6e1ae512f77cf16b5c3a8fcd121bd74a Mon Sep 17 00:00:00 2001 From: Abhishek-kumar09 Date: Sun, 20 Sep 2020 22:24:02 +0530 Subject: [PATCH 1/5] Added AutoSuggestion for District state college --- .../ApplicationsView/ApplicationSteps.js | 173 +++++++++++++++--- src/views/pages/ApplicationsView/helper.js | 27 +++ 2 files changed, 173 insertions(+), 27 deletions(-) create mode 100644 src/views/pages/ApplicationsView/helper.js diff --git a/src/views/pages/ApplicationsView/ApplicationSteps.js b/src/views/pages/ApplicationsView/ApplicationSteps.js index 03200bd1..4d27ca3a 100644 --- a/src/views/pages/ApplicationsView/ApplicationSteps.js +++ b/src/views/pages/ApplicationsView/ApplicationSteps.js @@ -17,6 +17,10 @@ import { SelectValidator } from 'react-material-ui-form-validator'; +import { getStates, getDistrict, getColleges } from './helper'; + +// import axios from 'axios'; + const useStyles = makeStyles(theme => ({ root: { width: '100%' @@ -308,6 +312,9 @@ function FormEducationInfo({ }) { const classes = useStyles(); const [formData, updateFormData] = useState(data.education); + const [districtToCollegePair, updateDistrictToCollegePair] = useState({}); + const [districts, updateDistricts] = useState([]); + const [collegeList, updateCollege] = useState([]); const handleChange = event => { updateFormData({ @@ -339,9 +346,40 @@ function FormEducationInfo({ setActiveStep(2); }; + const handleStateFieldChange = event => { + updateFormData({ + ...formData, + [event.target.name]: event.target.value + }); + updateDistrictToCollegePair(getDistrict(event.target.value)); + }; + + const handleDistrictFieldChange = event => { + updateFormData({ + ...formData, + [event.target.name]: event.target.value + }); + updateCollege(getColleges(districtToCollegePair, event.target.value)); + }; + + const handleDistrictFocus = () => { + if (formData.state != undefined) { + updateDistricts(Object.keys(districtToCollegePair)); + } + }; + + function notIndia() { + return ( + formData.country === undefined || + formData.country.trim().toLowerCase() !== 'india' + ); + } + const years = Array(25) - .fill(2000) - .map((x, y) => x + y); + .fill(2024) + .map((x, y) => x - y); + + const states = getStates(); return ( @@ -361,7 +399,6 @@ function FormEducationInfo({ return {year}; })} - + {notIndia() ? ( + + ) : ( + + {states.sort().map(state => { + return {state}; + })} + + )} - + {notIndia() ? ( + + ) : ( + + {formData.state === undefined ? ( + {'Select State'} + ) : ( + districts.sort().map(dis => { + return {dis}; + }) + )} + + )} - + {notIndia() ? ( + + ) : ( + + {formData.district === undefined ? ( + {'Select District'} + ) : ( + collegeList.sort().map(college => { + return {college}; + }) + )} + + )}