import React from 'react'; import SettingSelector from './SettingSelector.jsx'; import SettingCheckbox from '../common/SettingCheckbox.jsx'; import RichSettingSelect from '../common/RichSettingSelect.jsx'; import RichMultiSelect from '../common/RichMultiSelect.jsx'; import RichNumber from '../common/RichNumber.jsx'; import { updateModuleSetting } from '../service/dashboardService.js'; export default class SettingsTab extends React.Component { state = { automod: {}, channels: [], ignoredChannels: [], roles: [], ignoredRoles: [], selectedValue: null, channel: false, } componentDidMount() { this.updateStateWithProps(this.props); } componentWillReceiveProps(props) { this.updateStateWithProps(props); } updateStateWithProps(props) { let { automod, channels, roles } = props; automod = automod || {}; this.setState({ automod, channels: channels || false, channel: automod.channel || false, ignoredChannels: automod.ignoredChannels || [], roles: roles || false, ignoredRoles: automod.ignoredRoles || [], }); } handleLogChannel = (selectedOption) => { this.setState({ channel: selectedOption.value || false }); } handleIgnoredChannels = (props, selectedOptions) => { const ignoredChannels = selectedOptions.map(o => ({ id: o.value, name: o.label })); updateModuleSetting(props.module, 'ignoredChannels', ignoredChannels, 'Ignored Channels'); this.setState({ ignoredChannels }); } handleAllowedRoles = (props, selectedOptions) => { const ignoredRoles = selectedOptions.map(o => ({ id: o.value, name: o.label })); updateModuleSetting(props.module, 'ignoredRoles', ignoredRoles, 'Allowed Roles'); this.setState({ ignoredRoles }); } getDefaultValue(setting) { let value = false; const options = [ { value: 'delete', label: 'Delete' }, { value: 'warn', label: 'Warn' }, { value: 'automute', label: 'Auto Mute' }, { value: 'instantban', label: 'Instant Ban' }, ]; if (typeof this.props.automod[setting] === 'object') { value = options.filter(o => this.props.automod[setting][o.value]); } return value; } updateNumber = (type, friendlyName, number) => { updateModuleSetting(this.props.data.module, type, number, friendlyName); } render() { const { automod } = this.state; const module = this.props.data.module; const roles = this.state.roles; const channels = this.state.channels.filter(c => (c.type === 0 || c.type === 4)); const defaultChannel = channels.find(c => c.id === this.state.channel); const channelOptions = channels.map(c => ({ value: c.id, label: c.name })); const ignoredChannels = channels.filter(c => this.state.ignoredChannels.find(i => i.id === c.id)); const ignoredRoles = roles.filter(r => this.state.ignoredRoles.find(i => i.id === r.id)); const roleOptions = roles.map(r => ({ value: r.id, label: r.name })); return (
{/*

Settings

*/}

Log Channel

Filter Options

{/* */}

Ignored Channels

Message sent in these channels will not trigger Automod.

Allowed Roles

Members in these roles will not trigger Automod.

); } }