maintenance.page.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import type { IUser, IUserHasId } from '@growi/core';
  2. import { NextPage, GetServerSideProps, GetServerSidePropsContext } from 'next';
  3. import { useTranslation } from 'next-i18next';
  4. import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
  5. import { apiv3Post } from '~/client/util/apiv3-client';
  6. import { toastError } from '~/client/util/toastr';
  7. import type { CrowiRequest } from '~/interfaces/crowi-request';
  8. import { useCurrentUser } from '~/stores/context';
  9. import {
  10. CommonProps, getServerSideCommonProps, getNextI18NextConfig,
  11. } from './utils/commons';
  12. type Props = CommonProps & {
  13. currentUser: IUser,
  14. };
  15. const MaintenancePage: NextPage<CommonProps> = (props: Props) => {
  16. const { t } = useTranslation();
  17. useCurrentUser(props.currentUser ?? null);
  18. const logoutHandler = async() => {
  19. try {
  20. await apiv3Post('/logout');
  21. window.location.reload();
  22. }
  23. catch (err) {
  24. toastError(err);
  25. }
  26. };
  27. return (
  28. <div id="content-main" className="content-main container-lg">
  29. <div className="container">
  30. <div className="row justify-content-md-center">
  31. <div className="col-md-6 mt-5">
  32. <div className="text-center">
  33. <h1><i className="icon-exclamation large"></i></h1>
  34. <h1 className="text-center">{ t('maintenance_mode.maintenance_mode') }</h1>
  35. <h3>{ t('maintenance_mode.growi_is_under_maintenance') }</h3>
  36. <hr />
  37. <div className="text-start">
  38. {props.currentUser?.admin
  39. && (
  40. <p>
  41. <i className="icon-arrow-right"></i>
  42. <a className="btn btn-link" href="/admin">{ t('maintenance_mode.admin_page') }</a>
  43. </p>
  44. )}
  45. {props.currentUser != null
  46. ? (
  47. <p>
  48. <i className="icon-arrow-right"></i>
  49. <a className="btn btn-link" onClick={logoutHandler} id="maintanounse-mode-logout">{ t('maintenance_mode.logout') }</a>
  50. </p>
  51. )
  52. : (
  53. <p>
  54. <i className="icon-arrow-right"></i>
  55. <a className="btn btn-link" href="/login">{ t('maintenance_mode.login') }</a>
  56. </p>
  57. )
  58. }
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. );
  66. };
  67. async function injectNextI18NextConfigurations(context: GetServerSidePropsContext, props: Props, namespacesRequired?: string[] | undefined): Promise<void> {
  68. const nextI18NextConfig = await getNextI18NextConfig(serverSideTranslations, context, namespacesRequired);
  69. props._nextI18Next = nextI18NextConfig._nextI18Next;
  70. }
  71. export const getServerSideProps: GetServerSideProps = async(context: GetServerSidePropsContext) => {
  72. const req = context.req as CrowiRequest<IUserHasId & any>;
  73. const result = await getServerSideCommonProps(context);
  74. if ('redirect' in result) {
  75. return { redirect: result.redirect };
  76. }
  77. if (!('props' in result)) {
  78. throw new Error('invalid getSSP result');
  79. }
  80. const props: Props = result.props as Props;
  81. if (props.redirectDestination != null) {
  82. return {
  83. redirect: {
  84. permanent: false,
  85. destination: props.redirectDestination,
  86. },
  87. };
  88. }
  89. const { user } = req;
  90. if (user != null) {
  91. props.currentUser = user.toObject();
  92. }
  93. await injectNextI18NextConfigurations(context, props, ['translation']);
  94. return {
  95. props,
  96. };
  97. };
  98. export default MaintenancePage;