import React, { FC } from 'react'; import { useTranslation } from 'react-i18next'; import { DevidedPagePath } from '@growi/core'; import { IPageHasId } from '~/interfaces/page'; import { useCurrentPagePath, useIsSharedUser } from '~/stores/context'; import { useDescendantsPageListModal } from '~/stores/modal'; import { useSWRxPageInfoForList } from '~/stores/page'; import PageListIcon from './Icons/PageListIcon'; import { PageListItemL } from './PageList/PageListItemL'; type IdenticalPathAlertProps = { path? : string | null, } const IdenticalPathAlert : FC = (props: IdenticalPathAlertProps) => { const { path } = props; const { t } = useTranslation(); let _path = '――'; let _pageName = '――'; if (path != null) { const devidedPath = new DevidedPagePath(path); _path = devidedPath.isFormerRoot ? '/' : devidedPath.former; _pageName = devidedPath.latter; } return (
{t('duplicated_page_alert.same_page_name_exists', { pageName: _pageName })}

{t('duplicated_page_alert.same_page_name_exists_at_path', { path: _path, pageName: _pageName })}

{t('duplicated_page_alert.select_page_to_see')}

); }; type IdenticalPathPageProps= { // add props and types here } const jsonNull = 'null'; const IdenticalPathPage:FC = (props: IdenticalPathPageProps) => { const { t } = useTranslation(); const identicalPageDocument = document.getElementById('identical-path-page'); const pages = JSON.parse(identicalPageDocument?.getAttribute('data-identical-path-pages') || jsonNull) as IPageHasId[]; const pageIds = pages.map(page => page._id) as string[]; const { data: currentPath } = useCurrentPagePath(); const { data: isSharedUser } = useIsSharedUser(); const { injectTo } = useSWRxPageInfoForList(pageIds, true, true); const { open: openDescendantPageListModal } = useDescendantsPageListModal(); const injectedPages = injectTo(pages); return (
{ currentPath != null && !isSharedUser && ( ) }
    {injectedPages.map((pageWithMeta) => { const pageId = pageWithMeta.data._id; return ( ); })}
); }; export default IdenticalPathPage;