DescendantsPageListModal.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import React, { useState, useMemo } from 'react';
  2. import { useTranslation } from 'next-i18next';
  3. import dynamic from 'next/dynamic';
  4. import {
  5. Modal, ModalHeader, ModalBody,
  6. } from 'reactstrap';
  7. import { useIsSharedUser } from '~/stores/context';
  8. import { useDescendantsPageListModal } from '~/stores/modal';
  9. import { CustomNavTab } from './CustomNavigation/CustomNav';
  10. import CustomTabContent from './CustomNavigation/CustomTabContent';
  11. import { DescendantsPageListProps } from './DescendantsPageList';
  12. import ExpandOrContractButton from './ExpandOrContractButton';
  13. import PageListIcon from './Icons/PageListIcon';
  14. import TimeLineIcon from './Icons/TimeLineIcon';
  15. import styles from './DescendantsPageListModal.module.scss';
  16. const DescendantsPageList = (props: DescendantsPageListProps): JSX.Element => {
  17. const DescendantsPageList = dynamic<DescendantsPageListProps>(() => import('./DescendantsPageList').then(mod => mod.DescendantsPageList), { ssr: false });
  18. return <DescendantsPageList {...props}/>;
  19. };
  20. const PageTimeline = (): JSX.Element => {
  21. const PageTimeline = dynamic(() => import('./PageTimeline').then(mod => mod.PageTimeline), { ssr: false });
  22. return <PageTimeline />;
  23. };
  24. export const DescendantsPageListModal = (): JSX.Element => {
  25. const { t } = useTranslation();
  26. const [activeTab, setActiveTab] = useState('pagelist');
  27. const [isWindowExpanded, setIsWindowExpanded] = useState(false);
  28. const { data: isSharedUser } = useIsSharedUser();
  29. const { data: status, close } = useDescendantsPageListModal();
  30. const navTabMapping = useMemo(() => {
  31. return {
  32. pagelist: {
  33. Icon: PageListIcon,
  34. Content: () => {
  35. if (status == null || status.path == null || !status.isOpened) {
  36. return <></>;
  37. }
  38. return <DescendantsPageList path={status.path} />;
  39. },
  40. i18n: t('page_list'),
  41. index: 0,
  42. isLinkEnabled: () => !isSharedUser,
  43. },
  44. timeline: {
  45. Icon: TimeLineIcon,
  46. Content: () => {
  47. if (status == null || !status.isOpened) {
  48. return <></>;
  49. }
  50. return <PageTimeline />;
  51. },
  52. i18n: t('Timeline View'),
  53. index: 1,
  54. isLinkEnabled: () => !isSharedUser,
  55. },
  56. };
  57. }, [isSharedUser, status, t]);
  58. const buttons = useMemo(() => (
  59. <div className="d-flex flex-nowrap">
  60. <ExpandOrContractButton
  61. isWindowExpanded={isWindowExpanded}
  62. expandWindow={() => setIsWindowExpanded(true)}
  63. contractWindow={() => setIsWindowExpanded(false)}
  64. />
  65. <button type="button" className="close" onClick={close} aria-label="Close">
  66. <span aria-hidden="true">&times;</span>
  67. </button>
  68. </div>
  69. ), [close, isWindowExpanded]);
  70. if (status == null) {
  71. return <></>;
  72. }
  73. const { isOpened } = status;
  74. return (
  75. <Modal
  76. size="xl"
  77. isOpen={isOpened}
  78. toggle={close}
  79. data-testid="page-accessories-modal"
  80. className={`grw-page-accessories-modal ${styles['grw-page-accessories-modal']} ${isWindowExpanded ? 'grw-modal-expanded' : ''} `}
  81. >
  82. <ModalHeader className="p-0" toggle={close} close={buttons}>
  83. <CustomNavTab
  84. activeTab={activeTab}
  85. navTabMapping={navTabMapping}
  86. breakpointToHideInactiveTabsDown="md"
  87. onNavSelected={v => setActiveTab(v)}
  88. hideBorderBottom
  89. />
  90. </ModalHeader>
  91. <ModalBody>
  92. <CustomTabContent activeTab={activeTab} navTabMapping={navTabMapping} />
  93. </ModalBody>
  94. </Modal>
  95. );
  96. };