Skip to content

Commit

Permalink
ExternalLinkModal in PresentationLinksCard
Browse files Browse the repository at this point in the history
  • Loading branch information
adamodd committed Jan 22, 2025
1 parent a766613 commit 9c8879d
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/views/GovernanceReviewTeam/GRBReview/PresentationLinksCard.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -53,6 +54,8 @@ function PresentationLinksCard({
transcriptFileStatus === SystemIntakeDocumentStatus.UNAVAILABLE &&
presentationDeckFileStatus === SystemIntakeDocumentStatus.UNAVAILABLE);

// Remove links handling

const [deleteSystemIntakeGRBPresentationLinks] =
useDeleteSystemIntakeGRBPresentationLinksMutation({
variables: {
Expand Down Expand Up @@ -84,6 +87,35 @@ function PresentationLinksCard({
});
};

// External link modal handling

const [externalUrl, setExternalUrl] = useState<string>('');
const [isExternalModalOpen, setExternalModalOpen] = useState<boolean>(false);

const externalModalScopeRef = useRef<HTMLDivElement>(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;

Expand Down Expand Up @@ -132,7 +164,10 @@ function PresentationLinksCard({
</CardBody>
<CardFooter>
{!isEmpty && (
<div className="display-flex flex-wrap border-top-1px border-gray-10 padding-top-2">
<div
ref={externalModalScopeRef}
className="presentation-card-links display-flex flex-wrap border-top-1px border-gray-10 padding-top-2"
>
{recordingLink && (
<Link
className="margin-right-2 display-flex flex-align-center"
Expand Down Expand Up @@ -205,6 +240,13 @@ function PresentationLinksCard({
</Button>
</ButtonGroup>
</Modal>

{/* Modal for external links */}
<ExternalLinkModal
isOpen={isExternalModalOpen}
url={externalUrl}
closeModal={() => setExternalModalOpen(false)}
/>
</>
);
}
Expand Down

0 comments on commit 9c8879d

Please sign in to comment.