Skip to content

Commit

Permalink
Merge pull request #6 from abraha2d/dev
Browse files Browse the repository at this point in the history
Release 0.2.1-beta.1
  • Loading branch information
abraha2d authored Aug 13, 2018
2 parents d1c3d30 + ef06a25 commit 6663760
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coursewatch",
"version": "0.2.0-alpha.2",
"version": "0.2.1-beta.1",
"homepage": "https://web.coursewatch.sueztech.com",
"bugs": "https://github.com/abraha2d/coursewatch/issues",
"license": "UNLICENSED",
Expand Down
5 changes: 3 additions & 2 deletions src/components/SubscriptionDialog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ class SubscriptionDialog extends React.PureComponent {
loading: false,
responses: { ...prevState.responses, courses: response.data }
}));
this.setState({ suggestions: this.getSuggestions(this.state.course) });
})
.catch(error => this.setState({ loading: false, error }));
};
Expand Down Expand Up @@ -280,7 +279,9 @@ class SubscriptionDialog extends React.PureComponent {
});
}
}}
onSuggestionsClearRequested={() => {}}
onSuggestionsClearRequested={() => {
this.setState({ suggestions: [] });
}}
getSuggestionValue={this.getCourseValue}
renderSuggestion={(course, { query, isHighlighted }) => (
<MenuItem selected={isHighlighted}>
Expand Down
9 changes: 8 additions & 1 deletion src/containers/LoginPage/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
*
*/

import { SET_AUTH } from "./constants";
import { SET_AUTH, SET_USER } from "./constants";

export function setAuth(response) {
return {
type: SET_AUTH,
payload: response
};
}

export function setUser(response) {
return {
type: SET_USER,
payload: response
};
}
1 change: 1 addition & 0 deletions src/containers/LoginPage/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*/

export const SET_AUTH = "app/auth/SET_AUTH";
export const SET_USER = "app/auth/SET_USER";
7 changes: 5 additions & 2 deletions src/containers/LoginPage/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
*/

import { fromJS } from "immutable";
import { SET_AUTH } from "./constants";
import { SET_AUTH, SET_USER } from "./constants";

export const initialState = fromJS({});

function authReducer(state = initialState, action) {
let newState = state;
switch (action.type) {
case SET_AUTH:
let newState = state;
newState = newState.set("token", action.payload.token);
newState = newState.set("user", action.payload.user);
return newState;
case SET_USER:
newState = newState.set("user", action.payload);
return newState;
default:
return state;
}
Expand Down
34 changes: 30 additions & 4 deletions src/containers/ProfilePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import PropTypes from "prop-types";
import { connect } from "react-redux";
import { compose } from "redux";
import { createStructuredSelector } from "reselect";
import axios from "axios";

import {
Avatar,
Expand All @@ -19,6 +20,7 @@ import {
} from "@material-ui/core";

import makeSelectAuth from "containers/LoginPage/selectors";
import { setUser } from "containers/LoginPage/actions";

const styles = theme => ({
container: {
Expand All @@ -42,16 +44,31 @@ const styles = theme => ({
export class ProfilePage extends React.PureComponent {
constructor(props) {
super(props);
this.state = { ...props.auth.user };
this.state = { loading: false, error: null, user: props.auth.user };
}

handleChange = name => event => {
const value = event.target.value;
this.setState({ [name]: value });
this.setState(prevState => ({
user: { ...prevState.user, [name]: value }
}));
};

handleSave = event => {
event.preventDefault();
this.setState({ error: null, loading: true });
axios
.put(
"/api/users/me",
{ ...this.state.user },
{ headers: { Authorization: `Bearer ${this.props.auth.token}` } }
)
.then(response => {
this.setState({ loading: false });
localStorage.setItem("authUser", JSON.stringify(response.data));
this.props.dispatch(setUser(response.data));
})
.catch(error => this.setState({ loading: false, error }));
};

render() {
Expand All @@ -70,7 +87,7 @@ export class ProfilePage extends React.PureComponent {
required
fullWidth
margin="dense"
value={this.state.name}
value={this.state.user.name}
onChange={this.handleChange("name")}
/>
<TextField
Expand All @@ -79,9 +96,17 @@ export class ProfilePage extends React.PureComponent {
required
fullWidth
margin="dense"
value={this.state.email}
value={this.state.user.email}
onChange={this.handleChange("email")}
/>
<TextField
label="Phone"
type="tel"
fullWidth
margin="dense"
value={this.state.user.tel}
onChange={this.handleChange("tel")}
/>
</div>
<div className={classes.actions}>
<Button variant="contained" color="primary" type="submit">
Expand All @@ -95,6 +120,7 @@ export class ProfilePage extends React.PureComponent {
}

ProfilePage.propTypes = {
dispatch: PropTypes.func.isRequired,
auth: PropTypes.object.isRequired
};

Expand Down

0 comments on commit 6663760

Please sign in to comment.