|
|
@@ -1,6 +1,7 @@
|
|
|
-import React, { useEffect, useMemo, useState } from 'react';
|
|
|
+import React, { useMemo, useState } from 'react';
|
|
|
|
|
|
import { useTranslation } from 'next-i18next';
|
|
|
+import dynamic from 'next/dynamic';
|
|
|
import {
|
|
|
Modal, ModalBody, ModalHeader,
|
|
|
} from 'reactstrap';
|
|
|
@@ -16,21 +17,21 @@ import ExpandOrContractButton from '../ExpandOrContractButton';
|
|
|
import AttachmentIcon from '../Icons/AttachmentIcon';
|
|
|
import HistoryIcon from '../Icons/HistoryIcon';
|
|
|
import ShareLinkIcon from '../Icons/ShareLinkIcon';
|
|
|
-import PageAttachment from '../PageAttachment';
|
|
|
-import { PageHistory, getQueryParam } from '../PageHistory';
|
|
|
-import ShareLink from '../ShareLink/ShareLink';
|
|
|
|
|
|
-import { useOpenModalByQueryParam } from './open-modal-by-query-param';
|
|
|
+import { useAutoOpenModalByQueryParam } from './hooks';
|
|
|
|
|
|
import styles from './PageAccessoriesModal.module.scss';
|
|
|
|
|
|
+
|
|
|
+const PageAttachment = dynamic(() => import('./PageAttachment'), { ssr: false });
|
|
|
+const PageHistory = dynamic(() => import('./PageHistory').then(mod => mod.PageHistory), { ssr: false });
|
|
|
+const ShareLink = dynamic(() => import('./ShareLink').then(mod => mod.ShareLink), { ssr: false });
|
|
|
+
|
|
|
+
|
|
|
export const PageAccessoriesModal = (): JSX.Element => {
|
|
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
- const [sourceRevisionId, setSourceRevisionId] = useState<string>();
|
|
|
- const [targetRevisionId, setTargetRevisionId] = useState<string>();
|
|
|
-
|
|
|
const [isWindowExpanded, setIsWindowExpanded] = useState(false);
|
|
|
|
|
|
const { data: isSharedUser } = useIsSharedUser();
|
|
|
@@ -40,35 +41,14 @@ export const PageAccessoriesModal = (): JSX.Element => {
|
|
|
|
|
|
const { data: status, close, selectContents } = usePageAccessoriesModal();
|
|
|
|
|
|
- useOpenModalByQueryParam();
|
|
|
-
|
|
|
- // Set sourceRevisionId and targetRevisionId as state with valid object id string
|
|
|
- useEffect(() => {
|
|
|
- const queryParams = getQueryParam();
|
|
|
- // https://regex101.com/r/YHTDsr/1
|
|
|
- const regex = /^([0-9a-f]{24})...([0-9a-f]{24})$/i;
|
|
|
-
|
|
|
- if (queryParams == null || !regex.test(queryParams)) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const matches = queryParams.match(regex);
|
|
|
-
|
|
|
- if (matches == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const [, sourceRevisionId, targetRevisionId] = matches;
|
|
|
- setSourceRevisionId(sourceRevisionId);
|
|
|
- setTargetRevisionId(targetRevisionId);
|
|
|
- }, []);
|
|
|
+ useAutoOpenModalByQueryParam();
|
|
|
|
|
|
const navTabMapping = useMemo(() => {
|
|
|
return {
|
|
|
[PageAccessoriesModalContents.PageHistory]: {
|
|
|
Icon: HistoryIcon,
|
|
|
Content: () => {
|
|
|
- return <PageHistory onClose={close} sourceRevisionId={sourceRevisionId} targetRevisionId={targetRevisionId}/>;
|
|
|
+ return <PageHistory onClose={close} />;
|
|
|
},
|
|
|
i18n: t('History'),
|
|
|
isLinkEnabled: () => !isGuestUser && !isSharedUser,
|
|
|
@@ -89,7 +69,7 @@ export const PageAccessoriesModal = (): JSX.Element => {
|
|
|
isLinkEnabled: () => !isGuestUser && !isReadOnlyUser && !isSharedUser && !isLinkSharingDisabled,
|
|
|
},
|
|
|
};
|
|
|
- }, [t, close, sourceRevisionId, targetRevisionId, isGuestUser, isReadOnlyUser, isSharedUser, isLinkSharingDisabled]);
|
|
|
+ }, [t, close, isGuestUser, isReadOnlyUser, isSharedUser, isLinkSharingDisabled]);
|
|
|
|
|
|
const buttons = useMemo(() => (
|
|
|
<div className="d-flex flex-nowrap">
|