import React, { useState } from "react"; import { useRouter } from "next/router"; // react-hook-form import { UseFormWatch } from "react-hook-form"; // hooks import useToast from "hooks/use-toast"; import useUser from "hooks/use-user"; // icons import { X, CopyPlus } from "lucide-react"; // components import { ExistingIssuesListModal } from "components/core"; // services import { IssueService } from "services/issue"; // types import { BlockeIssueDetail, IIssue, ISearchIssueResponse } from "types"; type Props = { issueId?: string; submitChanges: (formData?: Partial) => void; watch: UseFormWatch; disabled?: boolean; }; // services const issueService = new IssueService(); export const SidebarDuplicateSelect: React.FC = (props) => { const { issueId, submitChanges, watch, disabled = false } = props; const [isDuplicateModalOpen, setIsDuplicateModalOpen] = useState(false); const { user } = useUser(); const { setToastAlert } = useToast(); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const handleClose = () => { setIsDuplicateModalOpen(false); }; const onSubmit = async (data: ISearchIssueResponse[]) => { if (data.length === 0) { setToastAlert({ type: "error", title: "Error!", message: "Please select at least one issue.", }); return; } const selectedIssues: { blocker_issue_detail: BlockeIssueDetail }[] = data.map((i) => ({ blocker_issue_detail: { id: i.id, name: i.name, sequence_id: i.sequence_id, project_detail: { id: i.project_id, identifier: i.project__identifier, name: i.project__name, }, }, })); if (!user) return; issueService .createIssueRelation(workspaceSlug as string, projectId as string, issueId as string, user, { related_list: [ ...selectedIssues.map((issue) => ({ issue: issueId as string, issue_detail: issue.blocker_issue_detail, related_issue: issue.blocker_issue_detail.id, relation_type: "duplicate" as const, })), ], }) .then(() => { submitChanges(); }); handleClose(); }; const duplicateIssuesRelation = [ ...(watch("related_issues")?.filter((i) => i.relation_type === "duplicate") ?? []), ...(watch("issue_relations") ?? []) ?.filter((i) => i.relation_type === "duplicate") .map((i) => ({ ...i, issue_detail: i.issue_detail, related_issue: i.issue_detail?.id, })), ]; return ( <> setIsDuplicateModalOpen(false)} searchParams={{ issue_relation: true, issue_id: issueId }} handleOnSubmit={onSubmit} workspaceLevelToggle />

Duplicate

{duplicateIssuesRelation && duplicateIssuesRelation.length > 0 ? duplicateIssuesRelation.map((relation) => (
{`${relation.issue_detail?.project_detail.identifier}-${relation.issue_detail?.sequence_id}`}
)) : null}
); };