import React from "react"; import { observer } from "mobx-react"; import Link from "next/link"; import { Pencil, X } from "lucide-react"; // hooks // components import { TOAST_TYPE, Tooltip, setToast } from "@plane/ui"; import { ParentIssuesListModal } from "@/components/issues"; // ui // helpers import { cn } from "@/helpers/common.helper"; import { useIssueDetail, useProject } from "@/hooks/store"; import { usePlatformOS } from "@/hooks/use-platform-os"; // types import { TIssueOperations } from "./root"; type TIssueParentSelect = { className?: string; disabled?: boolean; issueId: string; issueOperations: TIssueOperations; projectId: string; workspaceSlug: string; }; export const IssueParentSelect: React.FC = observer((props) => { const { className = "", disabled = false, issueId, issueOperations, projectId, workspaceSlug } = props; // store hooks const { getProjectById } = useProject(); const { issue: { getIssueById }, } = useIssueDetail(); const { isParentIssueModalOpen, toggleParentIssueModal, removeSubIssue, subIssues: { setSubIssueHelpers, fetchSubIssues }, } = useIssueDetail(); // derived values const issue = getIssueById(issueId); const parentIssue = issue?.parent_id ? getIssueById(issue.parent_id) : undefined; const parentIssueProjectDetails = parentIssue && parentIssue.project_id ? getProjectById(parentIssue.project_id) : undefined; const { isMobile } = usePlatformOS(); const handleParentIssue = async (_issueId: string | null = null) => { try { await issueOperations.update(workspaceSlug, projectId, issueId, { parent_id: _issueId }); await issueOperations.fetch(workspaceSlug, projectId, issueId); _issueId && (await fetchSubIssues(workspaceSlug, projectId, _issueId)); toggleParentIssueModal(null); } catch (error) { console.error("something went wrong while fetching the issue"); } }; const handleRemoveSubIssue = async ( workspaceSlug: string, projectId: string, parentIssueId: string, issueId: string ) => { try { setSubIssueHelpers(parentIssueId, "issue_loader", issueId); await removeSubIssue(workspaceSlug, projectId, parentIssueId, issueId); await fetchSubIssues(workspaceSlug, projectId, parentIssueId); setSubIssueHelpers(parentIssueId, "issue_loader", issueId); } catch (error) { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Something went wrong", }); } }; if (!issue) return <>; return ( <> toggleParentIssueModal(null)} onChange={(issue: any) => handleParentIssue(issue?.id)} /> ); });