// next import Link from "next/link"; import { useRouter } from "next/router"; import useSWR from "swr"; // services import issuesService from "lib/services/issues.service"; // ui import { CustomMenu } from "ui"; // icons import { CalendarDaysIcon } from "@heroicons/react/24/outline"; // types import { IIssue, IssueResponse, Properties } from "types"; // fetch-keys import { PROJECT_ISSUES_LIST } from "constants/fetch-keys"; // common import { addSpaceIfCamelCase, findHowManyDaysLeft, renderShortNumericDateFormat, } from "constants/common"; type Props = { type?: string; issue: IIssue; properties: Properties; editIssue: () => void; handleDeleteIssue: () => void; removeIssue: () => void; }; const SingleListIssue: React.FC = ({ type, issue, properties, editIssue, handleDeleteIssue, removeIssue, }) => { const router = useRouter(); let { workspaceSlug, projectId } = router.query; const { data: issues } = useSWR( workspaceSlug && projectId ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string) : null, workspaceSlug && projectId ? () => issuesService.getIssues(workspaceSlug as string, projectId as string) : null ); const totalChildren = issues?.results.filter((i) => i.parent === issue.id).length; return ( <>
{properties.key && ( {issue.project_detail?.identifier}-{issue.sequence_id} )} {issue.name}
{properties.priority && (
{/* {getPriorityIcon(issue.priority ?? "")} */} {issue.priority ?? "None"}
Priority
{issue.priority ?? "None"}
)} {properties.state && (
{addSpaceIfCamelCase(issue?.state_detail.name)}
State
{issue?.state_detail.name}
)} {properties.due_date && (
{issue.target_date ? renderShortNumericDateFormat(issue.target_date) : "N/A"}
Due date
{renderShortNumericDateFormat(issue.target_date ?? "")}
{issue.target_date && (issue.target_date < new Date().toISOString() ? `Due date has passed by ${findHowManyDaysLeft(issue.target_date)} days` : findHowManyDaysLeft(issue.target_date) <= 3 ? `Due date is in ${findHowManyDaysLeft(issue.target_date)} days` : "Due date")}
)} {properties.sub_issue_count && projectId && (
{totalChildren} {totalChildren === 1 ? "sub-issue" : "sub-issues"}
)} {type && ( editIssue()}>Edit removeIssue()}> <>Remove from {type} handleDeleteIssue()}> Delete permanently )}
); }; export default SingleListIssue;