DescendantsPageListModal.tsx 2.8 KB

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