customize.page.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import type { GetServerSideProps, GetServerSidePropsContext } from 'next';
  2. import dynamic from 'next/dynamic';
  3. import { useHydrateAtoms } from 'jotai/utils';
  4. import type { CrowiRequest } from '~/interfaces/crowi-request';
  5. import { isCustomizedLogoUploadedAtom } from '~/states/server-configurations';
  6. import type { NextPageWithLayout } from '../_app.page';
  7. import { mergeGetServerSidePropsResults } from '../utils/server-side-props';
  8. import type { AdminCommonProps } from './_shared';
  9. import {
  10. createAdminPageLayout,
  11. getServerSideAdminCommonProps,
  12. } from './_shared';
  13. const CustomizeSettingContents = dynamic(
  14. // biome-ignore lint/style/noRestrictedImports: no-problem dynamic import
  15. () => import('~/client/components/Admin/Customize/Customize'),
  16. { ssr: false },
  17. );
  18. type PageProps = {
  19. isCustomizedLogoUploaded: boolean;
  20. customTitleTemplate?: string;
  21. };
  22. type Props = AdminCommonProps & PageProps;
  23. // eslint-disable-next-line react/prop-types
  24. const AdminCustomizeSettingsPage: NextPageWithLayout<Props> = (
  25. props: Props,
  26. ) => {
  27. useHydrateAtoms(
  28. [[isCustomizedLogoUploadedAtom, props.isCustomizedLogoUploaded]],
  29. { dangerouslyForceHydrate: true },
  30. );
  31. return <CustomizeSettingContents />;
  32. };
  33. AdminCustomizeSettingsPage.getLayout = createAdminPageLayout<Props>({
  34. title: (_p, t) => t('customize_settings.customize_settings'),
  35. containerFactories: [
  36. async () => {
  37. // biome-ignore lint/style/noRestrictedImports: no-problem dynamic import
  38. const C = (await import('~/client/services/AdminCustomizeContainer'))
  39. .default;
  40. return new C();
  41. },
  42. ],
  43. });
  44. export const getServerSideProps: GetServerSideProps<Props> = async (
  45. context: GetServerSidePropsContext,
  46. ) => {
  47. const commonResult = await getServerSideAdminCommonProps(context);
  48. const req: CrowiRequest = context.req as CrowiRequest;
  49. const { crowi } = req;
  50. const customizePropsFragment = {
  51. props: {
  52. isCustomizedLogoUploaded:
  53. await crowi.attachmentService.isBrandLogoExist(),
  54. },
  55. } satisfies { props: PageProps };
  56. return mergeGetServerSidePropsResults(commonResult, customizePropsFragment);
  57. };
  58. export default AdminCustomizeSettingsPage;