import React from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import loggerFactory from '@alias/logger'; import { createSubscribedElement } from '../../UnstatedUtils'; import { toastSuccess, toastError } from '../../../util/apiNotification'; import AppContainer from '../../../services/AppContainer'; import AdminNotificationContainer from '../../../services/AdminNotificationContainer'; import UserNotificationRow from './UserNotificationRow'; const logger = loggerFactory('growi:slackAppConfiguration'); class UserTriggerNotification extends React.Component { constructor(props) { super(props); this.state = { pathPattern: '', channel: '', }; this.changePathPattern = this.changePathPattern.bind(this); this.changeChannel = this.changeChannel.bind(this); this.validateForm = this.validateForm.bind(this); this.onClickSubmit = this.onClickSubmit.bind(this); } /** * Change pathPattern */ changePathPattern(pathPattern) { this.setState({ pathPattern }); } /** * Change channel */ changeChannel(channel) { this.setState({ channel }); } validateForm() { return this.state.pathPattern !== '' && this.state.channel !== ''; } async onClickSubmit() { const { t, adminNotificationContainer } = this.props; try { await adminNotificationContainer.addNotificationPattern(this.state.pathPattern, this.state.channel); toastSuccess(t('notification_setting.add_notification_pattern')); this.setState({ pathPattern: '', channel: '' }); } catch (err) { toastError(err); logger.error(err); } } // TODO GW-788 i18n render() { const { t, adminNotificationContainer } = this.props; return (

Default Notification Settings for Patterns

{adminNotificationContainer.state.userNotifications.map((notification) => { return ; }) }
Pattern Channel Operation
{ this.changePathPattern(e.target.value) }} />

Path name of wiki. Pattern expression with * can be used.

{ this.changeChannel(e.target.value) }} />

Slack channel name. Without #.

); } } const UserTriggerNotificationWrapper = (props) => { return createSubscribedElement(UserTriggerNotification, props, [AppContainer, AdminNotificationContainer]); }; UserTriggerNotification.propTypes = { t: PropTypes.func.isRequired, // i18next appContainer: PropTypes.instanceOf(AppContainer).isRequired, adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired, }; export default withTranslation()(UserTriggerNotificationWrapper);