// react import React, { useState } from "react"; // next import { useRouter } from "next/router"; // swr import { mutate } from "swr"; // react hook forms import { Control, Controller, useWatch } from "react-hook-form"; // services import issuesService from "services/issues.service"; // hooks import useUser from "hooks/use-user"; // fetch keys import { ISSUE_DETAILS } from "constants/fetch-keys"; // icons import { BlockedIcon, BlockerIcon } from "components/icons"; import { ChevronDown, PlayIcon, User, X, CalendarDays, LayoutGrid, Users } from "lucide-react"; // hooks import useEstimateOption from "hooks/use-estimate-option"; // ui import { SecondaryButton, CustomDatePicker } from "components/ui"; // components import { Label, StateSelect, PrioritySelect, AssigneeSelect, EstimateSelect, ParentSelect, BlockerSelect, BlockedSelect, } from "components/web-view"; // types import type { IIssue } from "types"; type Props = { control: Control; submitChanges: (data: Partial) => Promise; }; export const IssuePropertiesDetail: React.FC = (props) => { const { control, submitChanges } = props; const blockerIssue = useWatch({ control, name: "issue_relations", })?.filter((i) => i.relation_type === "blocked_by") || []; const blockedIssue = useWatch({ control, name: "related_issues", })?.filter((i) => i.relation_type === "blocked_by"); const startDate = useWatch({ control, name: "start_date", }); const router = useRouter(); const { workspaceSlug, projectId, issueId } = router.query; const { user } = useUser(); const [isViewAllOpen, setIsViewAllOpen] = useState(false); const { isEstimateActive } = useEstimateOption(); const handleMutation = (data: any) => { mutate( ISSUE_DETAILS(issueId as string), (prevData) => { if (!prevData) return prevData; return { ...prevData, ...data, }; }, false ); }; return (
State
( submitChanges({ state: val })} /> )} />
Priority
( submitChanges({ priority: val })} /> )} />
Assignee
( submitChanges({ assignees_list: [val] })} /> )} />
{isViewAllOpen && ( <> {isEstimateActive && (
Estimate
( submitChanges({ estimate_point: val })} /> )} />
)}
Parent
( submitChanges({ parent: val })} /> )} />
Blocking
{ if (!user || !workspaceSlug || !projectId || !issueId) return; issuesService .createIssueRelation( workspaceSlug as string, projectId as string, issueId as string, user, { related_list: [ ...val.map((issue: any) => ({ issue: issue.blocker_issue_detail.id, relation_type: "blocked_by" as const, related_issue: issueId as string, related_issue_detail: issue.blocker_issue_detail, })), ], } ) .then((response) => { handleMutation({ issue_relations: [ ...blockerIssue, ...(response ?? []).map((i: any) => ({ id: i.id, relation_type: i.relation_type, issue_detail: i.related_issue_detail, issue: i.related_issue, })), ], }); }); }} />
{blockerIssue && blockerIssue.map((issue) => (
{`${issue.issue_detail?.project_detail.identifier}-${issue.issue_detail?.sequence_id}`}
))}
Blocked by
{ if (!user || !workspaceSlug || !projectId || !issueId) return; issuesService .createIssueRelation( workspaceSlug as string, projectId as string, issueId as string, user, { related_list: [ ...val.map((issue: any) => ({ issue: issue.blocked_issue_detail.id, relation_type: "blocked_by" as const, related_issue: issueId as string, related_issue_detail: issue.blocked_issue_detail, })), ], } ) .then((response) => { handleMutation({ related_issues: [ ...blockedIssue, ...(response ?? []).map((i: any) => ({ id: i.id, relation_type: i.relation_type, issue_detail: i.related_issue_detail, issue: i.related_issue, })), ], }); }); }} />
{blockedIssue && blockedIssue.map((issue) => (
{`${issue?.issue_detail?.project_detail?.identifier}-${issue?.issue_detail?.sequence_id}`}
))}
Due date
( submitChanges({ target_date: val, }) } className="border-transparent !shadow-none !w-[6.75rem]" minDate={startDate ? new Date(startDate) : undefined} /> )} />
)}
setIsViewAllOpen((prev) => !prev)} className="w-full flex justify-center items-center gap-1 !py-2" > {isViewAllOpen ? "View less" : "View all"}
); };