import React, { useState, useMemo, useEffect } from 'react'; import { useTranslation } from 'next-i18next'; import dynamic from 'next/dynamic'; import { useRouter } from 'next/router'; import { Modal, ModalHeader, ModalBody, } from 'reactstrap'; import { useIsSharedUser } from '~/stores/context'; import { useDescendantsPageListModal } from '~/stores/modal'; import { CustomNavTab } from './CustomNavigation/CustomNav'; import CustomTabContent from './CustomNavigation/CustomTabContent'; import type { DescendantsPageListProps } from './DescendantsPageList'; import ExpandOrContractButton from './ExpandOrContractButton'; import styles from './DescendantsPageListModal.module.scss'; const DescendantsPageList = dynamic(() => import('./DescendantsPageList').then(mod => mod.DescendantsPageList), { ssr: false }); const PageTimeline = dynamic(() => import('./PageTimeline').then(mod => mod.PageTimeline), { ssr: false }); export const DescendantsPageListModal = (): JSX.Element => { const { t } = useTranslation(); const [activeTab, setActiveTab] = useState('pagelist'); const [isWindowExpanded, setIsWindowExpanded] = useState(false); const { data: isSharedUser } = useIsSharedUser(); const { data: status, close } = useDescendantsPageListModal(); const { events } = useRouter(); useEffect(() => { events.on('routeChangeStart', close); return () => { events.off('routeChangeStart', close); }; }, [close, events]); const navTabMapping = useMemo(() => { return { pagelist: { Icon: () => subject, Content: () => { if (status == null || status.path == null || !status.isOpened) { return <>; } return ; }, i18n: t('page_list'), isLinkEnabled: () => !isSharedUser, }, timeline: { Icon: () => timeline, Content: () => { if (status == null || !status.isOpened) { return <>; } return ; }, i18n: t('Timeline View'), isLinkEnabled: () => !isSharedUser, }, }; }, [isSharedUser, status, t]); const buttons = useMemo(() => ( setIsWindowExpanded(true)} contractWindow={() => setIsWindowExpanded(false)} /> ), [close, isWindowExpanded]); if (status == null) { return <>; } const { isOpened } = status; return ( setActiveTab(v)} hideBorderBottom /> ); };