瀏覽代碼

refactor slack integration page

Yuki Takei 7 月之前
父節點
當前提交
6839969631
共有 1 個文件被更改,包括 18 次插入49 次删除
  1. 18 49
      apps/app/src/pages/admin/slack-integration.page.tsx

+ 18 - 49
apps/app/src/pages/admin/slack-integration.page.tsx

@@ -1,64 +1,33 @@
-import type {
-  NextPage, GetServerSideProps, GetServerSidePropsContext,
-} from 'next';
-import { useTranslation } from 'next-i18next';
+import { useHydrateAtoms } from 'jotai/utils';
+import type { GetServerSideProps, GetServerSidePropsContext } from 'next';
 import dynamic from 'next/dynamic';
-import Head from 'next/head';
 
-import type { CrowiRequest } from '~/interfaces/crowi-request';
-import type { CommonProps } from '~/pages/utils/commons';
-import { generateCustomTitle } from '~/pages/utils/commons';
-import { useCurrentUser, useSiteUrl } from '~/stores-universal/context';
+import { siteUrlWithEmptyValueWarnAtom } from '~/states/global';
 
-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 SlackIntegration = dynamic(() => import('~/client/components/Admin/SlackIntegration/SlackIntegration').then(mod => mod.SlackIntegration), { ssr: false });
-const ForbiddenPage = dynamic(() => import('~/client/components/Admin/ForbiddenPage').then(mod => mod.ForbiddenPage), { ssr: false });
 
+type Props = AdminCommonProps;
 
-type Props = CommonProps & {
-  siteUrl: string
-};
-
-
-const AdminSlackIntegrationPage: NextPage<Props> = (props) => {
-  const { t } = useTranslation('admin');
-  useCurrentUser(props.currentUser ?? null);
-  useSiteUrl(props.siteUrl);
-
-  const componentTitle = t('slack_integration.slack_integration');
-  const pageTitle = generateCustomTitle(props, componentTitle);
-
-  if (props.isAccessDeniedForNonAdminUser) {
-    return <ForbiddenPage />;
-  }
+const AdminSlackIntegrationPage: NextPageWithLayout<Props> = (props: Props) => {
+  // hydrate global state
+  useHydrateAtoms([
+    [siteUrlWithEmptyValueWarnAtom, props.siteUrlWithEmptyValueWarn],
+  ], { dangerouslyForceHydrate: true });
 
-  return (
-    <AdminLayout componentTitle={componentTitle}>
-      <Head>
-        <title>{pageTitle}</title>
-      </Head>
-      <SlackIntegration />
-    </AdminLayout>
-  );
+  return <SlackIntegration />;
 };
 
+AdminSlackIntegrationPage.getLayout = createAdminPageLayout<Props>({
+  title: (_p, t) => t('slack_integration.slack_integration'),
+});
 
-const injectServerConfigurations = async(context: GetServerSidePropsContext, props: Props): Promise<void> => {
-  const req: CrowiRequest = context.req as CrowiRequest;
-  const { crowi } = req;
-  const { growiInfoService } = crowi;
-
-  props.siteUrl = growiInfoService.getSiteUrl();
+export const getServerSideProps: GetServerSideProps<Props> = async(context: GetServerSidePropsContext) => {
+  return getServerSideAdminCommonProps(context);
 };
 
-
-export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
-  const props = await retrieveServerSideProps(context, injectServerConfigurations);
-  return props;
-};
-
-
 export default AdminSlackIntegrationPage;