-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New sign up page with form completed and major and year dropdown done. #75
Changes from 14 commits
cafa47d
d036d4d
3f846e0
08f8c57
2fe0d99
2058bc3
3045a41
2e62a6e
14f5930
959070c
de71729
c551b1c
5430eba
df153a0
5afc7d3
faa946b
a77c04b
c4d2572
e4cc0c5
677fd4a
83b1317
2e0922d
b05455b
6a77b39
db011ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as React from 'react'; | ||
import { MenuItem, TextField } from '@material-ui/core'; | ||
import { getIn } from 'formik'; | ||
|
||
import ELIGIBLE_MAJORS from '../../../constants/eligibleMajors'; | ||
|
||
const createFullMajorTitle = (department, major) => { | ||
let fullMajorTitle = ''; | ||
|
||
if (ELIGIBLE_MAJORS[department][major] === 'Computer Engineering') { | ||
if (department === 'CSE') | ||
fullMajorTitle = `${ELIGIBLE_MAJORS[department][major]} - CSE`; | ||
else if (department === 'ECE') | ||
fullMajorTitle = `${ELIGIBLE_MAJORS[department][major]} - ECE`; | ||
} else fullMajorTitle = ELIGIBLE_MAJORS[department][major]; | ||
|
||
return fullMajorTitle; | ||
}; | ||
|
||
/* | ||
* From https://github.com/stackworx/formik-material-ui/tree/master/packages/formik-material-ui/src (TextField) :p | ||
* This essentially takes the props received at the top-level <Field /> as well | ||
* as the default props for that <Field /> (field, form, meta) and transforms | ||
* all that into a props that is suitable for MUI's <TextField /> | ||
*/ | ||
export function fieldToTextField({ | ||
disabled, | ||
field, | ||
form: { isSubmitting, touched, errors }, | ||
...props | ||
}) { | ||
const fieldError = getIn(errors, field.name); | ||
const showError = getIn(touched, field.name) && !!fieldError; | ||
|
||
return { | ||
...props, | ||
...field, | ||
error: showError, | ||
helperText: showError ? fieldError : props.helperText, | ||
disabled: disabled ?? isSubmitting, | ||
variant: props.variant, | ||
}; | ||
} | ||
|
||
const MajorDropdown = props => { | ||
return ( | ||
<TextField select {...fieldToTextField(props)}> | ||
{Object.keys(ELIGIBLE_MAJORS).map(department => | ||
Object.keys(ELIGIBLE_MAJORS[department]).map(major => { | ||
const fullMajorTitle = createFullMajorTitle(department, major); | ||
return <MenuItem value={fullMajorTitle}>{fullMajorTitle}</MenuItem>; | ||
}) | ||
)} | ||
</TextField> | ||
); | ||
}; | ||
|
||
export default MajorDropdown; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as React from 'react'; | ||
import { MenuItem, TextField } from '@material-ui/core'; | ||
import { getIn } from 'formik'; | ||
|
||
const yearDropdownChoices = (minYear, maxYear) => { | ||
const yearChoices = []; | ||
|
||
for (let year = 0; year <= maxYear - minYear; year += 1) { | ||
yearChoices.push(year + minYear); | ||
} | ||
|
||
return yearChoices; | ||
}; | ||
|
||
/* | ||
* From https://github.com/stackworx/formik-material-ui/tree/master/packages/formik-material-ui/src (TextField) :p | ||
* This essentially takes the props received at the top-level <Field /> as well | ||
* as the default props for that <Field /> (field, form, meta) and transforms | ||
* all that into a props that is suitable for MUI's <TextField /> | ||
*/ | ||
export function fieldToTextField({ | ||
disabled, | ||
field, | ||
form: { isSubmitting, touched, errors }, | ||
...props | ||
}) { | ||
const fieldError = getIn(errors, field.name); | ||
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. what's getIn? 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. This is probably the only thing I found that actually explains what getIn() does lol. I don't know why there is no documentation for it on Formik's official website, even though getIn() is imported from formik. |
||
const showError = getIn(touched, field.name) && !!fieldError; | ||
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. no bang bang hacks :) just check if it's null or sth idk what getIn returns |
||
|
||
return { | ||
...props, | ||
...field, | ||
error: showError, | ||
helperText: showError ? fieldError : props.helperText, | ||
disabled: disabled ?? isSubmitting, | ||
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. again change to null check for future sustainability - not a big fan of ?? 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. Honestly that stuff is the stuff that came from formik-material-ui that I didn't touch. I'll change it tho |
||
variant: props.variant, | ||
}; | ||
} | ||
|
||
const YearDropdown = props => { | ||
const { minyear, maxyear } = fieldToTextField(props); | ||
|
||
return ( | ||
<TextField select {...fieldToTextField(props)}> | ||
{yearDropdownChoices(minyear, maxyear).map(year => ( | ||
<MenuItem key={year} value={year}> | ||
{year} | ||
</MenuItem> | ||
))} | ||
</TextField> | ||
); | ||
}; | ||
|
||
export default YearDropdown; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,9 +163,21 @@ const EventEditForm = props => { | |
EventEditForm.propTypes = { | ||
handleSubmit: PropTypes.func.isRequired, | ||
handleCancel: PropTypes.func.isRequired, | ||
initialValues: PropTypes.objectOf( | ||
PropTypes.oneOfType(PropTypes.object, PropTypes.string) | ||
).isRequired, | ||
initialValues: PropTypes.shape({ | ||
startDate: PropTypes.instanceOf(Date).isRequired, | ||
endDate: PropTypes.instanceOf(Date).isRequired, | ||
hosts: PropTypes.arrayOf(PropTypes.string.isRequired).isRequired, | ||
location: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired, | ||
tags: PropTypes.arrayOf(PropTypes.string.isRequired).isRequired, | ||
description: PropTypes.string.isRequired, | ||
urls: PropTypes.shape({ | ||
fb: PropTypes.string.isRequired, | ||
canva: PropTypes.string.isRequired, | ||
rsvp: PropTypes.string.isRequired, | ||
signin: PropTypes.string.isRequired, | ||
}), | ||
}).isRequired, | ||
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. lol looking at all these long af proptypes makes me miss typescript |
||
}; | ||
|
||
export default withStyles(styles)(EventEditForm); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { LinearProgress as CircularProgress } from '@material-ui/core'; | |
|
||
const styles = theme => ({ | ||
progress: { | ||
margin: theme.spacing.unit * 3, | ||
margin: theme.spacing(3), | ||
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. ty for fixing |
||
}, | ||
}); | ||
|
||
|
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.
why is this file changed?
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.
I'm guessing indentation? Not sure why this was changed, it might have been done by VSCode
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.
Okay yeah it's indentation changes made automatically by VSCode, the actual code is still the same as the original html file.