import React from "react"; // next import Link from "next/link"; import Image from "next/image"; import { useRouter } from "next/router"; // swr import useSWR from "swr"; // react-beautiful-dnd import { DraggableStateSnapshot } from "react-beautiful-dnd"; // headless ui import { Listbox, Transition } from "@headlessui/react"; // constants import { TrashIcon } from "@heroicons/react/24/outline"; import { CalendarDaysIcon } from "@heroicons/react/20/solid"; // services import issuesService from "services/issues.service"; import stateService from "services/state.service"; import projectService from "services/project.service"; // components import { AssigneesList } from "components/ui/avatar"; // helpers import { renderShortNumericDateFormat, findHowManyDaysLeft } from "helpers/date-time.helper"; import { addSpaceIfCamelCase } from "helpers/string.helper"; // types import { IIssue, IssueResponse, IUserLite, IWorkspaceMember, Properties } from "types"; // common import { PRIORITIES } from "constants/"; import { PROJECT_ISSUES_LIST, STATE_LIST, PROJECT_DETAILS } from "constants/fetch-keys"; import { getPriorityIcon } from "constants/global"; type Props = { issue: IIssue; properties: Properties; snapshot?: DraggableStateSnapshot; assignees: Partial[] | (Partial | undefined)[]; people: IWorkspaceMember[] | undefined; handleDeleteIssue?: React.Dispatch>; partialUpdateIssue: any; }; const SingleBoardIssue: React.FC = ({ issue, properties, snapshot, assignees, people, handleDeleteIssue, partialUpdateIssue, }) => { const router = useRouter(); const { 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 { data: states } = useSWR( workspaceSlug && projectId ? STATE_LIST(projectId as string) : null, workspaceSlug && projectId ? () => stateService.getStates(workspaceSlug as string, projectId as string) : null ); const { data: projectDetails } = useSWR( workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null, workspaceSlug && projectId ? () => projectService.getProject(workspaceSlug as string, projectId as string) : null ); const totalChildren = issues?.results.filter((i) => i.parent === issue.id).length; return (
{handleDeleteIssue && (
)} {properties.key && (
{projectDetails?.identifier}-{issue.sequence_id}
)}
{issue.name}
{properties.priority && ( { partialUpdateIssue({ priority: data }, issue.id); }} className="group relative flex-shrink-0" > {({ open }) => ( <>
{getPriorityIcon(issue?.priority ?? "None")} {PRIORITIES?.map((priority) => ( `flex cursor-pointer select-none items-center gap-2 px-3 py-2 capitalize ${ active ? "bg-indigo-50" : "bg-white" }` } value={priority} > {getPriorityIcon(priority)} {priority} ))}
)}
)} {properties.state && ( { partialUpdateIssue({ state: data }, issue.id); }} className="group relative flex-shrink-0" > {({ open }) => ( <>
{addSpaceIfCamelCase(issue.state_detail.name)} {states?.map((state) => ( `flex cursor-pointer select-none items-center gap-2 px-3 py-2 ${ active ? "bg-indigo-50" : "bg-white" }` } value={state.id} > {addSpaceIfCamelCase(state.name)} ))}
{/*
State
{issue.state_detail.name}
*/} )}
)} {properties.due_date && (
{issue.target_date ? renderShortNumericDateFormat(issue.target_date) : "N/A"}
)} {properties.sub_issue_count && (
{totalChildren} {totalChildren === 1 ? "sub-issue" : "sub-issues"}
)} {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 }) => ( <>
{people?.map((person) => ( `cursor-pointer select-none p-2 ${ active ? "bg-indigo-50" : "bg-white" }` } 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}

))}
)}
)}
); }; export default SingleBoardIssue;