From 09e144babce9852129736ab129ed651dd5569589 Mon Sep 17 00:00:00 2001 From: Irshad Ansari Date: Thu, 5 Mar 2020 21:17:33 +0530 Subject: [PATCH] Changed frontend according to new API error structure --- front-end/src/components/Login/index.jsx | 23 +++++++++---- front-end/src/components/Register/index.jsx | 37 +++++++++++++-------- front-end/src/services/http.js | 31 +++++++++++++++++ 3 files changed, 70 insertions(+), 21 deletions(-) diff --git a/front-end/src/components/Login/index.jsx b/front-end/src/components/Login/index.jsx index 42ee111..edfe2f4 100644 --- a/front-end/src/components/Login/index.jsx +++ b/front-end/src/components/Login/index.jsx @@ -17,7 +17,8 @@ class Login extends Component { password: "", isAuthenticated: false, exists: false, - hidden: true + errors: {}, + commonError: null }; this.handleSubmit = this.handleSubmit.bind(this); @@ -38,7 +39,10 @@ class Login extends Component { username, password }; - + this.setState({ + errors: {}, + commonError: null + }) userLogin(user) .then(res => { @@ -56,10 +60,11 @@ class Login extends Component { this.props.history.push("/", this.state); } }).catch(error => { + const len = Object.keys(error.data).length; this.setState({ - hidden: false + errors: len > 0 ? error.data : {}, + commonError: len <= 0 ? error.message : null }); - this.props.history.push("/sign-in"); }) } @@ -70,7 +75,7 @@ class Login extends Component { } render() { - const { username, password, exists, hidden } = this.state; + const { username, password, exists, commonError, errors } = this.state; const isEnabled = username && password; return ( @@ -80,9 +85,9 @@ class Login extends Component {

Sign In

- {!exists ? ( + {!exists && commonError ? ( - + { commonError } ) : null}