Don't require notify property

This commit is contained in:
Chi Vinh Le
2018-01-23 20:27:46 +01:00
parent 59cdc9fd5d
commit d15694041a
18 changed files with 13 additions and 101 deletions
@@ -10,7 +10,6 @@ import {
} from 'coral-framework/graphql/mutations';
import { compose } from 'react-apollo';
import t from 'coral-framework/services/i18n';
import { notify } from 'coral-framework/actions/notification';
class BanUserDialogContainer extends Component {
banUser = async () => {
@@ -72,7 +71,6 @@ const mapDispatchToProps = dispatch => ({
...bindActionCreators(
{
hideBanUserDialog,
notify,
},
dispatch
),
@@ -26,7 +26,6 @@ import UserDetailComment from './UserDetailComment';
import update from 'immutability-helper';
import { showBanUserDialog } from 'actions/banUserDialog';
import { showSuspendUserDialog } from 'actions/suspendUserDialog';
import { notify } from 'coral-framework/actions/notification';
const commentConnectionFragment = gql`
fragment CoralAdmin_UserDetail_CommentConnection on CommentConnection {
@@ -272,7 +271,6 @@ const mapDispatchToProps = dispatch => ({
viewUserDetail,
hideUserDetail,
toggleSelectAllCommentInUserDetail,
notify,
},
dispatch
),
@@ -16,7 +16,6 @@ import { appendNewNodes } from 'plugin-api/beta/client/utils';
import update from 'immutability-helper';
import { Spinner } from 'coral-ui';
import withQuery from 'coral-framework/hocs/withQuery';
import { notify } from 'coral-framework/actions/notification';
class PeopleContainer extends React.Component {
timer = null;
@@ -132,7 +131,6 @@ const mapDispatchToProps = dispatch =>
viewUserDetail,
showSuspendUserDialog,
showBanUserDialog,
notify,
},
dispatch
);
@@ -4,7 +4,6 @@ import { hideRejectUsernameDialog } from '../../../actions/community';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { compose } from 'react-apollo';
import { notify } from 'coral-framework/actions/notification';
const mapStateToProps = state => ({
user: state.community.user,
@@ -15,7 +14,6 @@ const mapDispatchToProps = dispatch =>
bindActionCreators(
{
handleClose: hideRejectUsernameDialog,
notify,
},
dispatch
);
@@ -12,7 +12,6 @@ import TechSettings from './TechSettings';
import ModerationSettings from './ModerationSettings';
import { clearPending, setActiveSection } from '../../../actions/configure';
import Configure from '../components/Configure';
import { notify } from 'coral-framework/actions/notification';
class ConfigureContainer extends Component {
savePending = async () => {
@@ -83,7 +82,6 @@ const mapDispatchToProps = dispatch =>
{
clearPending,
setActiveSection,
notify,
},
dispatch
);
@@ -7,9 +7,6 @@ import {
withUpdateAssetStatus,
withCloseAsset,
} from 'coral-framework/graphql/mutations';
import { notify } from 'coral-framework/actions/notification';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
class AssetStatusInfoContainer extends React.Component {
openAsset = () =>
@@ -45,16 +42,7 @@ const withAssetStatusInfoFragments = withFragments({
`,
});
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
notify,
},
dispatch
);
const enhance = compose(
connect(null, mapDispatchToProps),
withAssetStatusInfoFragments,
withUpdateAssetStatus,
withCloseAsset
@@ -8,7 +8,6 @@ import { withUpdateAssetSettings } from 'coral-framework/graphql/mutations';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { clearPending, updatePending } from '../../../actions/configure';
import { notify } from 'coral-framework/actions/notification';
const slots = ['streamSettings'];
@@ -129,7 +128,6 @@ const mapDispatchToProps = dispatch =>
{
clearPending,
updatePending,
notify,
},
dispatch
);
@@ -1,18 +1,5 @@
import { compose } from 'react-apollo';
import { withChangeUsername } from 'coral-framework/graphql/mutations';
import ChangeUsername from '../components/ChangeUsername';
import { notify } from 'coral-framework/actions/notification';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
notify,
},
dispatch
);
export default compose(connect(null, mapDispatchToProps), withChangeUsername)(
ChangeUsername
);
export default compose(withChangeUsername)(ChangeUsername);
+3 -9
View File
@@ -13,6 +13,7 @@ import PropTypes from 'prop-types';
import t from 'coral-framework/services/i18n';
import hoistStatics from 'recompose/hoistStatics';
import union from 'lodash/union';
import { notify } from 'coral-framework/actions/notification';
class ResponseErrors extends Error {
constructor(errors) {
@@ -55,14 +56,7 @@ const createHOC = (document, config, { notifyOnError = true }) =>
}
notifyErrors(messages) {
if (this.props.notify) {
this.props.notify('error', messages);
} else {
console.error(
'`notifyOnError` is set to `true` but missing `notify` property'
);
console.error(messages);
}
this.context.store.dispatch(notify('error', messages));
}
resolveDocument(documentOrCallback) {
@@ -240,7 +234,7 @@ const createHOC = (document, config, { notifyOnError = true }) =>
*
* The returned HOC accepts a settings object with the following properties:
* notifyOnError: show a notification to the user when an error occured.
* Defaults to true, requires the `notify` action to be mounted.
* Defaults to true.
*/
export default (document, config = {}) => settingsOrComponent => {
if (typeof settingsOrComponent === 'function') {
+4 -9
View File
@@ -10,6 +10,7 @@ import hoistStatics from 'recompose/hoistStatics';
import { getOperationName } from 'apollo-client/queries/getFromAST';
import throttle from 'lodash/throttle';
import get from 'lodash/get';
import { notify } from 'coral-framework/actions/notification';
const withSkipOnErrors = reducer => (prev, action, ...rest) => {
if (
@@ -49,6 +50,7 @@ const createHOC = (document, config, { notifyOnError = true }) =>
eventEmitter: PropTypes.object,
graphql: PropTypes.object,
client: PropTypes.object,
store: PropTypes.object,
};
static propTypes = {
@@ -169,14 +171,7 @@ const createHOC = (document, config, { notifyOnError = true }) =>
};
notifyErrors(messages) {
if (this.props.notify) {
this.props.notify('error', messages);
} else {
console.error(
'`notifyOnError` is set to `true` but missing `notify` property'
);
console.error(messages);
}
this.context.store.dispatch(notify('error', messages));
}
nextData(data) {
@@ -349,7 +344,7 @@ const createHOC = (document, config, { notifyOnError = true }) =>
*
* The returned HOC accepts a settings object with the following properties:
* notifyOnError: show a notification to the user when an error occured.
* Defaults to true, requires the `notify` action to be mounted.
* Defaults to true.
*/
export default (document, config = {}) => settingsOrComponent => {
if (typeof settingsOrComponent === 'function') {
+1 -6
View File
@@ -1,12 +1,10 @@
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { compose, gql } from 'react-apollo';
import { getDisplayName } from 'coral-framework/helpers/hoc';
import { capitalize } from 'coral-framework/helpers/strings';
import { withAddTag, withRemoveTag } from 'coral-framework/graphql/mutations';
import withFragments from 'coral-framework/hocs/withFragments';
import { notify } from 'coral-framework/actions/notification';
import { isTagged } from 'coral-framework/utils';
import hoistStatics from 'recompose/hoistStatics';
import { getDefinitionName } from '../utils';
@@ -112,9 +110,6 @@ export default (tag, options = {}) =>
user: state.auth.user,
});
const mapDispatchToProps = dispatch =>
bindActionCreators({ notify }, dispatch);
const enhance = compose(
withFragments({
...fragments,
@@ -144,7 +139,7 @@ export default (tag, options = {}) =>
}),
withAddTag,
withRemoveTag,
connect(mapStateToProps, mapDispatchToProps)
connect(mapStateToProps, null)
);
WithTags.displayName = `WithTags(${getDisplayName(WrappedComponent)})`;
@@ -64,7 +64,6 @@ export default class ModTag extends React.Component {
ModTag.propTypes = {
alreadyTagged: PropTypes.bool,
deleteTag: PropTypes.func,
notify: PropTypes.func,
openFeaturedDialog: PropTypes.func,
comment: PropTypes.object,
asset: PropTypes.object,
@@ -3,12 +3,10 @@ import { bindActionCreators } from 'redux';
import ModActionButton from '../components/ModActionButton';
import { withTags, connect } from 'plugin-api/beta/client/hocs';
import { closeMenu } from 'plugins/talk-plugin-moderation-actions/client/actions';
import { notify } from 'plugin-api/beta/client/actions/notification';
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
notify,
closeMenu,
},
dispatch
@@ -3,12 +3,10 @@ import { withTags, connect } from 'plugin-api/beta/client/hocs';
import { gql, compose } from 'react-apollo';
import { bindActionCreators } from 'redux';
import { openFeaturedDialog } from '../actions';
import { notify } from 'plugin-api/beta/client/actions/notification';
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
notify,
openFeaturedDialog,
},
dispatch
@@ -4,7 +4,6 @@ import { compose, gql } from 'react-apollo';
import TabPane from '../components/TabPane';
import { withFragments, connect } from 'plugin-api/beta/client/hocs';
import Comment from '../containers/Comment';
import { notify } from 'plugin-api/beta/client/actions/notification';
import { viewComment } from 'coral-embed-stream/src/actions/stream';
import {
appendNewNodes,
@@ -81,7 +80,6 @@ const mapDispatchToProps = dispatch =>
bindActionCreators(
{
viewComment,
notify,
},
dispatch
);
@@ -1,9 +1,7 @@
import React from 'react';
import { compose } from 'react-apollo';
import { bindActionCreators } from 'redux';
import { notify } from 'plugin-api/beta/client/actions/notification';
import ApproveCommentAction from '../components/ApproveCommentAction';
import { connect, withSetCommentStatus } from 'plugin-api/beta/client/hocs';
import { withSetCommentStatus } from 'plugin-api/beta/client/hocs';
class ApproveCommentActionContainer extends React.Component {
approveComment = async () => {
@@ -27,17 +25,6 @@ class ApproveCommentActionContainer extends React.Component {
}
}
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
notify,
},
dispatch
);
const enhance = compose(
connect(null, mapDispatchToProps),
withSetCommentStatus
);
const enhance = compose(withSetCommentStatus);
export default enhance(ApproveCommentActionContainer);
@@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
import { compose } from 'react-apollo';
import { bindActionCreators } from 'redux';
import { closeBanDialog, closeMenu } from '../actions';
import { notify } from 'plugin-api/beta/client/actions/notification';
import {
connect,
withSetCommentStatus,
@@ -64,7 +63,6 @@ const mapStateToProps = ({ talkPluginModerationActions: state }) => ({
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
notify,
closeBanDialog,
closeMenu,
},
@@ -1,9 +1,7 @@
import React from 'react';
import { compose } from 'react-apollo';
import { bindActionCreators } from 'redux';
import { notify } from 'plugin-api/beta/client/actions/notification';
import RejectCommentAction from '../components/RejectCommentAction';
import { connect, withSetCommentStatus } from 'plugin-api/beta/client/hocs';
import { withSetCommentStatus } from 'plugin-api/beta/client/hocs';
class RejectCommentActionContainer extends React.Component {
rejectComment = async () => {
@@ -22,17 +20,6 @@ class RejectCommentActionContainer extends React.Component {
}
}
const mapDispatchToProps = dispatch =>
bindActionCreators(
{
notify,
},
dispatch
);
const enhance = compose(
connect(null, mapDispatchToProps),
withSetCommentStatus
);
const enhance = compose(withSetCommentStatus);
export default enhance(RejectCommentActionContainer);