// react import React, { useState } from "react"; // next import Link from "next/link"; import { useRouter } from "next/router"; // swr import { mutate } from "swr"; // services import issuesService from "services/issues.service"; // icons // import { LinkIcon, PlusIcon, PencilIcon, TrashIcon } from "@heroicons/react/24/outline"; import { Link as LinkIcon, Plus, Pencil, X } from "lucide-react"; // components import { Label, WebViewModal, CreateUpdateLinkForm } from "components/web-view"; // ui import { SecondaryButton } from "components/ui"; // fetch keys import { ISSUE_DETAILS } from "constants/fetch-keys"; // types import type { IIssue } from "types"; type Props = { allowed: boolean; issueDetails: IIssue; }; export const IssueLinks: React.FC = (props) => { const { issueDetails, allowed } = props; const links = issueDetails?.issue_link; const [isOpen, setIsOpen] = useState(false); const [selectedLink, setSelectedLink] = useState(null); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const handleDeleteLink = async (linkId: string) => { if (!workspaceSlug || !projectId || !issueDetails) return; const updatedLinks = issueDetails.issue_link.filter((l) => l.id !== linkId); mutate( ISSUE_DETAILS(issueDetails.id), (prevData) => ({ ...(prevData as IIssue), issue_link: updatedLinks }), false ); await issuesService .deleteIssueLink(workspaceSlug as string, projectId as string, issueDetails.id, linkId) .then((res) => { mutate(ISSUE_DETAILS(issueDetails.id)); }) .catch((err) => { console.log(err); }); }; return (
{ setIsOpen(false); setSelectedLink(null); }} modalTitle={selectedLink ? "Update Link" : "Add Link"} > { setIsOpen(false); setSelectedLink(null); }} data={links?.find((link) => link.id === selectedLink)} />
{links?.map((link) => (
{link.title} {allowed && (
)}
))} setIsOpen(true)} className="w-full !py-2 text-custom-text-300 !text-base flex items-center justify-center" > Add
); };