customize.page.tsx 2.5 KB

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