import React, { useCallback, useState } from 'react'; import { useTranslation } from 'next-i18next'; import PropTypes from 'prop-types'; import urljoin from 'url-join'; // import AppContainer from '~/client/services/AppContainer'; // import { toastError } from '~/client/util/apiNotification'; import { apiv3Post, apiv3Put } from '~/client/util/apiv3-client'; import loggerFactory from '~/utils/logger'; // import { withUnstatedContainers } from '../../UnstatedUtils'; import AdminUpdateButtonRow from '../Common/AdminUpdateButtonRow'; import TriggerEventCheckBox from './TriggerEventCheckBox'; const logger = loggerFactory('growi:manageGlobalNotification'); const ManageGlobalNotification = (props) => { // constructor() { // super(); // const globalNotification = null; // // try { // // globalNotification = JSON.parse(document.getElementById('admin-global-notification-setting').getAttribute('data-global-notification')); // // } // // catch (err) { // // // toastError(err); // // logger.error(err); // // } // this.state = { // // globalNotificationId: globalNotification._id || null, // globalNotificationId: null, // // triggerPath: globalNotification.triggerPath || '', // triggerPath: '', // // notifyToType: globalNotification.__t || 'mail', // notifyToType: 'mail', // // emailToSend: globalNotification.toEmail || '', // emailToSend: '', // // slackChannelToSend: globalNotification.slackChannels || '', // slackChannelToSend: '', // // triggerEvents: new Set(globalNotification.triggerEvents), // triggerEvents: new Set(), // }; // this.submitHandler = this.submitHandler.bind(this); // } const [globalNotificationId, setGlobalNotificationId] = useState(null); const [triggerPath, setTriggerPath] = useState(''); const [notifyToType, setNotifyToType] = useState('mail'); const [emailToSend, setEmailToSend] = useState(''); const [slacChannelToSend, setSlackChannelToSend] = useState(''); const [triggerEvents, setTriggerEvents] = useState(new Set()); const [retrieveError] = useState(null); // onChangeTriggerPath(inputValue) { // this.setState({ triggerPath: inputValue }); // } // onChangeNotifyToType(notifyToType) { // this.setState({ notifyToType }); // } // onChangeEmailToSend(inputValue) { // this.setState({ emailToSend: inputValue }); // } // onChangeSlackChannelToSend(inputValue) { // this.setState({ slackChannelToSend: inputValue }); // } const onChangeTriggerEvents = (triggerEvent) => { if (triggerEvents.has(triggerEvent)) { triggerEvents.delete(triggerEvent); this.setState({ triggerEvents }); } else { triggerEvents.add(triggerEvent); this.setState({ triggerEvents }); } }; const submitHandler = useCallback(async() => { const requestParams = { triggerPath, notifyToType, emailToSend, slacChannelToSend, triggerEvents, }; try { if (globalNotificationId != null) { await apiv3Put(`/notification-setting/global-notification/${globalNotificationId}`, requestParams); } else { await apiv3Post('/notification-setting/global-notification', requestParams); } window.location.href = urljoin(window.location.origin, '/admin/notification#global-notification'); } catch (err) { // toastError(err); logger.error(err); } }, []); const { isMailerSetup } = props; const { t } = useTranslation('admin'); return ( <>
{/* eslint-disable-next-line react/no-danger */} {!isMailerSetup && } Hint: {t('notification_settings.email.ifttt_link')}
> ) : ( <>{/* eslint-disable-next-line react/no-danger */}
> )}