Skip to content

Commit bcb851b

Browse files
author
Sergiu Miclea
committed
Add styled message if login info is incorrect
Fix login page reload after incorrect login info
1 parent e4c5ed6 commit bcb851b

5 files changed

Lines changed: 50 additions & 17 deletions

File tree

src/components/ApiCaller/ApiCaller.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class ApiCaller {
7070
reject(err)
7171
}
7272

73+
let reportError = (data) => {
74+
if (data && data.error && data.error.message) {
75+
NotificationActions.notify(data.error.message, "error")
76+
}
77+
}
78+
7379
request.onload = () => {
7480
let result = {
7581
status: request.status,
@@ -82,13 +88,18 @@ class ApiCaller {
8288
resolve(result);
8389
} else {
8490
console.log(`Error Response: ${options.url}`, result.data);
85-
if (result.data && result.data.error && result.data.error.message) {
86-
NotificationActions.notify(result.data.error.message, "error")
87-
}
88-
if (result.status == 401) {
91+
92+
if (result.status === 401) {
8993
this.resetHeaders()
90-
window.location.href = "/"
94+
95+
if (window.location.pathname !== '/login') {
96+
window.location.href = '/login'
97+
reportError(result.data)
98+
}
99+
} else {
100+
reportError(result.data)
91101
}
102+
92103
reject({ status: request.status });
93104
}
94105
};

src/components/LoginPage/LoginPage.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/LoginPage/LoginPage.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
5454
background-color: rgba(221, 224, 229, 0.5);
5555
box-sizing: border-box;
5656
border-radius: 8px;
57+
.loginFailedInfo {
58+
display: flex;
59+
flex-direction: column;
60+
align-items: center;
61+
margin-top: 4px;
62+
margin-bottom: 16px;
63+
64+
.loginFailedIcon {
65+
width: 26px;
66+
height: 26px;
67+
background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIHdpZHRoPSIyNnB4IiBo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IGlkPSJMaW5lLUNvcHkiPjwvcGF0aD4gICAgICAgICAgICAgICAgPC9nPiAgICAgICAgICAgIDwvZz4gICAgICAgIDwvZz4gICAgPC9nPjwvc3ZnPg==);
68+
}
69+
70+
.loginFailedText {
71+
color: white;
72+
font-size: 12px;
73+
margin-top: 4px;
74+
}
75+
}
5776
&.noSeparator {
5877
padding-top: 16px;
5978
}

src/stores/NotificationsStore/NotificationsStore.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,6 @@ class NotificationsStore extends Reflux.Store
148148
this.setState({ notifications: notifications })
149149
}
150150

151-
onLoginFailed() {
152-
let notifications = [{
153-
message: "Login failed",
154-
type: 'error'
155-
}]
156-
this.setState({ notifications: notifications })
157-
}
158-
159151
onExecuteReplicaCompleted() {
160152
let notifications = [{
161153
message: "Executing replica",

src/stores/UserStore/UserStore.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class UserStore extends Reflux.Store
4949

5050
this.state = {
5151
currentUser: this.user,
52-
loadingState: false
52+
loadingState: false,
53+
loginFailed: false,
5354
}
5455

5556
let token = cookie.load('token')
@@ -61,7 +62,7 @@ class UserStore extends Reflux.Store
6162

6263
onLogin() {
6364
Api.setDefaultHeader('X-Auth-Token', null)
64-
this.setState({ loadingState: true })
65+
this.setState({ loadingState: true, loginFailed: false })
6566
}
6667

6768
onLoginSuccess(response) {
@@ -88,7 +89,7 @@ class UserStore extends Reflux.Store
8889
}
8990

9091
onLoginScopeSuccess(response) {
91-
this.setState({ loadingState: false })
92+
this.setState({ loadingState: false, loginFailed: false })
9293

9394
let currentUser = this.state.currentUser
9495
currentUser.id = response.data.token.user.id
@@ -115,7 +116,7 @@ class UserStore extends Reflux.Store
115116
}
116117

117118
onLoginFailed() {
118-
this.setState({ loadingState: false })
119+
this.setState({ loadingState: false, loginFailed: true })
119120
}
120121

121122
onLogout() {

0 commit comments

Comments
 (0)