kaori 3 лет назад
Родитель
Сommit
41d906cb69

+ 5 - 15
packages/app/src/components/Admin/Notification/ManageGlobalNotification.tsx

@@ -6,7 +6,6 @@ import { useTranslation } from 'next-i18next';
 import { useRouter } from 'next/router';
 import { useRouter } from 'next/router';
 
 
 import { NotifyType, TriggerEventType } from '~/client/interfaces/global-notification';
 import { NotifyType, TriggerEventType } from '~/client/interfaces/global-notification';
-import AdminNotificationContainer from '~/client/services/AdminNotificationContainer';
 import { toastError } from '~/client/util/apiNotification';
 import { toastError } from '~/client/util/apiNotification';
 import { apiv3Post } from '~/client/util/apiv3-client';
 import { apiv3Post } from '~/client/util/apiv3-client';
 import { useIsMailerSetup } from '~/stores/context';
 import { useIsMailerSetup } from '~/stores/context';
@@ -14,7 +13,6 @@ import { useSWRxGlobalNotification } from '~/stores/global-notification';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
 
 
-import { withUnstatedContainers } from '../../UnstatedUtils';
 import AdminUpdateButtonRow from '../Common/AdminUpdateButtonRow';
 import AdminUpdateButtonRow from '../Common/AdminUpdateButtonRow';
 
 
 import TriggerEventCheckBox from './TriggerEventCheckBox';
 import TriggerEventCheckBox from './TriggerEventCheckBox';
@@ -24,11 +22,9 @@ const logger = loggerFactory('growi:manageGlobalNotification');
 
 
 
 
 type Props = {
 type Props = {
-  adminNotificationContainer: AdminNotificationContainer,
   globalNotificationId?: string,
   globalNotificationId?: string,
 }
 }
 
 
-
 const ManageGlobalNotification = (props: Props): JSX.Element => {
 const ManageGlobalNotification = (props: Props): JSX.Element => {
 
 
   const [triggerPath, setTriggerPath] = useState('');
   const [triggerPath, setTriggerPath] = useState('');
@@ -36,7 +32,7 @@ const ManageGlobalNotification = (props: Props): JSX.Element => {
   const [emailToSend, setEmailToSend] = useState('');
   const [emailToSend, setEmailToSend] = useState('');
   const [slackChannelToSend, setSlackChannelToSend] = useState('');
   const [slackChannelToSend, setSlackChannelToSend] = useState('');
   const [triggerEvents, setTriggerEvents] = useState(new Set());
   const [triggerEvents, setTriggerEvents] = useState(new Set());
-  const { data: globalNotificationData, update: updateGlobalNotification } = useSWRxGlobalNotification(props.globalNotificationId || '');
+  const { data: globalNotificationData, update: updateGlobalNotification } = useSWRxGlobalNotification(props.notificationId || '');
   const globalNotification = useMemo(() => globalNotificationData?.globalNotification, [globalNotificationData?.globalNotification]);
   const globalNotification = useMemo(() => globalNotificationData?.globalNotification, [globalNotificationData?.globalNotification]);
 
 
   const router = useRouter();
   const router = useRouter();
@@ -92,10 +88,8 @@ const ManageGlobalNotification = (props: Props): JSX.Element => {
       triggerEvents: [...triggerEvents],
       triggerEvents: [...triggerEvents],
     };
     };
 
 
-    const globalNotificationId = globalNotification?._id;
-
     try {
     try {
-      if (globalNotificationId != null) {
+      if (props.globalNotificationId != null) {
         await updateGlobalNotification(requestParams);
         await updateGlobalNotification(requestParams);
         router.push('/admin/notification');
         router.push('/admin/notification');
       }
       }
@@ -108,11 +102,10 @@ const ManageGlobalNotification = (props: Props): JSX.Element => {
       toastError(err);
       toastError(err);
       logger.error(err);
       logger.error(err);
     }
     }
-  }, [emailToSend, globalNotification, notifyType, router, slackChannelToSend, triggerEvents, triggerPath, updateGlobalNotification]);
+  }, [emailToSend, notifyType, props.globalNotificationId, router, slackChannelToSend, triggerEvents, triggerPath, updateGlobalNotification]);
 
 
 
 
   const { data: isMailerSetup } = useIsMailerSetup();
   const { data: isMailerSetup } = useIsMailerSetup();
-  const { adminNotificationContainer } = props;
   const { t } = useTranslation('admin');
   const { t } = useTranslation('admin');
 
 
   return (
   return (
@@ -315,13 +308,10 @@ const ManageGlobalNotification = (props: Props): JSX.Element => {
 
 
       <AdminUpdateButtonRow
       <AdminUpdateButtonRow
         onClick={updateButtonClickedHandler}
         onClick={updateButtonClickedHandler}
-        disabled={adminNotificationContainer.state.retrieveError != null}
+        disabled={false}
       />
       />
     </>
     </>
   );
   );
 };
 };
 
 
-
-const ManageGlobalNotificationWrapper = withUnstatedContainers(ManageGlobalNotification, [AdminNotificationContainer]);
-
-export default ManageGlobalNotificationWrapper;
+export default ManageGlobalNotification;

+ 2 - 0
packages/app/src/pages/admin/global-notification/[globalNotificationId].page.tsx

@@ -11,10 +11,12 @@ import { Container, Provider } from 'unstated';
 
 
 import AdminNotificationContainer from '~/client/services/AdminNotificationContainer';
 import AdminNotificationContainer from '~/client/services/AdminNotificationContainer';
 import { toastError } from '~/client/util/apiNotification';
 import { toastError } from '~/client/util/apiNotification';
+import { Props } from '~/components/Admin/Notification/ManageGlobalNotification';
 import { CommonProps, useCustomTitle } from '~/pages/utils/commons';
 import { CommonProps, useCustomTitle } from '~/pages/utils/commons';
 
 
 import { retrieveServerSideProps } from '../../../utils/admin-page-util';
 import { retrieveServerSideProps } from '../../../utils/admin-page-util';
 
 
+
 const AdminLayout = dynamic(() => import('~/components/Layout/AdminLayout'), { ssr: false });
 const AdminLayout = dynamic(() => import('~/components/Layout/AdminLayout'), { ssr: false });
 const ManageGlobalNotification = dynamic(() => import('~/components/Admin/Notification/ManageGlobalNotification'), { ssr: false });
 const ManageGlobalNotification = dynamic(() => import('~/components/Admin/Notification/ManageGlobalNotification'), { ssr: false });
 
 

+ 1 - 0
packages/app/src/pages/admin/global-notification/new.page.tsx

@@ -8,6 +8,7 @@ import { Container, Provider } from 'unstated';
 
 
 import AdminNotificationContainer from '~/client/services/AdminNotificationContainer';
 import AdminNotificationContainer from '~/client/services/AdminNotificationContainer';
 import { CommonProps, useCustomTitle } from '~/pages/utils/commons';
 import { CommonProps, useCustomTitle } from '~/pages/utils/commons';
+
 import { retrieveServerSideProps } from '../../../utils/admin-page-util';
 import { retrieveServerSideProps } from '../../../utils/admin-page-util';
 
 
 const AdminLayout = dynamic(() => import('~/components/Layout/AdminLayout'), { ssr: false });
 const AdminLayout = dynamic(() => import('~/components/Layout/AdminLayout'), { ssr: false });