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 AdminNotificationContainer from '~/client/services/AdminNotificationContainer'; import { apiv3Post, apiv3Put } from '~/client/util/apiv3-client'; import { useIsMailerSetup } from '~/stores/context'; import loggerFactory from '~/utils/logger'; // import { withUnstatedContainers } from '../../UnstatedUtils'; import { withUnstatedContainers } from '../../UnstatedUtils'; import AdminUpdateButtonRow from '../Common/AdminUpdateButtonRow'; import TriggerEventCheckBox from './TriggerEventCheckBox'; const logger = loggerFactory('growi:manageGlobalNotification'); const ManageGlobalNotification = (props) => { const [globalNotificationId, setGlobalNotificationId] = useState(null); const [triggerPath, setTriggerPath] = useState(''); const [notifyToType, setNotifyToType] = useState('mail'); const [emailToSend, setEmailToSend] = useState(''); const [slackChannelToSend, setSlackChannelToSend] = useState(''); const [triggerEvents, setTriggerEvents] = useState(new Set()); const onChangeTriggerEvents = (triggerEvent) => { if (triggerEvents.has(triggerEvent)) { triggerEvents.delete(triggerEvent); setTriggerEvents(triggerEvents); } else { triggerEvents.add(triggerEvent); setTriggerEvents(triggerEvents); } }; const submitHandler = useCallback(async() => { const requestParams = { triggerPath, notifyToType, emailToSend, slackChannelToSend, 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 { data: isMailerSetup } = useIsMailerSetup(); const { adminNotificationContainer } = 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 */}
> )}