// react import React, { useState } from "react"; // next import Link from "next/link"; import Image from "next/image"; // swr import useSWR from "swr"; // react-beautiful-dnd import { Draggable } from "react-beautiful-dnd"; import StrictModeDroppable from "components/dnd/StrictModeDroppable"; // services import workspaceService from "lib/services/workspace.service"; // hooks import useUser from "lib/hooks/useUser"; // headless ui import { Listbox, Transition } from "@headlessui/react"; // icons import { ArrowsPointingInIcon, ArrowsPointingOutIcon, CalendarDaysIcon, EllipsisHorizontalIcon, PlusIcon, TrashIcon, } from "@heroicons/react/24/outline"; import User from "public/user.png"; // common import { PRIORITIES } from "constants/"; import { addSpaceIfCamelCase, classNames, findHowManyDaysLeft, renderShortNumericDateFormat, } from "constants/common"; import { WORKSPACE_MEMBERS } from "constants/fetch-keys"; import { getPriorityIcon } from "constants/global"; // types import { IIssue, Properties, NestedKeyOf, IWorkspaceMember } from "types"; type Props = { selectedGroup: NestedKeyOf | null; groupTitle: string; groupedByIssues: { [key: string]: IIssue[]; }; index: number; setIsIssueOpen: React.Dispatch>; properties: Properties; setPreloadedData: React.Dispatch< React.SetStateAction< | (Partial & { actionType: "createIssue" | "edit" | "delete"; }) | undefined > >; bgColor?: string; stateId: string | null; createdBy: string | null; handleDeleteIssue: React.Dispatch>; partialUpdateIssue: (formData: Partial, childIssueId: string) => void; }; const SingleBoard: React.FC = ({ selectedGroup, groupTitle, groupedByIssues, index, setIsIssueOpen, properties, setPreloadedData, bgColor = "#0f2b16", stateId, createdBy, handleDeleteIssue, partialUpdateIssue, }) => { // Collapse/Expand const [show, setShow] = useState(true); const { activeProject, activeWorkspace, states } = useUser(); if (selectedGroup === "priority") groupTitle === "high" ? (bgColor = "#dc2626") : groupTitle === "medium" ? (bgColor = "#f97316") : groupTitle === "low" ? (bgColor = "#22c55e") : (bgColor = "#ff0000"); const { data: people } = useSWR( activeWorkspace ? WORKSPACE_MEMBERS : null, activeWorkspace ? () => workspaceService.workspaceMembers(activeWorkspace.slug) : null ); return ( {(provided, snapshot) => (

{groupTitle === null || groupTitle === "null" ? "None" : createdBy ? createdBy : addSpaceIfCamelCase(groupTitle)}

{groupedByIssues[groupTitle].length}
{(provided, snapshot) => (
{groupedByIssues[groupTitle].map((childIssue, index: number) => { const assignees = [ ...(childIssue?.assignees_list ?? []), ...(childIssue?.assignees ?? []), ]?.map((assignee) => { const tempPerson = people?.find((p) => p.member.id === assignee)?.member; return { avatar: tempPerson?.avatar, first_name: tempPerson?.first_name, email: tempPerson?.email, }; }); return ( {(provided, snapshot) => (
{properties.key && (
{activeProject?.identifier}-{childIssue.sequence_id}
)}
{childIssue.name}
{properties.priority && ( { partialUpdateIssue({ priority: data }, childIssue.id); }} className="group relative flex-shrink-0" > {({ open }) => ( <>
{childIssue.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
{childIssue.priority ?? "None"}
)}
)} {properties.state && ( { partialUpdateIssue({ state: data }, childIssue.id); }} className="group relative flex-shrink-0" > {({ open }) => ( <>
{addSpaceIfCamelCase(childIssue.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
{childIssue.state_detail.name}
)}
)} {properties.start_date && (
{childIssue.start_date ? renderShortNumericDateFormat(childIssue.start_date) : "N/A"}
Started at
{renderShortNumericDateFormat(childIssue.start_date ?? "")}
)} {properties.target_date && (
{childIssue.target_date ? renderShortNumericDateFormat(childIssue.target_date) : "N/A"}
Target date
{renderShortNumericDateFormat(childIssue.target_date ?? "")}
{childIssue.target_date && (childIssue.target_date < new Date().toISOString() ? `Target date has passed by ${findHowManyDaysLeft( childIssue.target_date )} days` : findHowManyDaysLeft(childIssue.target_date) <= 3 ? `Target date is in ${findHowManyDaysLeft( childIssue.target_date )} days` : "Target date")}
)} {properties.assignee && ( { const newData = childIssue.assignees ?? []; if (newData.includes(data)) { newData.splice(newData.indexOf(data), 1); } else { newData.push(data); } partialUpdateIssue( { assignees_list: newData }, childIssue.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?.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
{childIssue.assignee_details?.length > 0 ? childIssue.assignee_details .map((assignee) => assignee.first_name) .join(", ") : "No one"}
)}
)}
)}
); })} {provided.placeholder}
)}
)}
); }; export default SingleBoard;