Skip to content

Commit d1c3d30

Browse files
authored
Merge pull request #4 from abraha2d/dev
Release v0.2.0
2 parents b0e4c7f + c8d742f commit d1c3d30

File tree

3 files changed

+120
-18
lines changed

3 files changed

+120
-18
lines changed

src/containers/HomePage/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import React from "react";
88
import PropTypes from "prop-types";
99
import { connect } from "react-redux";
1010
import { compose } from "redux";
11+
import { createStructuredSelector } from "reselect";
1112
import { Route, Switch } from "react-router-dom";
1213
import { push } from "connected-react-router/immutable";
1314

@@ -33,9 +34,13 @@ import {
3334
Settings as SettingsIcon
3435
} from "@material-ui/icons";
3536

37+
import makeSelectAuth from "containers/LoginPage/selectors";
38+
3639
import Subscriptions from "containers/Subscriptions";
40+
import ProfilePage from "containers/ProfilePage";
3741
import Settings from "containers/Settings";
3842
import NotFoundPage from "containers/NotFoundPage";
43+
3944
import LogoutButton from "containers/LoginPage/ConnectedLogoutButton";
4045
import UserListItem from "components/UserListItem";
4146

@@ -182,6 +187,7 @@ class HomePage extends React.PureComponent {
182187
<div className={classes.toolbar} />
183188
<Switch>
184189
<Route exact path="/" component={Subscriptions} />
190+
<Route exact path="/profile" component={ProfilePage} />
185191
<Route exact path="/settings" component={Settings} />
186192
<Route component={NotFoundPage} />
187193
</Switch>
@@ -198,14 +204,9 @@ HomePage.propTypes = {
198204
auth: PropTypes.object
199205
};
200206

201-
const mapStateToProps = state => {
202-
let location = state.getIn(["router", "location"]).toJS();
203-
if (location.location) {
204-
location = location.location;
205-
}
206-
const auth = state.get("auth").toJS();
207-
return { location, auth };
208-
};
207+
const mapStateToProps = createStructuredSelector({
208+
auth: makeSelectAuth()
209+
});
209210

210211
const withConnect = connect(mapStateToProps);
211212

src/containers/NotFoundPage/index.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import React from "react";
88
import PropTypes from "prop-types";
9-
import { connect } from "react-redux";
109

1110
import { Typography } from "@material-ui/core";
1211

@@ -23,12 +22,4 @@ NotFoundPage.propTypes = {
2322
location: PropTypes.object.isRequired
2423
};
2524

26-
const mapStateToProps = state => {
27-
let location = state.getIn(["router", "location"]).toJS();
28-
if (location.location) {
29-
location = location.location;
30-
}
31-
return { location };
32-
};
33-
34-
export default connect(mapStateToProps)(NotFoundPage);
25+
export default NotFoundPage;

src/containers/ProfilePage/index.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/**
2+
*
3+
* ProfilePage
4+
*
5+
*/
6+
7+
import React from "react";
8+
import PropTypes from "prop-types";
9+
import { connect } from "react-redux";
10+
import { compose } from "redux";
11+
import { createStructuredSelector } from "reselect";
12+
13+
import {
14+
Avatar,
15+
Button,
16+
TextField,
17+
Typography,
18+
withStyles
19+
} from "@material-ui/core";
20+
21+
import makeSelectAuth from "containers/LoginPage/selectors";
22+
23+
const styles = theme => ({
24+
container: {
25+
display: "flex",
26+
flexDirection: "column"
27+
},
28+
centerAvatar: {
29+
width: "96px",
30+
height: "96px",
31+
alignSelf: "center"
32+
},
33+
content: {
34+
padding: `${theme.spacing.unit}px`
35+
},
36+
actions: {
37+
padding: `${theme.spacing.unit}px`,
38+
textAlign: "end"
39+
}
40+
});
41+
42+
export class ProfilePage extends React.PureComponent {
43+
constructor(props) {
44+
super(props);
45+
this.state = { ...props.auth.user };
46+
}
47+
48+
handleChange = name => event => {
49+
const value = event.target.value;
50+
this.setState({ [name]: value });
51+
};
52+
53+
handleSave = event => {
54+
event.preventDefault();
55+
};
56+
57+
render() {
58+
const { classes } = this.props;
59+
return (
60+
<div className={classes.container}>
61+
<Typography variant="title">Profile</Typography>
62+
<Avatar
63+
src={this.props.auth.user.picture}
64+
className={classes.centerAvatar}
65+
/>
66+
<form onSubmit={this.handleSave}>
67+
<div className={classes.content}>
68+
<TextField
69+
label="Name"
70+
required
71+
fullWidth
72+
margin="dense"
73+
value={this.state.name}
74+
onChange={this.handleChange("name")}
75+
/>
76+
<TextField
77+
label="Email"
78+
type="email"
79+
required
80+
fullWidth
81+
margin="dense"
82+
value={this.state.email}
83+
onChange={this.handleChange("email")}
84+
/>
85+
</div>
86+
<div className={classes.actions}>
87+
<Button variant="contained" color="primary" type="submit">
88+
Save
89+
</Button>
90+
</div>
91+
</form>
92+
</div>
93+
);
94+
}
95+
}
96+
97+
ProfilePage.propTypes = {
98+
auth: PropTypes.object.isRequired
99+
};
100+
101+
const mapStateToProps = createStructuredSelector({
102+
auth: makeSelectAuth()
103+
});
104+
105+
const withConnect = connect(mapStateToProps);
106+
107+
export default compose(
108+
withConnect,
109+
withStyles(styles)
110+
)(ProfilePage);

0 commit comments

Comments
 (0)