|
@@ -1,90 +1,51 @@
|
|
|
-import { useEffect, useMemo } from 'react';
|
|
|
|
|
|
|
+import { useEffect } from 'react';
|
|
|
|
|
|
|
|
import { objectIdUtils } from '@growi/core/dist/utils';
|
|
import { objectIdUtils } from '@growi/core/dist/utils';
|
|
|
-import type {
|
|
|
|
|
- NextPage, GetServerSideProps, GetServerSidePropsContext,
|
|
|
|
|
-} from 'next';
|
|
|
|
|
-import { useTranslation } from 'next-i18next';
|
|
|
|
|
import dynamic from 'next/dynamic';
|
|
import dynamic from 'next/dynamic';
|
|
|
-import Head from 'next/head';
|
|
|
|
|
import { useRouter } from 'next/router';
|
|
import { useRouter } from 'next/router';
|
|
|
-import type { Container } from 'unstated';
|
|
|
|
|
-import { Provider } from 'unstated';
|
|
|
|
|
|
|
|
|
|
-import type { CommonProps } from '~/pages/utils/commons';
|
|
|
|
|
-import { generateCustomTitle } from '~/pages/utils/commons';
|
|
|
|
|
-import { useCurrentUser } from '~/stores-universal/context';
|
|
|
|
|
|
|
+import type { NextPageWithLayout } from '../../_app.page';
|
|
|
|
|
+import type { AdminCommonProps } from '../_shared';
|
|
|
|
|
+import { createAdminPageLayout, getServerSideAdminCommonProps } from '../_shared';
|
|
|
|
|
|
|
|
-import { retrieveServerSideProps } from '../../../utils/admin-page-util';
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-const AdminLayout = dynamic(() => import('~/components/Layout/AdminLayout'), { ssr: false });
|
|
|
|
|
const ManageGlobalNotification = dynamic(() => import('~/client/components/Admin/Notification/ManageGlobalNotification'), { ssr: false });
|
|
const ManageGlobalNotification = dynamic(() => import('~/client/components/Admin/Notification/ManageGlobalNotification'), { ssr: false });
|
|
|
-const ForbiddenPage = dynamic(() => import('~/client/components/Admin/ForbiddenPage').then(mod => mod.ForbiddenPage), { ssr: false });
|
|
|
|
|
|
|
|
|
|
|
|
+type Props = AdminCommonProps;
|
|
|
|
|
|
|
|
-const AdminGlobalNotificationNewPage: NextPage<CommonProps> = (props) => {
|
|
|
|
|
- const { t } = useTranslation('admin');
|
|
|
|
|
- useCurrentUser(props.currentUser ?? null);
|
|
|
|
|
|
|
+const AdminGlobalNotificationDetailPage: NextPageWithLayout<Props> = () => {
|
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
|
const { globalNotificationId } = router.query;
|
|
const { globalNotificationId } = router.query;
|
|
|
const currentGlobalNotificationId = Array.isArray(globalNotificationId) ? globalNotificationId[0] : globalNotificationId;
|
|
const currentGlobalNotificationId = Array.isArray(globalNotificationId) ? globalNotificationId[0] : globalNotificationId;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
|
- const toastError = import('~/client/util/toastr').then(mod => mod.toastError);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ const toastErrorPromise = import('~/client/util/toastr').then(mod => mod.toastError);
|
|
|
if (globalNotificationId == null) {
|
|
if (globalNotificationId == null) {
|
|
|
router.push('/admin/notification');
|
|
router.push('/admin/notification');
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
- if ((currentGlobalNotificationId != null && !objectIdUtils.isValidObjectId(currentGlobalNotificationId))) {
|
|
|
|
|
|
|
+ if (currentGlobalNotificationId != null && !objectIdUtils.isValidObjectId(currentGlobalNotificationId)) {
|
|
|
(async() => {
|
|
(async() => {
|
|
|
- (await toastError)(t('notification_settings.not_found_global_notification_triggerid'));
|
|
|
|
|
|
|
+ (await toastErrorPromise)('Invalid notification id');
|
|
|
router.push('/admin/global-notification/new');
|
|
router.push('/admin/global-notification/new');
|
|
|
})();
|
|
})();
|
|
|
- return;
|
|
|
|
|
}
|
|
}
|
|
|
- }, [currentGlobalNotificationId, globalNotificationId, router, t]);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- const title = t('external_notification.external_notification');
|
|
|
|
|
- const customTitle = generateCustomTitle(props, title);
|
|
|
|
|
-
|
|
|
|
|
- const injectableContainers: Container<any>[] = useMemo(() => [], []);
|
|
|
|
|
-
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- (async() => {
|
|
|
|
|
- const AdminNotificationContainer = (await import('~/client/services/AdminNotificationContainer')).default;
|
|
|
|
|
- const adminNotificationContainer = new AdminNotificationContainer();
|
|
|
|
|
- injectableContainers.push(adminNotificationContainer);
|
|
|
|
|
- })();
|
|
|
|
|
- }, [injectableContainers]);
|
|
|
|
|
-
|
|
|
|
|
- if (props.isAccessDeniedForNonAdminUser) {
|
|
|
|
|
- <ForbiddenPage />;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return (
|
|
|
|
|
- <Provider inject={[...injectableContainers]}>
|
|
|
|
|
- <AdminLayout componentTitle={title}>
|
|
|
|
|
- <Head>
|
|
|
|
|
- <title>{customTitle}</title>
|
|
|
|
|
- </Head>
|
|
|
|
|
- {
|
|
|
|
|
- currentGlobalNotificationId != null && router.isReady
|
|
|
|
|
- && <ManageGlobalNotification globalNotificationId={currentGlobalNotificationId} />
|
|
|
|
|
- }
|
|
|
|
|
- </AdminLayout>
|
|
|
|
|
- </Provider>
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ }, [currentGlobalNotificationId, globalNotificationId, router]);
|
|
|
|
|
|
|
|
|
|
+ return (currentGlobalNotificationId != null && router.isReady)
|
|
|
|
|
+ ? <ManageGlobalNotification globalNotificationId={currentGlobalNotificationId} />
|
|
|
|
|
+ : null;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+AdminGlobalNotificationDetailPage.getLayout = createAdminPageLayout<Props>({
|
|
|
|
|
+ title: (_p, t) => t('external_notification.external_notification'),
|
|
|
|
|
+ containerFactories: [
|
|
|
|
|
+ async() => {
|
|
|
|
|
+ const AdminNotificationContainer = (await import('~/client/services/AdminNotificationContainer')).default;
|
|
|
|
|
+ return new AdminNotificationContainer();
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+});
|
|
|
|
|
|
|
|
-export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
|
|
|
|
|
- const props = await retrieveServerSideProps(context);
|
|
|
|
|
- return props;
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
|
|
+export const getServerSideProps = getServerSideAdminCommonProps;
|
|
|
|
|
|
|
|
-export default AdminGlobalNotificationNewPage;
|
|
|
|
|
|
|
+export default AdminGlobalNotificationDetailPage;
|