maintenance.page.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import type { IUser } from '@growi/core';
  2. import type { NextPage, GetServerSideProps, GetServerSidePropsContext } from 'next';
  3. import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
  4. import dynamic from 'next/dynamic';
  5. import type { CrowiRequest } from '~/interfaces/crowi-request';
  6. import { useCurrentUser } from '~/stores-universal/context';
  7. import type { CommonProps } from './utils/commons';
  8. import { getServerSideCommonProps, getNextI18NextConfig } from './utils/commons';
  9. const Maintenance = dynamic(() => import('~/client/components/Maintenance').then(mod => mod.Maintenance), { ssr: false });
  10. type Props = CommonProps & {
  11. currentUser: IUser,
  12. };
  13. const MaintenancePage: NextPage<CommonProps> = (props: Props) => {
  14. useCurrentUser(props.currentUser ?? null);
  15. return (
  16. <div className="container-lg">
  17. <div className="container">
  18. <div className="row justify-content-md-center">
  19. <div className="col-md-6 mt-5">
  20. <Maintenance currentUser={props.currentUser} />
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. );
  26. };
  27. async function injectNextI18NextConfigurations(context: GetServerSidePropsContext, props: Props, namespacesRequired?: string[] | undefined): Promise<void> {
  28. const nextI18NextConfig = await getNextI18NextConfig(serverSideTranslations, context, namespacesRequired);
  29. props._nextI18Next = nextI18NextConfig._nextI18Next;
  30. }
  31. export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
  32. const req = context.req as CrowiRequest;
  33. const result = await getServerSideCommonProps(context);
  34. if ('redirect' in result) {
  35. return { redirect: result.redirect };
  36. }
  37. if (!('props' in result)) {
  38. throw new Error('invalid getSSP result');
  39. }
  40. const props: Props = result.props as Props;
  41. if (props.redirectDestination != null) {
  42. return {
  43. redirect: {
  44. permanent: false,
  45. destination: props.redirectDestination,
  46. },
  47. };
  48. }
  49. const { user } = req;
  50. if (user != null) {
  51. props.currentUser = user.toObject();
  52. }
  53. await injectNextI18NextConfigurations(context, props, ['translation']);
  54. return {
  55. props,
  56. };
  57. };
  58. export default MaintenancePage;