import React from 'react'; import { useTranslation } from 'next-i18next'; import PropTypes from 'prop-types'; import AdminNotificationContainer from '~/client/services/AdminNotificationContainer'; import { toastSuccess, toastError } from '~/client/util/toastr'; import loggerFactory from '~/utils/logger'; import { withUnstatedContainers } from '../../UnstatedUtils'; 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); this.onClickDeleteBtn = this.onClickDeleteBtn.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_settings.add_notification_pattern')); this.setState({ pathPattern: '', channel: '' }); } catch (err) { toastError(err); logger.error(err); } } async onClickDeleteBtn(notificationIdForDelete) { const { t, adminNotificationContainer } = this.props; try { const deletedNotificaton = await adminNotificationContainer.deleteUserTriggerNotificationPattern(notificationIdForDelete); toastSuccess(t('notification_settings.delete_notification_pattern', { path: deletedNotificaton.pathPattern })); } catch (err) { toastError(err); logger.error(err); } } render() { const { t, adminNotificationContainer } = this.props; const userNotifications = adminNotificationContainer.state.userNotifications || []; return (

{t('notification_settings.user_trigger_notification_header')}

{userNotifications.length > 0 && userNotifications.map((notification) => { return ; })}
{t('notification_settings.pattern')} {t('notification_settings.channel')}
{ this.changePathPattern(e.target.value) }} />

{/* eslint-disable-next-line react/no-danger */}

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

{/* eslint-disable-next-line react/no-danger */}

); } } UserTriggerNotification.propTypes = { t: PropTypes.func.isRequired, // i18next adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired, }; const UserTriggerNotificationWrapperFC = (props) => { const { t } = useTranslation('admin'); return ; }; const UserTriggerNotificationWrapper = withUnstatedContainers(UserTriggerNotificationWrapperFC, [AdminNotificationContainer]); export default UserTriggerNotificationWrapper;