Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
feat: add error message for login and register
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-Torrent committed Aug 20, 2021
1 parent cf86201 commit 89a47bc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/actions/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
SIGN_UP_ERROR,
SIGN_IN_ERROR,
GET_CURRENT_MEMBER_ERROR,
SIGN_IN_INVALID,
SIGN_UP_DUPLICATE,
} from '../types/member';
import notifier from '../utils/notifier';

Expand All @@ -23,7 +25,10 @@ export const signIn = async (payload) => {
await Api.signIn(payload);
notifier.success({ code: SIGN_IN_SUCCESS });
} catch (error) {
notifier.error({ code: SIGN_IN_ERROR, error });
if(error.message === 'Not Found')
notifier.error({ code: SIGN_IN_INVALID, error });
else
notifier.error({ code: SIGN_IN_ERROR, error });
}
};

Expand All @@ -33,6 +38,9 @@ export const signUp = async (payload) => {
await Api.signUp(payload);
notifier.success({ code: SIGN_UP_SUCCESS });
} catch (error) {
notifier.error({ code: SIGN_UP_ERROR, error });
if(error.message === 'Conflict')
notifier.error({ code: SIGN_UP_DUPLICATE, error });
else
notifier.error({ code: SIGN_UP_ERROR, error });
}
};
2 changes: 2 additions & 0 deletions src/config/messages.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
export const SIGN_IN_ERROR_MESSAGE = 'There was an error while signing in.';
export const SIGN_IN_INVALID_MESSAGE = 'This user doesn\'t exist. Please register.';
export const SIGN_IN_SUCCESS_MESSAGE =
'You successfully signed in. You will receive an email.';
export const SIGN_UP_ERROR_MESSAGE = 'There was an error signing up.';
export const SIGN_UP_DUPLICATE_MESSAGE = 'This user exist. Please sign in.';
export const SIGN_UP_SUCCESS_MESSAGE =
'You successfully signed up. You will receive an email.';
export const EMAIL_ERROR = 'Please enter a valid email address';
Expand Down
2 changes: 1 addition & 1 deletion src/env.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"API_HOST": false,
"GRAASP_COMPOSE_HOST": false,
"SHOW_NOTIFICATIONS": false
"SHOW_NOTIFICATIONS": true
}
2 changes: 2 additions & 0 deletions src/types/member.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const FLAG_SIGNING_OUT = 'FLAG_SIGNING_OUT';
export const FLAG_SIGNING_UP = 'FLAG_SIGNING_UP';
export const SIGN_OUT_SUCCESS = 'SIGN_OUT_SUCCESS';
export const SIGN_IN_SUCCESS = 'SIGN_IN_SUCCESS';
export const SIGN_IN_INVALID = 'SIGN_IN_INVALID';
export const SIGN_IN_ERROR = 'SIGN_IN_ERROR';
export const SIGN_UP_DUPLICATE = 'SIGN_UP_DUPLICATE';
export const SIGN_UP_SUCCESS = 'SIGN_UP_SUCCESS';
export const SIGN_UP_ERROR = 'SIGN_UP_ERROR';
export const SIGN_OUT_ERROR = 'SIGN_OUT_ERROR';
12 changes: 12 additions & 0 deletions src/utils/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { SHOW_NOTIFICATIONS } from '../config/constants';
import i18n from '../config/i18n';
import {
SIGN_IN_ERROR_MESSAGE,
SIGN_IN_INVALID_MESSAGE,
SIGN_IN_SUCCESS_MESSAGE,
SIGN_UP_DUPLICATE_MESSAGE,
SIGN_UP_ERROR_MESSAGE,
SIGN_UP_SUCCESS_MESSAGE,
} from '../config/messages';
import {
SIGN_IN_ERROR,
SIGN_IN_INVALID,
SIGN_IN_SUCCESS,
SIGN_UP_DUPLICATE,
SIGN_UP_ERROR,
SIGN_UP_SUCCESS,
} from '../types/member';
Expand All @@ -22,10 +26,18 @@ const notifier = {

let message = '';
switch (code) {
case SIGN_IN_INVALID: {
message = SIGN_IN_INVALID_MESSAGE;
break;
}
case SIGN_IN_ERROR: {
message = SIGN_IN_ERROR_MESSAGE;
break;
}
case SIGN_UP_DUPLICATE: {
message = SIGN_UP_DUPLICATE_MESSAGE;
break;
}
case SIGN_UP_ERROR: {
message = SIGN_UP_ERROR_MESSAGE;
break;
Expand Down

0 comments on commit 89a47bc

Please sign in to comment.