Fully working offtopic

This commit is contained in:
Belen Curcio
2017-05-17 11:19:06 -03:00
parent 9dc0693530
commit b2f1707f17
6 changed files with 29 additions and 5 deletions
@@ -170,7 +170,15 @@ const extension = {
parent_id,
asset_id,
action_summaries: [],
tags,
tags: tags.map(tag => ({
tag: {
name: tag,
created_at: new Date().toISOString(),
},
assigned_by: {
id: auth.toJS().user.id,
},
})),
status: null,
id: 'pending'
}
@@ -168,4 +168,3 @@ export const withStopIgnoringUser = withMutation(
});
}}),
});
@@ -7,3 +7,7 @@ export const removeTag = idx => ({
type: 'REMOVE_TAG',
idx
});
export const clearTags = () => ({
type: 'CLEAR_TAGS',
});
@@ -1,2 +1,3 @@
export const ADD_TAG = 'ADD_TAG';
export const REMOVE_TAG = 'REMOVE_TAG';
export const CLEAR_TAGS = 'CLEAR_TAGS';
+3 -1
View File
@@ -1,4 +1,4 @@
import {ADD_TAG, REMOVE_TAG} from './constants';
import {ADD_TAG, REMOVE_TAG, CLEAR_TAGS} from './constants';
const initialState = {
tags: []
@@ -19,6 +19,8 @@ export default function commentBox (state = initialState, action) {
...state.tags.slice(action.idx + 1)
]
};
case CLEAR_TAGS :
return initialState;
default :
return state;
}
@@ -1,13 +1,23 @@
import React from 'react';
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {addTag, removeTag} from 'coral-plugin-commentbox/actions';
import {addTag, removeTag, clearTags} from 'coral-plugin-commentbox/actions';
import styles from './styles.css';
class OffTopicCheckbox extends React.Component {
label = 'OFF_TOPIC';
componentDidMount() {
this.clearTagsHook = this.props.registerHook('postSubmit', (data) => {
this.props.clearTags();
});
}
componentWillUnmount() {
this.props.unregisterHook(this.clearTagsHook);
}
handleChange = (e) => {
if (e.target.checked) {
this.props.addTag(this.label)
@@ -33,6 +43,6 @@ class OffTopicCheckbox extends React.Component {
const mapStateToProps = ({commentBox}) => ({commentBox});
const mapDispatchToProps = dispatch =>
bindActionCreators({addTag, removeTag}, dispatch);
bindActionCreators({addTag, removeTag, clearTags}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(OffTopicCheckbox);