From 9c8879d8d8d406b2bf4e4f44f3df60782c32d53a Mon Sep 17 00:00:00 2001 From: adamodd Date: Tue, 21 Jan 2025 19:35:42 -0800 Subject: [PATCH] ExternalLinkModal in PresentationLinksCard --- .../GRBReview/PresentationLinksCard.tsx | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/views/GovernanceReviewTeam/GRBReview/PresentationLinksCard.tsx b/src/views/GovernanceReviewTeam/GRBReview/PresentationLinksCard.tsx index 1bfa6e90e..114746cde 100644 --- a/src/views/GovernanceReviewTeam/GRBReview/PresentationLinksCard.tsx +++ b/src/views/GovernanceReviewTeam/GRBReview/PresentationLinksCard.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useState } from 'react'; +import React, { useContext, useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Button, @@ -15,6 +15,7 @@ import { useDeleteSystemIntakeGRBPresentationLinksMutation } from 'gql/gen/graph import UswdsReactLink from 'components/LinkWrapper'; import Modal from 'components/Modal'; import Alert from 'components/shared/Alert'; +import ExternalLinkModal from 'components/shared/ExternalLinkModal'; import IconLink from 'components/shared/IconLink'; import useMessage from 'hooks/useMessage'; import { SystemIntake } from 'queries/types/SystemIntake'; @@ -53,6 +54,8 @@ function PresentationLinksCard({ transcriptFileStatus === SystemIntakeDocumentStatus.UNAVAILABLE && presentationDeckFileStatus === SystemIntakeDocumentStatus.UNAVAILABLE); + // Remove links handling + const [deleteSystemIntakeGRBPresentationLinks] = useDeleteSystemIntakeGRBPresentationLinksMutation({ variables: { @@ -84,6 +87,35 @@ function PresentationLinksCard({ }); }; + // External link modal handling + + const [externalUrl, setExternalUrl] = useState(''); + const [isExternalModalOpen, setExternalModalOpen] = useState(false); + + const externalModalScopeRef = useRef(null); + + function linkHandler(event: MouseEvent) { + const a = (event.target as HTMLElement)?.closest( + '.presentation-card-links a' + ); + if (a) { + event.preventDefault(); + const href = a.getAttribute('href'); + if (href) { + setExternalUrl(href); + setExternalModalOpen(true); + } + } + } + + useEffect(() => { + const eventEl = externalModalScopeRef.current; + eventEl?.addEventListener('click', linkHandler); + return () => { + eventEl?.removeEventListener('click', linkHandler); + }; + }, []); + // Render empty if not an admin and no links if (!isITGovAdmin && isEmpty) return null; @@ -132,7 +164,10 @@ function PresentationLinksCard({ {!isEmpty && ( -
+
{recordingLink && ( + + {/* Modal for external links */} + setExternalModalOpen(false)} + /> ); }