import { FC, useCallback, useMemo, useState } from "react"; import { Plus } from "lucide-react"; // hooks import { useIssueDetail } from "hooks/store"; // ui import { TOAST_TYPE, setToast } from "@plane/ui"; // components import { IssueLinkCreateUpdateModal } from "./create-update-link-modal"; import { IssueLinkList } from "./links"; // types import { TIssueLink } from "@plane/types"; export type TLinkOperations = { create: (data: Partial) => Promise; update: (linkId: string, data: Partial) => Promise; remove: (linkId: string) => Promise; }; export type TIssueLinkRoot = { workspaceSlug: string; projectId: string; issueId: string; disabled?: boolean; }; export const IssueLinkRoot: FC = (props) => { // props const { workspaceSlug, projectId, issueId, disabled = false } = props; // hooks const { toggleIssueLinkModal: toggleIssueLinkModalStore, createLink, updateLink, removeLink } = useIssueDetail(); // state const [isIssueLinkModal, setIsIssueLinkModal] = useState(false); const toggleIssueLinkModal = useCallback( (modalToggle: boolean) => { toggleIssueLinkModalStore(modalToggle); setIsIssueLinkModal(modalToggle); }, [toggleIssueLinkModalStore] ); const handleLinkOperations: TLinkOperations = useMemo( () => ({ create: async (data: Partial) => { try { if (!workspaceSlug || !projectId || !issueId) throw new Error("Missing required fields"); await createLink(workspaceSlug, projectId, issueId, data); setToast({ message: "The link has been successfully created", type: TOAST_TYPE.SUCCESS, title: "Link created", }); toggleIssueLinkModal(false); } catch (error) { setToast({ message: "The link could not be created", type: TOAST_TYPE.ERROR, title: "Link not created", }); } }, update: async (linkId: string, data: Partial) => { try { if (!workspaceSlug || !projectId || !issueId) throw new Error("Missing required fields"); await updateLink(workspaceSlug, projectId, issueId, linkId, data); setToast({ message: "The link has been successfully updated", type: TOAST_TYPE.SUCCESS, title: "Link updated", }); toggleIssueLinkModal(false); } catch (error) { setToast({ message: "The link could not be updated", type: TOAST_TYPE.ERROR, title: "Link not updated", }); } }, remove: async (linkId: string) => { try { if (!workspaceSlug || !projectId || !issueId) throw new Error("Missing required fields"); await removeLink(workspaceSlug, projectId, issueId, linkId); setToast({ message: "The link has been successfully removed", type: TOAST_TYPE.SUCCESS, title: "Link removed", }); toggleIssueLinkModal(false); } catch (error) { setToast({ message: "The link could not be removed", type: TOAST_TYPE.ERROR, title: "Link not removed", }); } }, }), [workspaceSlug, projectId, issueId, createLink, updateLink, removeLink, toggleIssueLinkModal] ); return ( <>

Links

{!disabled && ( )}
); };