| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import React, { useMemo } from 'react';
- import PropTypes from 'prop-types';
- import loggerFactory from '@alias/logger';
- import { withUnstatedContainers } from '../../UnstatedUtils';
- import { toastError } from '../../../util/apiNotification';
- import toArrayIfNot from '../../../../../lib/util/toArrayIfNot';
- import { withLoadingSppiner } from '../../SuspenseUtils';
- import AdminNotificationContainer from '../../../services/AdminNotificationContainer';
- import CustomNavigation from '../../CustomNavigation';
- import SlackAppConfiguration from './SlackAppConfiguration';
- import UserTriggerNotification from './UserTriggerNotification';
- import GlobalNotification from './GlobalNotification';
- const logger = loggerFactory('growi:NotificationSetting');
- let retrieveErrors = null;
- function NotificationSetting(props) {
- const { adminNotificationContainer } = props;
- if (adminNotificationContainer.state.webhookUrl === adminNotificationContainer.dummyWebhookUrl) {
- throw (async() => {
- try {
- await adminNotificationContainer.retrieveNotificationData();
- }
- catch (err) {
- const errs = toArrayIfNot(err);
- toastError(errs);
- logger.error(errs);
- retrieveErrors = errs;
- adminNotificationContainer.setState({ webhookUrl: adminNotificationContainer.dummyWebhookUrlForError });
- }
- })();
- }
- if (adminNotificationContainer.state.webhookUrl === adminNotificationContainer.dummyWebhookUrlForError) {
- throw new Error(`${retrieveErrors.length} errors occured`);
- }
- const navTabMapping = useMemo(() => {
- return {
- slack_configuration: {
- Icon: () => <i className="icon-settings" />,
- Content: SlackAppConfiguration,
- i18n: 'Slack configuration',
- index: 0,
- },
- user_trigger_notification: {
- Icon: () => <i className="icon-settings" />,
- Content: UserTriggerNotification,
- i18n: 'User trigger notification',
- index: 1,
- },
- global_notification: {
- Icon: () => <i className="icon-settings" />,
- Content: GlobalNotification,
- i18n: 'Global notification',
- index: 2,
- },
- };
- }, []);
- return <CustomNavigation navTabMapping={navTabMapping} />;
- }
- const NotificationSettingWithUnstatedContainer = withUnstatedContainers(withLoadingSppiner(NotificationSetting), [AdminNotificationContainer]);
- NotificationSetting.propTypes = {
- adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
- };
- export default NotificationSettingWithUnstatedContainer;
|