import React from 'react'; import axios from 'axios'; import { updateModuleSetting } from '../service/dashboardService.js'; import { EmbedBuilder } from '../common/Embed'; import MessageSetting from './MessageSetting.jsx'; import ModuleSettings from '../common/ModuleSettings.jsx'; import SettingCheckbox from '../common/SettingCheckbox.jsx'; import RichSettingSelect from '../common/RichSettingSelect.jsx'; import Variables from '../common/Variables.jsx'; import Loader from './../common/Loader.jsx'; import Help from '../common/Help.jsx'; export default class Welcome extends ModuleSettings { state = { welcome: {}, channels: [], roles: [], isLoading: true, type: 'MESSAGE', }; async componentWillMount() { try { let response = await axios.get(`/api/modules/${this.props.match.params.id}/welcome`); this.setState({ welcome: response.data.welcome, channels: response.data.channels, roles: response.data.roles, isLoading: false, }); } catch (e) { this.setState({ error: 'Failed to get data, try again later' }); } } handleChannel = (selectedOption) => { let welcome = this.state.welcome; welcome.channel = selectedOption.value || false; this.setState({ welcome }); } handleType = (event) => { const { welcome } = this.state; welcome.type = event.target.value; updateModuleSetting(this.props.data.module, 'type', event.target.value, 'type'); this.setState({ welcome }); } toggleDM = (props, isEnabled) => { const { welcome } = this.state; welcome.sendDM = !!isEnabled; this.setState({ welcome }); } saveEmbed = async (embed) => { let { welcome } = this.state; welcome.embed = embed; try { updateModuleSetting(this.props.data.module, 'embed', embed, 'embed'); await this.setState({ welcome }); } catch (err) { return _showError(err); } } render() { if (this.state.isLoading) { return ; } const module = this.props.data.module; const welcome = this.state.welcome; const channels = this.state.channels.filter(c => c.type === 0); const roles = this.state.roles; const channelOptions = channels.map(c => ({ value: c.id, label: c.name })); const defaultChannel = channels.find(c => c.id === welcome.channel); return (

Welcome {this.ModuleToggle}

{!welcome.sendDM && ( )} {welcome.type === 'MESSAGE' && ( )} {welcome.type === 'EMBED' && ( )}

Variables

You can use these variables in the message boxes below.

); } }