From 615503078e85803b8f8e46377b6d35094c56333e Mon Sep 17 00:00:00 2001 From: Kevin Abraham Date: Wed, 8 Aug 2018 12:05:40 -0400 Subject: [PATCH 01/10] Put proxy config back to localhost --- package.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d85ad57..7443213 100644 --- a/package.json +++ b/package.json @@ -78,5 +78,12 @@ "git add" ] }, - "proxy": "https://web.coursewatch.sueztech.com" + "proxy": { + "/api": { + "target": "http://localhost:9000", + "pathRewrite": { + "^/api/": "/" + } + } + } } From 219b58da3f708541d75073f3a776a3239c12a896 Mon Sep 17 00:00:00 2001 From: Kevin Abraham Date: Wed, 8 Aug 2018 17:40:54 -0400 Subject: [PATCH 02/10] Add college and term dropdowns to add course dialog --- src/components/AddCourseDialog/index.js | 144 +++++++++++++++++++----- 1 file changed, 115 insertions(+), 29 deletions(-) diff --git a/src/components/AddCourseDialog/index.js b/src/components/AddCourseDialog/index.js index b1ff627..dc31011 100644 --- a/src/components/AddCourseDialog/index.js +++ b/src/components/AddCourseDialog/index.js @@ -15,8 +15,11 @@ import { DialogActions, DialogContent, DialogTitle, + FormControl, + InputLabel, + MenuItem, Paper, - TextField, + Select as MuiSelect, Typography, withMobileDialog, withStyles @@ -38,18 +41,24 @@ const styles = theme => ({ class AddCourseDialog extends React.PureComponent { state = { - term: "201809", - crn: "", + college: "", + term: "", + course: "", loading: false, + responses: { + colleges: null, + terms: null, + courses: null + }, error: null, errors: { + college: false, term: false, - crn: false + course: false } }; - handleChange = name => event => { - const value = event.target.value; + handleChange = name => value => { this.setState(prevState => ({ [name]: value, errors: { @@ -57,6 +66,64 @@ class AddCourseDialog extends React.PureComponent { [name]: false } })); + if (name === "college") { + this.getTerms(value); + } else if (name === "term") { + this.getCourses(value); + } + }; + + getColleges = () => { + this.setState(prevState => ({ + error: null, + loading: true, + responses: { ...prevState.responses, terms: null, courses: null } + })); + axios + .get("/api/colleges", { + headers: { Authorization: `Bearer ${this.props.apiAccessToken}` } + }) + .then(response => { + this.setState(prevState => ({ + loading: false, + responses: { ...prevState.responses, colleges: response.data } + })); + }) + .catch(error => this.setState({ loading: false, error })); + }; + + getTerms = college => { + this.setState(prevState => ({ + error: null, + loading: true, + responses: { ...prevState.responses, courses: null } + })); + axios + .get(`/api/terms?college=${college}`, { + headers: { Authorization: `Bearer ${this.props.apiAccessToken}` } + }) + .then(response => { + this.setState(prevState => ({ + loading: false, + responses: { ...prevState.responses, terms: response.data } + })); + }) + .catch(error => this.setState({ loading: false, error })); + }; + + getCourses = term => { + this.setState({ error: null, loading: true }); + return axios + .get(`/api/courses?term=${term}`, { + headers: { Authorization: `Bearer ${this.props.apiAccessToken}` } + }) + .then(response => { + this.setState(prevState => ({ + loading: false, + responses: { ...prevState.responses, courses: response.data } + })); + }) + .catch(error => this.setState({ loading: false, error })); }; addCourse = event => { @@ -65,14 +132,8 @@ class AddCourseDialog extends React.PureComponent { axios .post( "/api/subscriptions", - { - term: this.state.term, - crn: this.state.crn, - title: `Sample Course (CRN: ${this.state.crn})` - }, - { - headers: { Authorization: `Bearer ${this.props.apiAccessToken}` } - } + { course: this.state.course }, + { headers: { Authorization: `Bearer ${this.props.apiAccessToken}` } } ) .then(response => { this.setState({ loading: false }); @@ -81,6 +142,10 @@ class AddCourseDialog extends React.PureComponent { .catch(error => this.setState({ loading: false, error })); }; + componentWillMount() { + this.getColleges(); + } + render() { const { classes } = this.props; return ( @@ -101,27 +166,48 @@ class AddCourseDialog extends React.PureComponent {
Add course - - + College + + this.handleChange("college")(event.target.value) + } + inputProps={{ name: "college", id: "college" }} + > + {this.state.responses.colleges && + this.state.responses.colleges.map(college => ( + {college.name} + ))} + + + + error={this.state.errors.term !== false} + > + Term + + this.handleChange("term")(event.target.value) + } + inputProps={{ name: "term", id: "term" }} + > + {this.state.responses.terms && + this.state.responses.terms.map(term => ( + {term.name} + ))} + +