// next import Link from "next/link"; import Image from "next/image"; // react-beautiful-dnd import { DraggableStateSnapshot } from "react-beautiful-dnd"; // headless ui import { Listbox, Transition } from "@headlessui/react"; // icons import { TrashIcon } from "@heroicons/react/24/outline"; import { CalendarDaysIcon } from "@heroicons/react/20/solid"; import User from "public/user.png"; // types import { IIssue, IWorkspaceMember, Properties } from "types"; // common import { addSpaceIfCamelCase, classNames, findHowManyDaysLeft, renderShortNumericDateFormat, } from "constants/common"; // constants import { PRIORITIES } from "constants/"; import useUser from "lib/hooks/useUser"; import React from "react"; type Props = { issue: IIssue; properties: Properties; snapshot?: DraggableStateSnapshot; assignees: { avatar: string | undefined; first_name: string | undefined; email: string | undefined; }[]; people: IWorkspaceMember[] | undefined; handleDeleteIssue?: React.Dispatch>; partialUpdateIssue: (formData: Partial, childIssueId: string) => void; }; const SingleIssue: React.FC = ({ issue, properties, snapshot, assignees, people, handleDeleteIssue, partialUpdateIssue, }) => { const { activeProject, states } = useUser(); return (
{handleDeleteIssue && (
)} {properties.key && (
{activeProject?.identifier}-{issue.sequence_id}
)}
{issue.name}
{properties.priority && ( { partialUpdateIssue({ priority: data }, issue.id); }} className="group relative flex-shrink-0" > {({ open }) => ( <>
{issue.priority ?? "None"} {PRIORITIES?.map((priority) => ( classNames( active ? "bg-indigo-50" : "bg-white", "cursor-pointer capitalize select-none px-3 py-2" ) } value={priority} > {priority} ))}
Priority
{issue.priority ?? "None"}
)}
)} {properties.state && ( { partialUpdateIssue({ state: data }, issue.id); }} className="group relative flex-shrink-0" > {({ open }) => ( <>
{addSpaceIfCamelCase(issue.state_detail.name)} {states?.map((state) => ( classNames( active ? "bg-indigo-50" : "bg-white", "cursor-pointer select-none px-3 py-2" ) } value={state.id} > {addSpaceIfCamelCase(state.name)} ))}
State
{issue.state_detail.name}
)}
)} {properties.start_date && (
{issue.start_date ? renderShortNumericDateFormat(issue.start_date) : "N/A"}
Started at
{renderShortNumericDateFormat(issue.start_date ?? "")}
)} {properties.target_date && (
{issue.target_date ? renderShortNumericDateFormat(issue.target_date) : "N/A"}
Target date
{renderShortNumericDateFormat(issue.target_date ?? "")}
{issue.target_date && (issue.target_date < new Date().toISOString() ? `Target date has passed by ${findHowManyDaysLeft(issue.target_date)} days` : findHowManyDaysLeft(issue.target_date) <= 3 ? `Target date is in ${findHowManyDaysLeft(issue.target_date)} days` : "Target date")}
)} {properties.assignee && ( { const newData = issue.assignees ?? []; if (newData.includes(data)) { newData.splice(newData.indexOf(data), 1); } else { newData.push(data); } partialUpdateIssue({ assignees_list: newData }, issue.id); }} className="group relative flex-shrink-0" > {({ open }) => ( <>
{assignees.length > 0 ? ( assignees.map((assignee, index: number) => (
{assignee.avatar && assignee.avatar !== "" ? (
{assignee?.first_name}
) : (
{assignee.first_name && assignee.first_name !== "" ? assignee.first_name.charAt(0) : assignee?.email?.charAt(0)}
)}
)) ) : (
No user
)}
{people?.map((person) => ( classNames( active ? "bg-indigo-50" : "bg-white", "cursor-pointer select-none p-2" ) } value={person.member.id} >
{person.member.avatar && person.member.avatar !== "" ? (
avatar
) : (
{person.member.first_name && person.member.first_name !== "" ? person.member.first_name.charAt(0) : person.member.email.charAt(0)}
)}

{person.member.first_name && person.member.first_name !== "" ? person.member.first_name : person.member.email}

))}
Assigned to
{issue.assignee_details?.length > 0 ? issue.assignee_details.map((assignee) => assignee.first_name).join(", ") : "No one"}
)}
)}
); }; export default SingleIssue;