Explorar el Código

Added installer.page.tsx file and render the page

Shunm634-source hace 3 años
padre
commit
d283afa4b4

+ 123 - 0
packages/app/src/pages/installer.page.tsx

@@ -0,0 +1,123 @@
+import React, { useEffect } from 'react';
+
+import { pagePathUtils } from '@growi/core';
+import { isValidObjectId } from 'mongoose';
+import {
+  NextPage, GetServerSideProps, GetServerSidePropsContext,
+} from 'next';
+import Head from 'next/head';
+import { useRouter } from 'next/router';
+
+import { CrowiRequest } from '~/interfaces/crowi-request';
+import { IPageWithMeta } from '~/interfaces/page';
+import { PageModel } from '~/server/models/page';
+import { useSWRxCurrentPage, useSWRxPageInfo } from '~/stores/page';
+import loggerFactory from '~/utils/logger';
+
+import { BasicLayout } from '../components/BasicLayout';
+import InstallerForm from '../components/InstallerForm';
+import {
+  useCurrentUser, useCurrentPagePath,
+  useOwnerOfCurrentPage,
+  useIsForbidden, useIsNotFound, useIsTrashPage, useShared, useShareLinkId, useIsSharedUser, useIsAbleToDeleteCompletely,
+  useAppTitle, useSiteUrl, useConfidential, useIsEnabledStaleNotification,
+  useIsSearchServiceConfigured, useIsSearchServiceReachable, useIsMailerSetup,
+  useAclEnabled, useHasSlackConfig, useDrawioUri, useHackmdUri, useMathJax, useNoCdn, useEditorConfig, useCsrfToken,
+} from '../stores/context';
+
+import { CommonProps, getServerSideCommonProps, useCustomTitle } from './commons';
+
+
+const logger = loggerFactory('growi:pages:all');
+const { isUsersHomePage, isTrashPage: _isTrashPage } = pagePathUtils;
+
+type Props = CommonProps & {
+  currentUser: string,
+  userName: string | undefined,
+  name: string | undefined,
+  email: string | undefined,
+
+  pageWithMetaStr: string,
+
+  isForbidden: boolean,
+  isNotFound: boolean,
+  isSearchServiceConfigured: boolean,
+  isSearchServiceReachable: boolean,
+};
+
+const InstallerPage: NextPage<Props> = (props: Props) => {
+  const router = useRouter();
+
+  const { data: currentUser } = useCurrentUser(props.currentUser != null ? JSON.parse(props.currentUser) : null);
+
+  // commons
+  useAppTitle(props.appTitle);
+  useSiteUrl(props.siteUrl);
+  useConfidential(props.confidential);
+  useCsrfToken(props.csrfToken);
+
+  // page
+  useCurrentPagePath(props.currentPathname);
+
+  useIsSearchServiceConfigured(props.isSearchServiceConfigured);
+  useIsSearchServiceReachable(props.isSearchServiceReachable);
+
+  let pageWithMeta: IPageWithMeta | undefined;
+  if (props.pageWithMetaStr != null) {
+    pageWithMeta = JSON.parse(props.pageWithMetaStr) as IPageWithMeta;
+  }
+  useSWRxCurrentPage(undefined, pageWithMeta?.data); // store initial data
+  useSWRxPageInfo(pageWithMeta?.data._id, undefined, pageWithMeta?.meta); // store initial data
+
+  const classNames: string[] = [];
+
+  return (
+    <>
+      <Head>
+      </Head>
+      {/* <BasicLayout title={useCustomTitle(props, t('GROWI'))} className={classNames.join(' ')}> */}
+      <BasicLayout title={useCustomTitle(props, 'GROWI')} className={classNames.join(' ')}>
+        <div id="content-main" className="content-main grw-container-convertible">
+          <InstallerForm userName={props.userName} name={props.name} email={props.email} />
+        </div>
+      </BasicLayout>
+    </>
+  );
+};
+
+export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
+  const req: CrowiRequest = context.req as CrowiRequest;
+  const { crowi } = req;
+  const {
+    appService, searchService, configManager, aclService, slackNotificationService, mailService,
+  } = crowi;
+
+  const { user } = req;
+
+  const result = await getServerSideCommonProps(context);
+
+  // check for presence
+  // see: https://github.com/vercel/next.js/issues/19271#issuecomment-730006862
+  if (!('props' in result)) {
+    throw new Error('invalid getSSP result');
+  }
+
+  const props: Props = result.props as Props;
+  // await injectPageInformation(context, props);
+
+  if (user != null) {
+    props.currentUser = JSON.stringify(user);
+  }
+  props.userName = user?.username;
+  props.name = user?.name;
+  props.email = user?.email;
+
+  props.isSearchServiceConfigured = searchService.isConfigured;
+  props.isSearchServiceReachable = searchService.isReachable;
+
+  return {
+    props,
+  };
+};
+
+export default InstallerPage;

+ 2 - 2
packages/app/src/server/routes/index.js

@@ -1,5 +1,5 @@
-import express from 'express';
 import csrf from 'csurf';
+import express from 'express';
 
 import apiV1FormValidator from '../middlewares/apiv1-form-validator';
 import injectResetOrderByTokenMiddleware from '../middlewares/inject-reset-order-by-token-middleware';
@@ -95,7 +95,7 @@ module.exports = function(crowi, app) {
   // installer
   if (!isInstalled) {
     const installer = require('./installer')(crowi);
-    app.get('/installer'              , applicationNotInstalled , installer.index);
+    app.get('/installer'              , applicationNotInstalled , installer.index, next.delegateToNext);
     app.post('/installer'             , apiLimiter , applicationNotInstalled , registerFormValidator.registerRules(), registerFormValidator.registerValidation, csrfProtection, installer.install);
     return;
   }