This repository has been archived by the owner on Mar 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Added Selectors for State Districts and Colleges #78
Open
Abhishek-kumar09
wants to merge
5
commits into
codeforcauseorg:development
Choose a base branch
from
Abhishek-kumar09:jason_filtering
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5f2814f
Added AutoSuggestion for District state college
Abhishek-kumar09 61a6127
Added AutoSuggestion for District state college
Abhishek-kumar09 e53a1d3
Resolve Conflicts and set active step to 1
Abhishek-kumar09 96d2b23
resolve netlify errors
Abhishek-kumar09 fbeaace
Clear District and College fields on changing state"
Abhishek-kumar09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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%' | ||
|
@@ -93,7 +97,7 @@ export function ApplicationSteps({ applicationId, setCourseTitle }) { | |
const isMountedRef = useIsMountedRef(); | ||
const baseUrl = | ||
'https://us-central1-codeforcauseorg.cloudfunctions.net/widgets/applications/request'; | ||
const [activeStep, setActiveStep] = React.useState(-1); | ||
const [activeStep, setActiveStep] = React.useState(1); | ||
const [formData, setFormData] = React.useState({ | ||
personal: {}, | ||
education: {}, | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most often, Courses will be booked by recent graduates, so reversed the array from |
||
|
||
const states = getStates(); | ||
|
||
return ( | ||
<ValidatorForm onSubmit={handleSubmit}> | ||
|
@@ -361,33 +399,6 @@ function FormEducationInfo({ | |
return <MenuItem value={year}>{year}</MenuItem>; | ||
})} | ||
</SelectValidator> | ||
|
||
<TextValidator | ||
key="college" | ||
className={classes.textField} | ||
label="College" | ||
variant="outlined" | ||
value={formData.college} | ||
fullWidth | ||
name="college" | ||
onChange={handleChange} | ||
validators={['required']} | ||
errorMessages={['College is a required field']} | ||
/> | ||
|
||
<TextValidator | ||
key="state" | ||
className={classes.textField} | ||
label="State" | ||
variant="outlined" | ||
value={formData.state} | ||
fullWidth | ||
name="state" | ||
onChange={handleChange} | ||
validators={['required']} | ||
errorMessages={['State is a required field']} | ||
/> | ||
|
||
<TextValidator | ||
key="country" | ||
className={classes.textField} | ||
|
@@ -400,6 +411,114 @@ function FormEducationInfo({ | |
validators={['required']} | ||
errorMessages={['Country is a required field']} | ||
/> | ||
{notIndia() ? ( | ||
<TextValidator | ||
key="state" | ||
className={classes.textField} | ||
autoComplete="true" | ||
label="State" | ||
variant="outlined" | ||
value={formData.state} | ||
fullWidth | ||
name="state" | ||
onChange={handleChange} | ||
validators={['required']} | ||
errorMessages={['State is a required field']} | ||
/> | ||
) : ( | ||
<SelectValidator | ||
key="state" | ||
className={classes.textField} | ||
autoComplete="true" | ||
label="State" | ||
variant="outlined" | ||
value={formData.state} | ||
fullWidth | ||
name="state" | ||
onChange={handleStateFieldChange} | ||
validators={['required']} | ||
errorMessages={['State is a required field']} | ||
> | ||
{states.sort().map(state => { | ||
return <MenuItem value={state}>{state}</MenuItem>; | ||
})} | ||
</SelectValidator> | ||
)} | ||
|
||
{notIndia() ? ( | ||
<TextValidator | ||
key="district" | ||
className={classes.textField} | ||
autoComplete="true" | ||
label="District" | ||
variant="outlined" | ||
value={formData.district} | ||
fullWidth | ||
name="district" | ||
onChange={handleChange} | ||
validators={['required']} | ||
errorMessages={['State is a required field']} | ||
/> | ||
) : ( | ||
<SelectValidator | ||
key="district" | ||
className={classes.textField} | ||
autoComplete="true" | ||
label="District" | ||
variant="outlined" | ||
value={formData.district} | ||
fullWidth | ||
onFocus={handleDistrictFocus} | ||
name="district" | ||
onChange={handleDistrictFieldChange} | ||
validators={['required']} | ||
errorMessages={['State is a required field']} | ||
> | ||
{formData.state === undefined ? ( | ||
<MenuItem value="undefined">{'Select State'}</MenuItem> | ||
) : ( | ||
districts.sort().map(dis => { | ||
return <MenuItem value={dis}>{dis}</MenuItem>; | ||
}) | ||
)} | ||
</SelectValidator> | ||
)} | ||
|
||
{notIndia() ? ( | ||
<TextValidator | ||
key="college" | ||
className={classes.textField} | ||
label="College" | ||
variant="outlined" | ||
value={formData.college} | ||
onChange={handleChange} | ||
fullWidth | ||
name="college" | ||
validators={['required']} | ||
errorMessages={['College is a required field']} | ||
/> | ||
) : ( | ||
<SelectValidator | ||
key="college" | ||
className={classes.textField} | ||
label="College" | ||
variant="outlined" | ||
value={formData.college} | ||
fullWidth | ||
onChange={handleChange} | ||
name="college" | ||
validators={['required']} | ||
errorMessages={['College is a required field']} | ||
> | ||
{formData.district === undefined ? ( | ||
<MenuItem value="undefined">{'Select District'}</MenuItem> | ||
) : ( | ||
collegeList.sort().map(college => { | ||
return <MenuItem value={college}>{college}</MenuItem>; | ||
}) | ||
)} | ||
</SelectValidator> | ||
)} | ||
|
||
<Button variant="outlined" onClick={handlePrev} color="secondary"> | ||
Prev | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Data from '../../../data/colleges.json'; | ||
|
||
export function getStates() { | ||
return Object.keys(Data); | ||
} | ||
|
||
export function getDistrict(state) { | ||
const disToC = Object.keys(Data) | ||
.filter(st => st === state) | ||
.reduce((obj, key) => { | ||
obj[key] = Data[key]; | ||
return obj; | ||
}, {}); | ||
|
||
return Object.values(disToC)[0]; | ||
} | ||
|
||
export function getColleges(districtToCollegePair, district) { | ||
const colleges = Object.keys(districtToCollegePair) | ||
.filter(dis => dis === district) | ||
.reduce((obj, key) => { | ||
obj[key] = districtToCollegePair[key]; | ||
return obj; | ||
}, {}); | ||
|
||
return Object.values(colleges)[0]; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary, just for easy review
1st thing to change after/before merging PR