import React, { useState } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; import { Controller, useFormContext } from "react-hook-form"; // hooks import useUser from "hooks/use-user"; import { useProjectMyMembership } from "contexts/project-member.context"; import useEstimateOption from "hooks/use-estimate-option"; // fetch keys import { ISSUE_DETAILS, PROJECT_ISSUES_ACTIVITY } from "constants/fetch-keys"; // icons import { PlayIcon, User, X, CalendarDays, LayoutGrid, Users, CopyPlus } from "lucide-react"; //services import { IssueService } from "services/issue"; // components import { Button, DiceIcon, BlockedIcon, BlockerIcon, RelatedIcon, ContrastIcon } from "@plane/ui"; import { Label, StateSelect, PrioritySelect, AssigneeSelect, EstimateSelect, ParentSelect, BlockerSelect, BlockedBySelect, RelatesSelect, DuplicateSelect, ModuleSelect, CycleSelect, DateSelector, } from "components/web-view"; // types import type { IIssue } from "types"; type Props = { submitChanges: (data: Partial) => Promise; }; const issueService = new IssueService(); export const IssuePropertiesDetail: React.FC = (props) => { const { submitChanges } = props; const { watch, control } = useFormContext(); const blockerIssues = watch("issue_relations")?.filter((i) => i.relation_type === "blocked_by") || []; const blockedByIssues = watch("related_issues")?.filter((i) => i.relation_type === "blocked_by"); const relatedToIssueRelation = [ ...(watch("related_issues")?.filter((i) => i.relation_type === "relates_to") ?? []), ...(watch("issue_relations") ?? []) ?.filter((i) => i.relation_type === "relates_to") .map((i) => ({ ...i, issue_detail: i.issue_detail, related_issue: i.issue_detail?.id, })), ]; 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, })), ]; const startDate = watch("start_date"); const router = useRouter(); const { workspaceSlug, projectId, issueId } = router.query; const isArchive = Boolean(router.query.archive); const { memberRole } = useProjectMyMembership(); const { user } = useUser(); const [isViewAllOpen, setIsViewAllOpen] = useState(false); const { isEstimateActive } = useEstimateOption(); return (
State
( submitChanges({ state: val })} /> )} />
Priority
( submitChanges({ priority: val })} /> )} />
Assignee
( { const assignees = value?.includes(val) ? value?.filter((i) => i !== val) : [...(value ?? []), val]; submitChanges({ assignees_list: assignees }); }} /> )} />
{isViewAllOpen && ( <> {isEstimateActive && (
Estimate
( submitChanges({ estimate_point: val })} /> )} />
)}
Parent
( submitChanges({ parent: val })} /> )} />
{/* blocker to / blocking */}
Blocking
{blockerIssues && blockerIssues.map((relation) => (
console.log( "issue", JSON.stringify({ issue_id: relation.issue_detail?.id, project_id: relation.issue_detail?.project_detail.id, issue_identifier: `${relation.issue_detail?.project_detail.identifier}-${relation.issue_detail?.sequence_id}` }) ) } className="flex items-center gap-1" > {`${relation.issue_detail?.project_detail.identifier}-${relation.issue_detail?.sequence_id}`} {!isArchive && ( )}
))}
{/* blocked by */}
Blocked by
{blockedByIssues && blockedByIssues.map((relation) => (
console.log( "issue", JSON.stringify({ issue_id: relation.issue_detail?.id, project_id: relation.issue_detail?.project_detail.id, issue_identifier: `${relation.issue_detail?.project_detail.identifier}-${relation.issue_detail?.sequence_id}` }) ) } className="flex items-center gap-1" > {`${relation?.issue_detail?.project_detail?.identifier}-${relation?.issue_detail?.sequence_id}`} {!isArchive && !(memberRole.isGuest || memberRole.isViewer) && ( )}
))}
{/* duplicate */}
Duplicate
{duplicateIssuesRelation && duplicateIssuesRelation.map((relation) => (
console.log( "issue", JSON.stringify({ issue_id: relation.issue_detail?.id, project_id: relation.issue_detail?.project_detail.id, issue_identifier: `${relation.issue_detail?.project_detail.identifier}-${relation.issue_detail?.sequence_id}` }) ) } className="flex items-center gap-1" > {`${relation?.issue_detail?.project_detail?.identifier}-${relation?.issue_detail?.sequence_id}`} {!isArchive && !(memberRole.isGuest || memberRole.isViewer) && ( )}
))}
{/* relates to */}
Relates To
{relatedToIssueRelation && relatedToIssueRelation.map((relation) => (
console.log( "issue", JSON.stringify({ issue_id: relation.issue_detail?.id, project_id: relation.issue_detail?.project_detail.id, issue_identifier: `${relation.issue_detail?.project_detail.identifier}-${relation.issue_detail?.sequence_id}` }) ) } className="flex items-center gap-1" > {`${relation?.issue_detail?.project_detail?.identifier}-${relation?.issue_detail?.sequence_id}`} {!isArchive && !(memberRole.isGuest || memberRole.isViewer) && ( )}
))}
Due date
( submitChanges({ target_date: val, }) } className="border-transparent !shadow-none !w-[6.75rem]" minDate={startDate ? new Date(startDate) : undefined} /> )} />
Module
Cycle
)}
); };