Просмотр исходного кода

Modified the code based off the first FB

Shunm634-source 3 лет назад
Родитель
Сommit
4f0a95c75e

+ 14 - 14
packages/app/src/components/Admin/Notification/GlobalNotification.jsx

@@ -8,15 +8,14 @@ import AdminNotificationContainer from '~/client/services/AdminNotificationConta
 import { toastSuccess, toastError } from '~/client/util/apiNotification';
 import { toastSuccess, toastError } from '~/client/util/apiNotification';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
-import { withUnstatedContainers } from '../../UnstatedUtils';
-
 import GlobalNotificationList from './GlobalNotificationList';
 import GlobalNotificationList from './GlobalNotificationList';
 
 
 const logger = loggerFactory('growi:GlobalNotification');
 const logger = loggerFactory('growi:GlobalNotification');
 
 
 const GlobalNotification = (props) => {
 const GlobalNotification = (props) => {
 
 
-  const { t, adminNotificationContainer } = props;
+  const { adminNotificationContainer } = props;
+  const { t } = useTranslation('admin');
 
 
   // constructor() {
   // constructor() {
   //   super();
   //   super();
@@ -27,7 +26,7 @@ const GlobalNotification = (props) => {
   const onClickSubmit = useCallback(async() => {
   const onClickSubmit = useCallback(async() => {
     try {
     try {
       await adminNotificationContainer.updateGlobalNotificationForPages();
       await adminNotificationContainer.updateGlobalNotificationForPages();
-      toastSuccess(t('toaster.update_successed', { target: t('External_Notification') }));
+      toastSuccess(t('toaster.update_successed', { target: t('external_notification.external_notification') }));
     }
     }
     catch (err) {
     catch (err) {
       toastError(err);
       toastError(err);
@@ -73,7 +72,8 @@ const GlobalNotification = (props) => {
             </label>
             </label>
           </div>
           </div>
         </div>
         </div>
-      </div><div className="row my-3">
+      </div>
+      <div className="row my-3">
         <div className="col-sm-5 offset-sm-4">
         <div className="col-sm-5 offset-sm-4">
           <button
           <button
             type="button"
             type="button"
@@ -95,7 +95,7 @@ const GlobalNotification = (props) => {
           <tr>
           <tr>
             <th>ON/OFF</th>
             <th>ON/OFF</th>
             {/* eslint-disable-next-line react/no-danger */}
             {/* eslint-disable-next-line react/no-danger */}
-            <th>{t('notification_settings.trigger_path')} <span dangerouslySetInnerHTML={{ __html: t('notification_setting.trigger_path_help') }} /></th>
+            <th>{t('notification_settings.trigger_path')} <span dangerouslySetInnerHTML={{ __html: t('notification_settings.trigger_path_help') }} /></th>
             <th>{t('notification_settings.trigger_events')}</th>
             <th>{t('notification_settings.trigger_events')}</th>
             <th>{t('notification_settings.notify_to')}</th>
             <th>{t('notification_settings.notify_to')}</th>
             <th></th>
             <th></th>
@@ -111,17 +111,17 @@ const GlobalNotification = (props) => {
 };
 };
 
 
 GlobalNotification.propTypes = {
 GlobalNotification.propTypes = {
-  t: PropTypes.func.isRequired, // i18next
   adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
   adminNotificationContainer: PropTypes.instanceOf(AdminNotificationContainer).isRequired,
-
 };
 };
 
 
-const GlobalNotificationWrapperFC = (props) => {
-  const { t } = useTranslation();
+export default GlobalNotification;
 
 
-  return <GlobalNotification t={t} {...props} />;
-};
+// const GlobalNotificationWrapperFC = (props) => {
+//   const { t } = useTranslation('admin');
+
+//   return <GlobalNotification t={t} {...props} />;
+// };
 
 
-const GlobalNotificationWrapper = withUnstatedContainers(GlobalNotificationWrapperFC, [AdminNotificationContainer]);
+// const GlobalNotificationWrapper = withUnstatedContainers(GlobalNotificationWrapperFC, [AdminNotificationContainer]);
 
 
-export default GlobalNotificationWrapper;
+// export default GlobalNotificationWrapper;

+ 24 - 18
packages/app/src/components/Admin/Notification/ManageGlobalNotification.jsx

@@ -23,22 +23,28 @@ export default class ManageGlobalNotification extends React.Component {
   constructor() {
   constructor() {
     super();
     super();
 
 
-    let globalNotification;
-    try {
-      globalNotification = JSON.parse(document.getElementById('admin-global-notification-setting').getAttribute('data-global-notification'));
-    }
-    catch (err) {
-      // toastError(err);
-      logger.error(err);
-    }
+    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 = {
     this.state = {
-      globalNotificationId: globalNotification._id || null,
-      triggerPath: globalNotification.triggerPath || '',
-      notifyToType: globalNotification.__t || 'mail',
-      emailToSend: globalNotification.toEmail || '',
-      slackChannelToSend: globalNotification.slackChannels || '',
-      triggerEvents: new Set(globalNotification.triggerEvents),
+      // 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);
     this.submitHandler = this.submitHandler.bind(this);
@@ -316,11 +322,11 @@ ManageGlobalNotification.propTypes = {
   isMailerSetup: PropTypes.bool,
   isMailerSetup: PropTypes.bool,
 };
 };
 
 
-const ManageGlobalNotificationWrapperFC = (props) => {
-  const { t } = useTranslation();
+// const ManageGlobalNotificationWrapperFC = (props) => {
+//   const { t } = useTranslation();
 
 
-  return <ManageGlobalNotification t={t} {...props} />;
-};
+//   return <ManageGlobalNotification t={t} {...props} />;
+// };
 
 
 // const ManageGlobalNotificationWrapper = withUnstatedContainers(ManageGlobalNotificationWrapperFC, [AppContainer]);
 // const ManageGlobalNotificationWrapper = withUnstatedContainers(ManageGlobalNotificationWrapperFC, [AppContainer]);
 
 

+ 4 - 4
packages/app/src/components/Admin/Notification/NotificationSetting.jsx

@@ -46,7 +46,7 @@ const SkeltonListItem = () => (
 
 
 // eslint-disable-next-line react/prop-types
 // eslint-disable-next-line react/prop-types
 const SlackIntegrationListItem = ({ isEnabled, currentBotType }) => {
 const SlackIntegrationListItem = ({ isEnabled, currentBotType }) => {
-  const { t } = useTranslation();
+  const { t } = useTranslation('admin');
 
 
   const isCautionVisible = currentBotType === SlackbotType.OFFICIAL || currentBotType === SlackbotType.CUSTOM_WITH_PROXY;
   const isCautionVisible = currentBotType === SlackbotType.OFFICIAL || currentBotType === SlackbotType.CUSTOM_WITH_PROXY;
 
 
@@ -68,7 +68,7 @@ const SlackIntegrationListItem = ({ isEnabled, currentBotType }) => {
 
 
 // eslint-disable-next-line react/prop-types
 // eslint-disable-next-line react/prop-types
 const LegacySlackIntegrationListItem = ({ isEnabled }) => {
 const LegacySlackIntegrationListItem = ({ isEnabled }) => {
-  const { t } = useTranslation();
+  const { t } = useTranslation('admin');
 
 
   return (
   return (
     <li className="list-group-item">
     <li className="list-group-item">
@@ -91,7 +91,7 @@ const LegacySlackIntegrationListItem = ({ isEnabled }) => {
 function NotificationSetting(props) {
 function NotificationSetting(props) {
   const { adminNotificationContainer } = props;
   const { adminNotificationContainer } = props;
 
 
-  const { t } = useTranslation();
+  const { t } = useTranslation('admin');
 
 
   const [isMounted, setMounted] = useState(false);
   const [isMounted, setMounted] = useState(false);
   const [activeTab, setActiveTab] = useState('user_trigger_notification');
   const [activeTab, setActiveTab] = useState('user_trigger_notification');
@@ -164,7 +164,7 @@ function NotificationSetting(props) {
           {activeComponents.has('user_trigger_notification') && <UserTriggerNotification />}
           {activeComponents.has('user_trigger_notification') && <UserTriggerNotification />}
         </TabPane>
         </TabPane>
         <TabPane tabId="global_notification">
         <TabPane tabId="global_notification">
-          {activeComponents.has('global_notification') && <GlobalNotification />}
+          {activeComponents.has('global_notification') && <GlobalNotification adminNotificationContainer={props.adminNotificationContainer} />}
         </TabPane>
         </TabPane>
       </TabContent>
       </TabContent>
     </div>
     </div>

+ 3 - 3
packages/app/src/pages/admin/[[...path]].page.tsx

@@ -28,7 +28,6 @@ import AdminSamlSecurityContainer from '~/client/services/AdminSamlSecurityConta
 import AdminSlackIntegrationLegacyContainer from '~/client/services/AdminSlackIntegrationLegacyContainer';
 import AdminSlackIntegrationLegacyContainer from '~/client/services/AdminSlackIntegrationLegacyContainer';
 import AdminTwitterSecurityContainer from '~/client/services/AdminTwitterSecurityContainer';
 import AdminTwitterSecurityContainer from '~/client/services/AdminTwitterSecurityContainer';
 import AdminUsersContainer from '~/client/services/AdminUsersContainer';
 import AdminUsersContainer from '~/client/services/AdminUsersContainer';
-import ManageGlobalNotification from '~/components/Admin/Notification/ManageGlobalNotification';
 import { SupportedActionType } from '~/interfaces/activity';
 import { SupportedActionType } from '~/interfaces/activity';
 import { CrowiRequest } from '~/interfaces/crowi-request';
 import { CrowiRequest } from '~/interfaces/crowi-request';
 import PluginUtils from '~/server/plugins/plugin-utils';
 import PluginUtils from '~/server/plugins/plugin-utils';
@@ -53,6 +52,7 @@ const CustomizeSettingContents = dynamic(() => import('../../components/Admin/Cu
 const DataImportPageContents = dynamic(() => import('../../components/Admin/ImportData/ImportDataPageContents'), { ssr: false });
 const DataImportPageContents = dynamic(() => import('../../components/Admin/ImportData/ImportDataPageContents'), { ssr: false });
 const ExportArchiveDataPage = dynamic(() => import('../../components/Admin/ExportArchiveDataPage'), { ssr: false });
 const ExportArchiveDataPage = dynamic(() => import('../../components/Admin/ExportArchiveDataPage'), { ssr: false });
 const NotificationSetting = dynamic(() => import('../../components/Admin/Notification/NotificationSetting'), { ssr: false });
 const NotificationSetting = dynamic(() => import('../../components/Admin/Notification/NotificationSetting'), { ssr: false });
+const ManageGlobalNotification = dynamic(() => import('../../components/Admin/Notification/ManageGlobalNotification'), { ssr: false });
 const SlackIntegration = dynamic(() => import('../../components/Admin/SlackIntegration/SlackIntegration'), { ssr: false });
 const SlackIntegration = dynamic(() => import('../../components/Admin/SlackIntegration/SlackIntegration'), { ssr: false });
 const LegacySlackIntegration = dynamic(() => import('../../components/Admin/LegacySlackIntegration/LegacySlackIntegration'), { ssr: false });
 const LegacySlackIntegration = dynamic(() => import('../../components/Admin/LegacySlackIntegration/LegacySlackIntegration'), { ssr: false });
 const UserManagement = dynamic(() => import('../../components/Admin/UserManagement'), { ssr: false });
 const UserManagement = dynamic(() => import('../../components/Admin/UserManagement'), { ssr: false });
@@ -142,8 +142,8 @@ const AdminMarkdownSettingsPage: NextPage<Props> = (props: Props) => {
     },
     },
     'global-notification': {
     'global-notification': {
       new: {
       new: {
-        title: t('external_notification'),
-        component: <ManageGlobalNotification isMailerSetup={props.isMailerSetup} />,
+        title: t('external_notification.external_notification'),
+        component: <ManageGlobalNotification isMailerSetup={props.isMailerSetup} t={t} />,
       },
       },
     },
     },
     'slack-integration': {
     'slack-integration': {