Skip to content

Commit

Permalink
Make profile editable
Browse files Browse the repository at this point in the history
  • Loading branch information
darkenergy96 committed Oct 1, 2018
1 parent cc2afb3 commit cb5bc22
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion components/dashboard/profile/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class extends Component {
} else {
return (
<>
<ToggleDisplay hide={this.state.profileEditable}>
<ToggleDisplay hide={profileEditable}>
<Profile
profile={profile}
toggleProfileForm={this.toggleProfileForm}
Expand Down
36 changes: 30 additions & 6 deletions components/dashboard/profile/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,32 @@ const styles = theme => ({
paddingBottom: theme.spacing.unit * 2
}
});
function renderOtherFields(profile) {
if (profile.phone) {
return (
<>
<p>
<b>Phone</b> :&nbsp;
{profile.phone}
</p>
<p>
<b>College</b> :&nbsp;
{profile.college}
</p>
</>
);
}
return (
<>
<p>
<b>Phone</b> :&nbsp; Not provided
</p>
<p>
<b>College</b> :&nbsp; Not provided
</p>
</>
);
}
export default withStyles(styles)(function({
profile,
toggleProfileForm,
Expand Down Expand Up @@ -63,18 +89,16 @@ export default withStyles(styles)(function({
<b>Gender</b> :&nbsp;
{profile.gender}
</p>
<p>
<b>College</b> :&nbsp;
{profile.college}
</p>
<ToggleDisplay hide={profile.updatedProfile}>

{renderOtherFields(profile)}
<ToggleDisplay>
<Button
color="primary"
variant="contained"
onClick={toggleProfileForm}
style={{ margin: "auto" }}
>
UPDATE PROFILE
{profile.updatedProfile ? "EDIT PROFILE" : "UPDATE PROFILE"}
</Button>
</ToggleDisplay>
</Paper>
Expand Down
31 changes: 12 additions & 19 deletions components/dashboard/profile/UpdateProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,10 @@ class UpdateProfile extends Component {
colleges: []
};

static getDerivedStateFromProps(props, state) {
let newState = { ...state };
if (props.profile) {
newState.name = props.profile.name;
if (props.profile.gender) {
newState.gender = props.profile.gender;
}
}
return newState;
}
componentDidMount() {
if (this.props.profile) {
this.setState({ ...this.state, ...this.props.profile });
}
this.fetchAllCities();
}
fetchAllCities = () => {
Expand Down Expand Up @@ -131,9 +124,9 @@ class UpdateProfile extends Component {
<div className="row center-md center-xs center-lg">
<div className="col-md-6">
<Paper className={classes.root} elevation={1}>
<p style={{ textAlign: "center", color: "red" }}>
* These fields must be filled and can only be updated once *
</p>
<h3 style={{ textAlign: "center", color: "#4caf50" }}>
UPDATE PROFILE
</h3>
<form className={classes.container} noValidate autoComplete="off">
<TextField
id="name"
Expand Down Expand Up @@ -239,16 +232,16 @@ class UpdateProfile extends Component {
fullWidth
required
>
<MenuItem value={1}>1</MenuItem>
<MenuItem value={2}>2</MenuItem>
<MenuItem value={3}>3</MenuItem>
<MenuItem value={4}>4</MenuItem>
<MenuItem value="1">1</MenuItem>
<MenuItem value="2">2</MenuItem>
<MenuItem value="3">3</MenuItem>
<MenuItem value="4">4</MenuItem>
</TextField>
<div>
{/* <div>
<p style={{ textAlign: "center", color: "red" }}>
* These fields must be filled and can only be updated once *
</p>
</div>
</div> */}
<Button
color="primary"
variant="contained"
Expand Down

0 comments on commit cb5bc22

Please sign in to comment.