Skip to content

Commit

Permalink
Frontend: Add Fullname to the Registration and Profile pages (#32)
Browse files Browse the repository at this point in the history
* Add fullname to registration form + validate it + updating it on the profile.

* Profile page now supports updating passwords by the user + About Me section.

* Support fullname + validation + about me

* Support fullname + validation + about me

Co-authored-by: Nadav Goldin <[email protected]>
  • Loading branch information
royackerman and nvgoldin authored Jul 8, 2020
1 parent bb4f492 commit 88a2ef1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
13 changes: 12 additions & 1 deletion frontend/zulu/src/components/Login/profile.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export default class Profile extends Component {
this.state = { currentUser: AuthService.getCurrentUser() };

}




render() {
console.log(this.state.currentUser);
return (
Expand All @@ -19,12 +23,19 @@ export default class Profile extends Component {
</header>
<p>
<strong>Full name:</strong>{" "}
{this.state.currentUser.full_name}
{this.state.currentUser.fullname}
</p>
<p>
<strong>Email:</strong>{" "}
{this.state.currentUser.email}
</p>

<p>
<strong>About Me:</strong>{" "}
{this.state.currentUser.fullname} ! What can you tell us about you?
</p>


</div>
);
}
Expand Down
44 changes: 43 additions & 1 deletion frontend/zulu/src/components/Login/register.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Form from "react-validation/build/form";
import Input from "react-validation/build/input";
import CheckButton from "react-validation/build/button";
import { isEmail } from "validator";
import { isAlpha } from "validator";

import AuthService from "../../services/auth.service";

Expand All @@ -26,7 +27,19 @@ const email = value => {
}
};


const vusername = value => {
if (value.length < 3 || value.length > 20 || !isAlpha(value)) {
return (
<div className="alert alert-danger" role="alert">
The full name must be between 3 and 20 characters, and only letters are allowed.
</div>
);
}
};

// Validator for fullname //
const vfullname = value => {
if (value.length < 3 || value.length > 20) {
return (
<div className="alert alert-danger" role="alert">
Expand All @@ -36,6 +49,8 @@ const vusername = value => {
}
};



const vpassword = value => {
if (value.length < 6 || value.length > 40) {
return (
Expand All @@ -51,6 +66,7 @@ export default class Register extends Component {
super(props);
this.handleRegister = this.handleRegister.bind(this);
this.onChangeUsername = this.onChangeUsername.bind(this);
this.onChangeFullname = this.onChangeFullname.bind(this);
this.onChangeEmail = this.onChangeEmail.bind(this);
this.onChangePassword = this.onChangePassword.bind(this);

Expand All @@ -59,6 +75,7 @@ export default class Register extends Component {
email: "",
password: "",
successful: false,
fullName: "",
message: ""
};
}
Expand All @@ -69,6 +86,13 @@ export default class Register extends Component {
});
}

// onChangeFullname //
onChangeFullname(e) {
this.setState({
fullName: e.target.value
});
}

onChangeEmail(e) {
this.setState({
email: e.target.value
Expand All @@ -95,7 +119,8 @@ export default class Register extends Component {
AuthService.register(
this.state.username,
this.state.email,
this.state.password
this.state.password,
this.state.fullName
).then(
response => {
this.setState({
Expand Down Expand Up @@ -151,6 +176,23 @@ export default class Register extends Component {
/>
</div>



<div className="form-group">
<label htmlFor="fullname">fullname</label>
<Input
type="text"
className="form-control"
name="fullname"
value={this.state.fullname}
onChange={this.onChangeFullname}
validations={[required, vfullname]}
/>
</div>




<div className="form-group">
<label htmlFor="email">Email</label>
<Input
Expand Down

0 comments on commit 88a2ef1

Please sign in to comment.