Skip to content

Commit

Permalink
Fix autofill + refactor radio buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
VikramjeetD authored and AetherPrior committed Jun 13, 2020
1 parent 3c1d83a commit 3a907ff
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 45 deletions.
10 changes: 7 additions & 3 deletions client/src/actions/helForm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from "axios";
import { SUBMIT_SUCCESS, SUBMIT_FAIL } from "./types";
import { SUBMIT_SUCCESS, SUBMIT_FAIL, UPDATE_INFO } from "./types";

export const submitForm = (
slotNumber,
Expand All @@ -18,7 +18,7 @@ export const submitForm = (
try {
await axios
.post("/api/helform/submit", helData, config)
.then(function(response) {
.then(function (response) {
if (response.status !== 201) {
throw new Error("Could not submit form.");
}
Expand All @@ -33,14 +33,18 @@ export const submitForm = (
const studentData = JSON.stringify({ email, studentBranch, year });
await axios
.post("/api/helform/firstlogin", studentData, config)
.then(function(response) {
.then(function (response) {
if (response.status !== 201) {
console.log("Update failed: " + response.status);
throw new Error("Could not submit form.");
} else {
dispatch({
type: SUBMIT_SUCCESS
});
dispatch({
type: UPDATE_INFO,
payload: { branch: studentBranch, year: year }
});
}
});
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions client/src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export const LOGIN_SUCCESS = "LOGIN_SUCCESS";
export const LOGIN_FAILURE = "LOGIN_FAILURE";
export const LOGOUT_SUCCESS = "LOGOUT_SUCCESS";
export const LOGOUT_FAILURE = "LOGOUT_FAILURE";
export const UPDATE_INFO = "UPDATE_INFO";
export const USER_LOADED = "USER_LOADED";
export const NO_USER = "NO_USER";
61 changes: 21 additions & 40 deletions client/src/components/layout/YearSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ const YearSelector = props => {
setYear({ ...yearData, year: e.target.value });
};

let yearList = [
["1", "First"],
["2", "Second"],
["3", "Third"],
["4", "Fourth"],
["5", "Fifth"]
];
let str = [];
yearList.map(Year => {
str.push(
<FormControlLabel
value={Year[0]}
control={<Radio color='primary' />}
label={Year[1]}
className='text-black'
onChange={handleYearChange}
checked={year === Year[0]}
/>
);
});
return (
<Fragment>
<p className='label-mod branch-inp'>Select year: </p>
Expand All @@ -31,46 +51,7 @@ const YearSelector = props => {
defaultValue='End'
className='radio-grp'
>
<FormControlLabel
value='1'
control={<Radio color='primary' />}
label='First'
className='text-black'
onChange={handleYearChange}
checked={year === "1"}
/>
<FormControlLabel
value='2'
control={<Radio color='primary' />}
label='Second'
className='text-black'
onChange={handleYearChange}
checked={year === "2"}
/>
<FormControlLabel
value='3'
control={<Radio color='primary' />}
label='Third'
className='text-black'
onChange={handleYearChange}
checked={year === "3"}
/>
<FormControlLabel
value='4'
control={<Radio color='primary' />}
label='Fourth'
className='text-black'
onChange={handleYearChange}
checked={year === "4"}
/>
<FormControlLabel
value='5'
control={<Radio color='primary' />}
label='Fifth'
className='text-black'
onChange={handleYearChange}
checked={year === "5"}
/>
{str}
</RadioGroup>
</FormControl>
</Fragment>
Expand Down
9 changes: 8 additions & 1 deletion client/src/reducers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
LOGIN_FAILURE,
LOGIN_SUCCESS,
LOGOUT_SUCCESS,
UPDATE_INFO,
LOGOUT_FAILURE,
USER_LOADED,
NO_USER
Expand All @@ -12,7 +13,7 @@ const initialState = {
user: null
};

export default function(state = initialState, action) {
export default function (state = initialState, action) {
const { type, payload } = action;
switch (type) {
case USER_LOADED:
Expand All @@ -23,6 +24,12 @@ export default function(state = initialState, action) {
user: payload
};

case UPDATE_INFO:
return {
...state,
user: { ...state.user, branch: payload.branch, year: payload.year }
};

case NO_USER:
case LOGOUT_SUCCESS:
case LOGIN_FAILURE:
Expand Down
2 changes: 1 addition & 1 deletion client/src/reducers/helForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const initialState = {
submitted: false
};

export default function(state = initialState, action) {
export default function (state = initialState, action) {
const { type, payload } = action;

switch (type) {
Expand Down

0 comments on commit 3a907ff

Please sign in to comment.