import React, { useCallback, useEffect } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; import { mutate } from "swr"; // react-beautiful-dnd import { DraggableProvided, DraggableStateSnapshot, DraggingStyle, NotDraggingStyle, } from "react-beautiful-dnd"; // constants import { TrashIcon } from "@heroicons/react/24/outline"; // services import issuesService from "services/issues.service"; // components import { ViewAssigneeSelect, ViewDueDateSelect, ViewPrioritySelect, ViewStateSelect, } from "components/issues/view-select"; // ui import { CustomMenu } from "components/ui"; // types import { CycleIssueResponse, IIssue, IssueResponse, ModuleIssueResponse, NestedKeyOf, Properties, UserAuth, } from "types"; // fetch-keys import { CYCLE_ISSUES, MODULE_ISSUES, PROJECT_ISSUES_LIST } from "constants/fetch-keys"; type Props = { type?: string; provided: DraggableProvided; snapshot: DraggableStateSnapshot; issue: IIssue; selectedGroup: NestedKeyOf | null; properties: Properties; editIssue: () => void; removeIssue?: (() => void) | null; handleDeleteIssue: (issue: IIssue) => void; orderBy: NestedKeyOf | "manual" | null; handleTrashBox: (isDragging: boolean) => void; userAuth: UserAuth; }; export const SingleBoardIssue: React.FC = ({ type, provided, snapshot, issue, selectedGroup, properties, editIssue, removeIssue, handleDeleteIssue, orderBy, handleTrashBox, userAuth, }) => { const router = useRouter(); const { workspaceSlug, projectId, cycleId, moduleId } = router.query; const partialUpdateIssue = useCallback( (formData: Partial) => { if (!workspaceSlug || !projectId) return; if (cycleId) mutate( CYCLE_ISSUES(cycleId as string), (prevData) => { const updatedIssues = (prevData ?? []).map((p) => { if (p.issue_detail.id === issue.id) { return { ...p, issue_detail: { ...p.issue_detail, ...formData, }, }; } return p; }); return [...updatedIssues]; }, false ); if (moduleId) mutate( MODULE_ISSUES(moduleId as string), (prevData) => { const updatedIssues = (prevData ?? []).map((p) => { if (p.issue_detail.id === issue.id) { return { ...p, issue_detail: { ...p.issue_detail, ...formData, }, }; } return p; }); return [...updatedIssues]; }, false ); mutate( PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string), (prevData) => ({ ...(prevData as IssueResponse), results: (prevData?.results ?? []).map((p) => { if (p.id === issue.id) return { ...p, ...formData }; return p; }), }), false ); issuesService .patchIssue(workspaceSlug as string, projectId as string, issue.id, formData) .then((res) => { if (cycleId) mutate(CYCLE_ISSUES(cycleId as string)); if (moduleId) mutate(MODULE_ISSUES(moduleId as string)); mutate(PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)); }) .catch((error) => { console.log(error); }); }, [workspaceSlug, projectId, cycleId, moduleId, issue] ); function getStyle( style: DraggingStyle | NotDraggingStyle | undefined, snapshot: DraggableStateSnapshot ) { if (orderBy === "manual") return style; if (!snapshot.isDragging) return {}; if (!snapshot.isDropAnimating) { return style; } return { ...style, transitionDuration: `0.001s`, }; } const isNotAllowed = userAuth.isGuest || userAuth.isViewer; useEffect(() => { if (snapshot.isDragging) handleTrashBox(snapshot.isDragging); }, [snapshot, handleTrashBox]); return (
{!isNotAllowed && (
{/* */} {type && !isNotAllowed && ( Edit {type !== "issue" && removeIssue && ( <>Remove from {type} )} handleDeleteIssue(issue)}> Delete permanently )}
)} {properties.key && (
{issue.project_detail.identifier}-{issue.sequence_id}
)}
{issue.name}
{properties.priority && selectedGroup !== "priority" && ( )} {properties.state && selectedGroup !== "state_detail.name" && ( )} {properties.due_date && ( )} {properties.sub_issue_count && (
{issue.sub_issues_count} {issue.sub_issues_count === 1 ? "sub-issue" : "sub-issues"}
)} {properties.assignee && ( )}
); };