From 559973de5ac76fb882016202b33e4b5ffdc3e32d Mon Sep 17 00:00:00 2001 From: Hansi Xu Date: Tue, 5 Apr 2022 21:15:39 -0400 Subject: [PATCH 1/3] Create signup.js --- .../client/src/components/SIgnup.js | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 sports-matcher/client/src/components/SIgnup.js diff --git a/sports-matcher/client/src/components/SIgnup.js b/sports-matcher/client/src/components/SIgnup.js new file mode 100644 index 0000000..08a6cac --- /dev/null +++ b/sports-matcher/client/src/components/SIgnup.js @@ -0,0 +1,82 @@ +import React from "react"; +import { Button, Card, Form } from "react-bootstrap"; +import { apiClient } from "../utils/httpClients"; +import { guard } from "../utils/routing"; + +export default class Signup extends React.Component { + constructor(props) { + super(props); + this.state = { + user: null, + alertShow: false, + alertKey: null, + alertMsg: null + } + this.state.user = { + email: null, + firstName: null, + lastName: null, + phone: null, + password: null + } + } + + async registerUser() { + const registerResponse = await apiClient.post("/user", this.state); + if (registerResponse.status === 200) { + this.warnUser() + } + } + + setUserState(event) { + newUser = this.state.user; + newUser[event.target.controlId] = event.target.value + this.setState({user: newUser}) + } + + warnUser(msg, key) { + this.setState({alertMsg: msg}) + this.setState({show: true}) + } + + render() { + return ( +
+ + {this.state.alertMsg} + + + + Login + Welcome to Sports Matcher! +
+ + First name + + + + Last name + + + + E-mail + + + + Phone number + + + + Password + + + +
+
+
+
+ ); + } +} From d86570996e10c13f591e995902d5a0c06d481b25 Mon Sep 17 00:00:00 2001 From: Hansi Xu Date: Tue, 5 Apr 2022 21:39:48 -0400 Subject: [PATCH 2/3] updating the signup page --- sports-matcher/client/src/components/SIgnup.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sports-matcher/client/src/components/SIgnup.js b/sports-matcher/client/src/components/SIgnup.js index 08a6cac..c603579 100644 --- a/sports-matcher/client/src/components/SIgnup.js +++ b/sports-matcher/client/src/components/SIgnup.js @@ -22,9 +22,15 @@ export default class Signup extends React.Component { } async registerUser() { - const registerResponse = await apiClient.post("/user", this.state); - if (registerResponse.status === 200) { - this.warnUser() + const res = await apiClient.post("/user", this.state); + if (res.status === 200) { + this.warnUser("You are successfully signed up!", "success") + } else if (res === 409) { + this.warnUser("This user already exists. Try logging in instead.", "danger") + } else if (res === 400) { + this.warnUser("Missing required fields.", "danger") + } else { + this.warnUser("Internal server error. Please try again later.", "danger") } } From 5a49a1e4f8a5d12bb929ed36c623a1ab27652244 Mon Sep 17 00:00:00 2001 From: Hansi Xu Date: Tue, 5 Apr 2022 21:48:08 -0400 Subject: [PATCH 3/3] Moved signup to pages --- sports-matcher/client/src/{components => pages}/SIgnup.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sports-matcher/client/src/{components => pages}/SIgnup.js (100%) diff --git a/sports-matcher/client/src/components/SIgnup.js b/sports-matcher/client/src/pages/SIgnup.js similarity index 100% rename from sports-matcher/client/src/components/SIgnup.js rename to sports-matcher/client/src/pages/SIgnup.js