Show notification upon failure

This commit is contained in:
Chi Vinh Le
2017-07-18 17:08:14 +07:00
parent 043d5fdcec
commit afeeffc262
+14 -7
View File
@@ -8,6 +8,7 @@ import withMutation from 'coral-framework/hocs/withMutation';
import withFragments from 'coral-framework/hocs/withFragments'; import withFragments from 'coral-framework/hocs/withFragments';
import {showSignInDialog} from 'coral-framework/actions/auth'; import {showSignInDialog} from 'coral-framework/actions/auth';
import {addNotification} from 'coral-framework/actions/notification'; import {addNotification} from 'coral-framework/actions/notification';
import {forEachError} from 'coral-framework/utils';
export default (tag) => (WrappedComponent) => { export default (tag) => (WrappedComponent) => {
if (typeof tag !== 'string') { if (typeof tag !== 'string') {
@@ -27,10 +28,10 @@ export default (tag) => (WrappedComponent) => {
} }
} }
`; `;
const isTagged = (tags) => const isTagged = (tags) =>
!!tags.filter((t) => t.tag.name === Tag.toUpperCase()).length; !!tags.filter((t) => t.tag.name === Tag.toUpperCase()).length;
const withAddTag = withMutation( const withAddTag = withMutation(
gql` gql`
mutation AddTag($id: ID!, $asset_id: ID!, $name: String!) { mutation AddTag($id: ID!, $asset_id: ID!, $name: String!) {
@@ -112,29 +113,35 @@ export default (tag) => (WrappedComponent) => {
}); });
}}), }}),
}); });
class WithTags extends React.Component { class WithTags extends React.Component {
postTag = () => { postTag = () => {
const {comment, asset} = this.props; const {comment, asset, addNotification} = this.props;
this.props.addTag({ this.props.addTag({
id: comment.id, id: comment.id,
name: Tag.toUpperCase(), name: Tag.toUpperCase(),
assetId: asset.id assetId: asset.id
})
.catch((err) => {
forEachError(err, ({msg}) => addNotification('error', msg));
}); });
} }
deleteTag = () => { deleteTag = () => {
const {comment, asset} = this.props; const {comment, asset, addNotification} = this.props;
this.props.removeTag({ this.props.removeTag({
id: comment.id, id: comment.id,
name: Tag.toUpperCase(), name: Tag.toUpperCase(),
assetId: asset.id assetId: asset.id
})
.catch((err) => {
forEachError(err, ({msg}) => addNotification('error', msg));
}); });
} }
render() { render() {
const {comment} = this.props; const {comment} = this.props;