slack-integration.page.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import type {
  2. GetServerSideProps,
  3. GetServerSidePropsContext,
  4. NextPage,
  5. } from 'next';
  6. import dynamic from 'next/dynamic';
  7. import Head from 'next/head';
  8. import { useTranslation } from 'next-i18next';
  9. import type { CrowiRequest } from '~/interfaces/crowi-request';
  10. import type { CommonProps } from '~/pages/utils/commons';
  11. import { generateCustomTitle } from '~/pages/utils/commons';
  12. import { useCurrentUser, useSiteUrl } from '~/stores-universal/context';
  13. import { retrieveServerSideProps } from '../../utils/admin-page-util';
  14. const AdminLayout = dynamic(() => import('~/components/Layout/AdminLayout'), {
  15. ssr: false,
  16. });
  17. const SlackIntegration = dynamic(
  18. () =>
  19. import('~/client/components/Admin/SlackIntegration/SlackIntegration').then(
  20. (mod) => mod.SlackIntegration,
  21. ),
  22. { ssr: false },
  23. );
  24. const ForbiddenPage = dynamic(
  25. () =>
  26. import('~/client/components/Admin/ForbiddenPage').then(
  27. (mod) => mod.ForbiddenPage,
  28. ),
  29. { ssr: false },
  30. );
  31. type Props = CommonProps & {
  32. siteUrl: string;
  33. };
  34. const AdminSlackIntegrationPage: NextPage<Props> = (props) => {
  35. const { t } = useTranslation('admin');
  36. useCurrentUser(props.currentUser ?? null);
  37. useSiteUrl(props.siteUrl);
  38. const componentTitle = t('slack_integration.slack_integration');
  39. const pageTitle = generateCustomTitle(props, componentTitle);
  40. if (props.isAccessDeniedForNonAdminUser) {
  41. return <ForbiddenPage />;
  42. }
  43. return (
  44. <AdminLayout componentTitle={componentTitle}>
  45. <Head>
  46. <title>{pageTitle}</title>
  47. </Head>
  48. <SlackIntegration />
  49. </AdminLayout>
  50. );
  51. };
  52. const injectServerConfigurations = async (
  53. context: GetServerSidePropsContext,
  54. props: Props,
  55. ): Promise<void> => {
  56. const req: CrowiRequest = context.req as CrowiRequest;
  57. const { crowi } = req;
  58. const { growiInfoService } = crowi;
  59. props.siteUrl = growiInfoService.getSiteUrl();
  60. };
  61. export const getServerSideProps: GetServerSideProps = async (
  62. context: GetServerSidePropsContext,
  63. ) => {
  64. const props = await retrieveServerSideProps(
  65. context,
  66. injectServerConfigurations,
  67. );
  68. return props;
  69. };
  70. export default AdminSlackIntegrationPage;