DescendantsPageListModal.tsx 3.4 KB

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