From b783ee8c0ba7fe23bbdc65b5faa62a29b56851ee Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Mon, 4 Jun 2018 15:45:31 +0200 Subject: [PATCH] Ignore already exists error --- .../src/containers/RejectUsernameDialog.js | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/client/coral-admin/src/containers/RejectUsernameDialog.js b/client/coral-admin/src/containers/RejectUsernameDialog.js index d2a2e61fa..90e329812 100644 --- a/client/coral-admin/src/containers/RejectUsernameDialog.js +++ b/client/coral-admin/src/containers/RejectUsernameDialog.js @@ -8,7 +8,9 @@ import { withRejectUsername, withPostFlag, } from 'coral-framework/graphql/mutations'; +import { notify } from 'coral-framework/actions/notification'; import { compose } from 'react-apollo'; +import { getErrorMessages } from 'coral-framework/utils'; class RejectUsernameDialogContainer extends Component { rejectUsername = async ({ reason, message }) => { @@ -19,12 +21,24 @@ class RejectUsernameDialogContainer extends Component { userId, } = this.props; - await postFlag({ - item_id: userId, - item_type: 'USERS', - reason, - message, - }); + // First flag the user. + try { + await postFlag({ + item_id: userId, + item_type: 'USERS', + reason, + message, + }); + } catch (error) { + // Ignore already exists error, otherwise show error. + if ( + error.errors && + (error.errors.length !== 1 || + error.errors[0].translation_key !== 'ALREADY_EXISTS') + ) { + notify('error', getErrorMessages(error)); + } + } await rejectUsername({ id: userId }); hideRejectUsernameDialog(); @@ -62,6 +76,7 @@ const mapDispatchToProps = dispatch => ({ ...bindActionCreators( { hideRejectUsernameDialog, + notify, }, dispatch ), @@ -70,5 +85,5 @@ const mapDispatchToProps = dispatch => ({ export default compose( connect(mapStateToProps, mapDispatchToProps), withRejectUsername, - withPostFlag + withPostFlag({ notifyOnError: false }) )(RejectUsernameDialogContainer);