diff --git a/client/talk-plugin-flags/components/FlagButton.js b/client/talk-plugin-flags/components/FlagButton.js index b8a24392d..64841a893 100644 --- a/client/talk-plugin-flags/components/FlagButton.js +++ b/client/talk-plugin-flags/components/FlagButton.js @@ -9,7 +9,7 @@ import cn from 'classnames'; import styles from './styles.css'; import * as REASONS from '../helpers/flagReasons'; -import { getErrorMessages } from 'coral-framework/utils'; +import { getErrorMessages, forEachError } from 'coral-framework/utils'; const name = 'talk-plugin-flags'; @@ -20,7 +20,6 @@ export default class FlagButton extends Component { reason: '', message: '', step: 0, - posted: false, localPost: null, }; @@ -63,7 +62,20 @@ export default class FlagButton extends Component { onPopupContinue = () => { const { postFlag, postDontAgree, id, author_id } = this.props; - const { itemType, reason, step, posted, message } = this.state; + const { itemType, reason, step, message } = this.state; + + switch (step) { + case 0: + if (!itemType) { + return; + } + break; + case 1: + if (!reason) { + return; + } + break; + } // Proceed to the next step or close the menu if we've reached the end if (step + 1 >= this.props.getPopupMenu.length) { @@ -73,9 +85,7 @@ export default class FlagButton extends Component { } // If itemType and reason are both set, post the action - if (itemType && reason && !posted) { - this.setState({ posted: true }); - + if (step === 1) { let item_id; switch (itemType) { case 'COMMENTS': @@ -113,9 +123,13 @@ export default class FlagButton extends Component { this.setState({ localPost: data.createFlag.flag.id }); } }) - .catch(err => { - this.props.notify('error', getErrorMessages(err)); - console.error(err); + .catch(errors => { + forEachError(errors, ({ error, msg }) => { + if (error.translation_key === 'ALREADY_EXISTS') { + msg = t('already_flagged_username'); + } + this.props.notify('error', msg); + }); }); } } diff --git a/graph/resolvers/root_mutation.js b/graph/resolvers/root_mutation.js index 3a646b3d8..8a638f589 100644 --- a/graph/resolvers/root_mutation.js +++ b/graph/resolvers/root_mutation.js @@ -23,7 +23,7 @@ const RootMutation = { { flag: { item_id, item_type, reason, message } }, { mutators: { Action } } ) => ({ - flag: Action.create({ + flag: await Action.create({ item_id, item_type, action_type: 'FLAG', diff --git a/locales/en.yml b/locales/en.yml index 39cd3f0d9..e4a1cb160 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -336,6 +336,7 @@ en: no_agree_comment: "I don't agree with this comment" no_like_bio: "I don't like this bio" no_like_username: "I don't like this username" + already_flagged_username: "You have already flagged this username." other: Other permalink: Share personal_info: "This comment reveals personally identifiable information"