mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
Edit Profile front-end finished and connected to back-end
This commit is contained in:
parent
696b00e304
commit
721aeeb350
@ -1,6 +1,8 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
// TODO: Add a read-only '@' in the left side of the handle input
|
||||||
|
// TODO: Add a cancel button, that takes the user back to their profile page
|
||||||
|
|
||||||
// Material-UI stuff
|
// Material-UI stuff
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
@ -8,6 +10,8 @@ import Typography from "@material-ui/core/Typography";
|
|||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
import Grid from "@material-ui/core/Grid";
|
import Grid from "@material-ui/core/Grid";
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
|
import CircularProgress from '@material-ui/core/CircularProgress';
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
form: {
|
form: {
|
||||||
textAlign: "center"
|
textAlign: "center"
|
||||||
@ -18,16 +22,13 @@ const styles = {
|
|||||||
pageTitle: {
|
pageTitle: {
|
||||||
marginTop: 40,
|
marginTop: 40,
|
||||||
marginBottom: 40
|
marginBottom: 40
|
||||||
|
},
|
||||||
|
button: {
|
||||||
|
positon: 'relative',
|
||||||
|
},
|
||||||
|
progress: {
|
||||||
|
position: 'absolute',
|
||||||
}
|
}
|
||||||
// firstName: {
|
|
||||||
// marginRight: 10,
|
|
||||||
// },
|
|
||||||
// lastname: {
|
|
||||||
// marginLeft: 10,
|
|
||||||
// }
|
|
||||||
// name: {
|
|
||||||
// width: '40%'
|
|
||||||
// }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// const classes = useStyles();
|
// const classes = useStyles();
|
||||||
@ -45,14 +46,7 @@ export class edit extends Component {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
axios
|
axios
|
||||||
.get("/getProfileInfo")
|
.get("/getProfileInfo")
|
||||||
.then(res => {
|
.then((res) => {
|
||||||
// console.log(res.data);
|
|
||||||
// this.state.firstName = res.data.firstName;
|
|
||||||
// this.state.lastName = res.data.lastName;
|
|
||||||
// this.state.email = res.data.email;
|
|
||||||
// this.state.handle = res.data.handle;
|
|
||||||
// this.state.bio = res.data.bio;
|
|
||||||
// this.state.valid = true;
|
|
||||||
this.setState({
|
this.setState({
|
||||||
firstName: res.data.firstName,
|
firstName: res.data.firstName,
|
||||||
lastName: res.data.lastName,
|
lastName: res.data.lastName,
|
||||||
@ -61,7 +55,7 @@ export class edit extends Component {
|
|||||||
bio: res.data.bio
|
bio: res.data.bio
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -82,49 +76,45 @@ export class edit extends Component {
|
|||||||
handleSubmit = (event) => {
|
handleSubmit = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.setState({
|
this.setState({
|
||||||
loading: true,
|
loading: true
|
||||||
});
|
});
|
||||||
const newProfileData = {
|
const newProfileData = {
|
||||||
firstName: this.state.firstName,
|
firstName: this.state.firstName,
|
||||||
lastName: this.state.lastName,
|
lastName: this.state.lastName,
|
||||||
email: this.state.email,
|
email: this.state.email,
|
||||||
handle: this.state.handle,
|
handle: this.state.handle,
|
||||||
bio: this.state.bio,
|
bio: this.state.bio
|
||||||
}
|
};
|
||||||
axios.post('updateProfileInfo', newProfileData)
|
axios
|
||||||
.then((res) => {
|
.post("/updateProfileInfo", newProfileData)
|
||||||
this.setState({
|
.then((res) => {
|
||||||
loading: false,
|
this.setState({
|
||||||
});
|
loading: false
|
||||||
// this.props.history.push('/');
|
});
|
||||||
})
|
// this.props.history.push('/');
|
||||||
.catch((err) => {
|
// TODO: Need to redirect user to their profile page
|
||||||
this.setState({
|
})
|
||||||
errors: err.response.data,
|
.catch((err) => {
|
||||||
loading: false,
|
this.setState({
|
||||||
});
|
errors: err.response.data,
|
||||||
})
|
loading: false
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
handleChange = (event) => {
|
handleChange = (event) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
[event.target.name]: event.target.value
|
[event.target.name]: event.target.value,
|
||||||
|
errors: {
|
||||||
|
[event.target.name]: null,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { classes } = this.props;
|
const { classes } = this.props;
|
||||||
const { errors, loading } = this.state;
|
const { errors, loading } = this.state;
|
||||||
// let editProfileMarkup = this.state.profileData ? (
|
|
||||||
// // this.state.profileData.map(profileData => <p>{profileData}</p>)
|
|
||||||
// <div>
|
|
||||||
|
|
||||||
// <p>{this.state.profileData.firstName}</p>
|
|
||||||
// <p>{this.state.profileData.lastName}</p>
|
|
||||||
// <p>{this.state.profileData.email}</p>
|
|
||||||
// <p>{this.state.profileData.bio}</p>
|
|
||||||
// </div>
|
|
||||||
// ) : <p>Loading...</p>
|
|
||||||
return (
|
return (
|
||||||
<Grid container className={classes.form}>
|
<Grid container className={classes.form}>
|
||||||
<Grid item sm />
|
<Grid item sm />
|
||||||
@ -141,6 +131,8 @@ export class edit extends Component {
|
|||||||
label="First Name"
|
label="First Name"
|
||||||
className={classes.textField}
|
className={classes.textField}
|
||||||
value={this.state.firstName}
|
value={this.state.firstName}
|
||||||
|
helperText={errors.firstName}
|
||||||
|
error={errors.firstName ? true : false}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
@ -153,6 +145,8 @@ export class edit extends Component {
|
|||||||
label="Last Name"
|
label="Last Name"
|
||||||
className={classes.textField}
|
className={classes.textField}
|
||||||
value={this.state.lastName}
|
value={this.state.lastName}
|
||||||
|
helperText={errors.lastname}
|
||||||
|
error={errors.lastName ? true : false}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
@ -162,11 +156,13 @@ export class edit extends Component {
|
|||||||
<TextField
|
<TextField
|
||||||
id="email"
|
id="email"
|
||||||
name="email"
|
name="email"
|
||||||
label="Email"
|
label="Email*"
|
||||||
className={classes.textField}
|
className={classes.textField}
|
||||||
value={this.state.email}
|
value={this.state.email}
|
||||||
disabled
|
disabled
|
||||||
helperText="(disabled)"
|
helperText="(disabled)"
|
||||||
|
// helperText={errors.email}
|
||||||
|
// error={errors.email ? true : false}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
@ -174,11 +170,13 @@ export class edit extends Component {
|
|||||||
<TextField
|
<TextField
|
||||||
id="handle"
|
id="handle"
|
||||||
name="handle"
|
name="handle"
|
||||||
label="Handle"
|
label="Handle*"
|
||||||
className={classes.textField}
|
className={classes.textField}
|
||||||
value={this.state.handle}
|
value={this.state.handle}
|
||||||
disabled
|
disabled
|
||||||
helperText="(disabled)"
|
helperText="(disabled)"
|
||||||
|
// helperText={errors.handle}
|
||||||
|
// error={errors.handle ? true : false}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
@ -189,6 +187,8 @@ export class edit extends Component {
|
|||||||
label="Bio"
|
label="Bio"
|
||||||
className={classes.textField}
|
className={classes.textField}
|
||||||
value={this.state.bio}
|
value={this.state.bio}
|
||||||
|
helperText={errors.bio}
|
||||||
|
error={errors.bio ? true : false}
|
||||||
multiline
|
multiline
|
||||||
rows="8"
|
rows="8"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
@ -200,8 +200,12 @@ export class edit extends Component {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
className={classes.button}
|
className={classes.button}
|
||||||
|
disabled={loading}
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
|
{loading && (
|
||||||
|
<CircularProgress size={30} className={classes.progress}/>
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user