|
@@ -1,69 +1,39 @@
|
|
|
-import type {
|
|
|
|
|
- NextPage, GetServerSideProps, GetServerSidePropsContext,
|
|
|
|
|
-} from 'next';
|
|
|
|
|
-import { useTranslation } from 'next-i18next';
|
|
|
|
|
|
|
+import { useMemo } from 'react';
|
|
|
|
|
+
|
|
|
|
|
+import { useHydrateAtoms } from 'jotai/utils';
|
|
|
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 { CrowiRequest } from '~/interfaces/crowi-request';
|
|
|
|
|
-import type { CommonProps } from '~/pages/utils/commons';
|
|
|
|
|
-import { generateCustomTitle } from '~/pages/utils/commons';
|
|
|
|
|
-import { useIsAclEnabled, useCurrentUser } from '~/stores-universal/context';
|
|
|
|
|
-import { useIsMaintenanceMode } from '~/stores/maintenanceMode';
|
|
|
|
|
|
|
+import { isAclEnabledAtom } from '~/states/server-configurations';
|
|
|
|
|
|
|
|
-import { retrieveServerSideProps } from '../../../utils/admin-page-util';
|
|
|
|
|
|
|
+import type { NextPageWithLayout } from '../../_app.page';
|
|
|
|
|
+import type { AdminCommonProps } from '../_shared';
|
|
|
|
|
+import { createAdminPageLayout, getServerSideAdminCommonProps } from '../_shared';
|
|
|
|
|
|
|
|
-const AdminLayout = dynamic(() => import('~/components/Layout/AdminLayout'), { ssr: false });
|
|
|
|
|
const UserGroupDetailPage = dynamic(() => import('~/client/components/Admin/UserGroupDetail/UserGroupDetailPage'), { ssr: false });
|
|
const UserGroupDetailPage = dynamic(() => import('~/client/components/Admin/UserGroupDetail/UserGroupDetailPage'), { ssr: false });
|
|
|
-const ForbiddenPage = dynamic(() => import('~/client/components/Admin/ForbiddenPage').then(mod => mod.ForbiddenPage), { ssr: false });
|
|
|
|
|
|
|
|
|
|
-type Props = CommonProps & {
|
|
|
|
|
- isAclEnabled: boolean
|
|
|
|
|
-}
|
|
|
|
|
|
|
+type PageProps = { isAclEnabled: boolean };
|
|
|
|
|
+type Props = AdminCommonProps & PageProps;
|
|
|
|
|
|
|
|
-const AdminUserGroupDetailPage: NextPage<Props> = (props: Props) => {
|
|
|
|
|
- const { t } = useTranslation('admin');
|
|
|
|
|
- useIsMaintenanceMode(props.isMaintenanceMode);
|
|
|
|
|
- useCurrentUser(props.currentUser ?? null);
|
|
|
|
|
|
|
+const AdminUserGroupDetailPage: NextPageWithLayout<Props> = (props: Props) => {
|
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
|
- const { userGroupId, isExternalGroup } = router.query;
|
|
|
|
|
-
|
|
|
|
|
- const title = t('user_group_management.user_group_management');
|
|
|
|
|
- const customTitle = generateCustomTitle(props, title);
|
|
|
|
|
-
|
|
|
|
|
- const currentUserGroupId = Array.isArray(userGroupId) ? userGroupId[0] : userGroupId;
|
|
|
|
|
-
|
|
|
|
|
- const isExternalGroupBool = isExternalGroup === 'true';
|
|
|
|
|
|
|
|
|
|
- useIsAclEnabled(props.isAclEnabled);
|
|
|
|
|
|
|
+ // hydrate
|
|
|
|
|
+ useHydrateAtoms([[isAclEnabledAtom, props.isAclEnabled]], { dangerouslyForceHydrate: true });
|
|
|
|
|
|
|
|
- if (props.isAccessDeniedForNonAdminUser) {
|
|
|
|
|
- return <ForbiddenPage />;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return (
|
|
|
|
|
- <AdminLayout componentTitle={title}>
|
|
|
|
|
- <Head>
|
|
|
|
|
- <title>{customTitle}</title>
|
|
|
|
|
- </Head>
|
|
|
|
|
- {
|
|
|
|
|
- currentUserGroupId != null && router.isReady
|
|
|
|
|
- && <UserGroupDetailPage userGroupId={currentUserGroupId} isExternalGroup={isExternalGroupBool} />
|
|
|
|
|
- }
|
|
|
|
|
- </AdminLayout>
|
|
|
|
|
- );
|
|
|
|
|
-};
|
|
|
|
|
|
|
+ const { userGroupId, isExternalGroup } = router.query;
|
|
|
|
|
+ const id = useMemo(() => (Array.isArray(userGroupId) ? userGroupId[0] : userGroupId), [userGroupId]);
|
|
|
|
|
+ const isExternal = isExternalGroup === 'true';
|
|
|
|
|
|
|
|
-const injectServerConfigurations = async(context: GetServerSidePropsContext, props: Props): Promise<void> => {
|
|
|
|
|
- const req: CrowiRequest = context.req as CrowiRequest;
|
|
|
|
|
- props.isAclEnabled = req.crowi.aclService.isAclEnabled();
|
|
|
|
|
|
|
+ return (id != null && router.isReady)
|
|
|
|
|
+ ? <UserGroupDetailPage userGroupId={id} isExternalGroup={isExternal} />
|
|
|
|
|
+ : null;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
|
|
|
|
|
- const props = await retrieveServerSideProps(context, injectServerConfigurations);
|
|
|
|
|
|
|
+AdminUserGroupDetailPage.getLayout = createAdminPageLayout<Props>({
|
|
|
|
|
+ title: (_p, t) => t('user_group_management.user_group_management'),
|
|
|
|
|
+});
|
|
|
|
|
|
|
|
- return props;
|
|
|
|
|
-};
|
|
|
|
|
|
|
+export const getServerSideProps = getServerSideAdminCommonProps;
|
|
|
|
|
|
|
|
export default AdminUserGroupDetailPage;
|
|
export default AdminUserGroupDetailPage;
|