Simplify Configure

This commit is contained in:
Chi Vinh Le
2017-10-07 00:31:44 +07:00
parent eae5b85d1a
commit 5fbabcaa1b
2 changed files with 14 additions and 75 deletions
@@ -19,33 +19,21 @@ export default class Configure extends Component {
this.setState({activeSection});
}
getSection (section) {
let SectionComponent;
getSectionComponent(section) {
switch(section){
case 'stream':
SectionComponent = StreamSettings;
break;
return StreamSettings;
case 'moderation':
SectionComponent = ModerationSettings;
break;
return ModerationSettings;
case 'tech':
SectionComponent = TechSettings;
return TechSettings;
}
return (
<div className={styles.settingsSection}>
<SectionComponent
data={this.props.data}
root={this.props.root}
settings={this.props.settings}
/>
</div>
);
throw new Error(`Unknown section ${section}`);
}
render () {
const {activeSection} = this.state;
const section = this.getSection(activeSection);
const SectionComponent = this.getSectionComponent(activeSection);
const {auth: {user}, canSave, savePending} = this.props;
if (!can(user, 'UPDATE_CONFIG')) {
@@ -92,7 +80,13 @@ export default class Configure extends Component {
</div>
<div className={styles.mainContent}>
{section}
<div className={styles.settingsSection}>
<SectionComponent
data={this.props.data}
root={this.props.root}
settings={this.props.settings}
/>
</div>
</div>
</div>
);
@@ -101,9 +95,6 @@ export default class Configure extends Component {
Configure.propTypes = {
notify: PropTypes.func.isRequired,
updateWordlist: PropTypes.func.isRequired,
updateSettings: PropTypes.func.isRequired,
errors: PropTypes.object.isRequired,
savePending: PropTypes.func.isRequired,
auth: PropTypes.object.isRequired,
data: PropTypes.object.isRequired,
@@ -12,34 +12,12 @@ import {getErrorMessages, getDefinitionName} from 'coral-framework/utils';
import StreamSettings from './StreamSettings';
import TechSettings from './TechSettings';
import ModerationSettings from './ModerationSettings';
import {
updatePending,
clearPending,
} from '../../../actions/configure';
import {clearPending} from '../../../actions/configure';
import Configure from '../components/Configure';
class ConfigureContainer extends Component {
updateWordlist = (listName, list) => {
this.props.updatePending({updater: {
wordlist: {$apply: (wordlist) => {
const changeSet = {[listName]: list};
if (!wordlist) {
return changeSet;
}
return {
...wordlist,
...changeSet,
};
}},
}});
};
updateSettings = (settings, {setError = {}} = {}) => {
this.props.updatePending({updater: {$merge: settings}, errorUpdater: {$merge: setError}});
};
savePending = async () => {
try {
await this.props.updateSettings(this.props.pending);
@@ -59,9 +37,6 @@ class ConfigureContainer extends Component {
return <Configure
notify={this.props.notify}
updateWordlist={this.updateWordlist}
updateSettings={this.updateSettings}
errors={this.props.errors}
auth={this.props.auth}
data={this.props.data}
root={this.props.root}
@@ -75,29 +50,6 @@ class ConfigureContainer extends Component {
const withConfigureQuery = withQuery(gql`
query TalkAdmin_Configure {
settings {
moderation
requireEmailConfirmation
infoBoxEnable
infoBoxContent
questionBoxEnable
questionBoxContent
premodLinksEnable
questionBoxIcon
autoCloseStream
customCssUrl
closedTimeout
closedMessage
editCommentWindowLength
charCountEnable
charCount
organizationName
wordlist {
suspect
banned
}
domains {
whitelist
}
...${getDefinitionName(StreamSettings.fragments.settings)}
...${getDefinitionName(TechSettings.fragments.settings)}
...${getDefinitionName(ModerationSettings.fragments.settings)}
@@ -122,13 +74,11 @@ const mapStateToProps = (state) => ({
auth: state.auth,
pending: state.configure.pending,
canSave: state.configure.canSave,
errors: state.configure.errors,
});
const mapDispatchToProps = (dispatch) =>
bindActionCreators({
notify,
updatePending,
clearPending,
}, dispatch);
@@ -139,14 +89,12 @@ export default compose(
)(ConfigureContainer);
ConfigureContainer.propTypes = {
updatePending: PropTypes.func.isRequired,
updateSettings: PropTypes.func.isRequired,
clearPending: PropTypes.func.isRequired,
notify: PropTypes.func.isRequired,
auth: PropTypes.object.isRequired,
data: PropTypes.object.isRequired,
root: PropTypes.object.isRequired,
errors: PropTypes.object.isRequired,
canSave: PropTypes.bool.isRequired,
pending: PropTypes.object.isRequired,
};