// react import React from "react"; // next import Link from "next/link"; // swr import useSWR from "swr"; // headless ui import { Disclosure, Transition } from "@headlessui/react"; // hooks import useUser from "lib/hooks/useUser"; // ui import { CustomMenu, Spinner } from "ui"; // icons import { PlusIcon, ChevronDownIcon } from "@heroicons/react/20/solid"; import { CalendarDaysIcon } from "@heroicons/react/24/outline"; // types import { IIssue, IWorkspaceMember, NestedKeyOf, Properties } from "types"; // fetch keys import { WORKSPACE_MEMBERS } from "constants/fetch-keys"; // constants import { addSpaceIfCamelCase, findHowManyDaysLeft, renderShortNumericDateFormat, } from "constants/common"; import workspaceService from "lib/services/workspace.service"; type Props = { groupedByIssues: { [key: string]: (IIssue & { bridge?: string })[]; }; properties: Properties; selectedGroup: NestedKeyOf | null; openCreateIssueModal: (issue?: IIssue, actionType?: "create" | "edit" | "delete") => void; openIssuesListModal: () => void; removeIssueFromModule: (issueId: string) => void; handleDeleteIssue: React.Dispatch>; setPreloadedData: React.Dispatch< React.SetStateAction< | (Partial & { actionType: "createIssue" | "edit" | "delete"; }) | undefined > >; }; const ModulesListView: React.FC = ({ groupedByIssues, selectedGroup, openCreateIssueModal, openIssuesListModal, properties, removeIssueFromModule, handleDeleteIssue, setPreloadedData, }) => { const { activeWorkspace, activeProject, states } = useUser(); const { data: people } = useSWR( activeWorkspace ? WORKSPACE_MEMBERS : null, activeWorkspace ? () => workspaceService.workspaceMembers(activeWorkspace.slug) : null ); return (
{Object.keys(groupedByIssues).map((singleGroup) => { const stateId = selectedGroup === "state_detail.name" ? states?.find((s) => s.name === singleGroup)?.id ?? null : null; return ( {({ open }) => (
{selectedGroup !== null ? (

{singleGroup === null || singleGroup === "null" ? selectedGroup === "priority" && "No priority" : addSpaceIfCamelCase(singleGroup)}

) : (

All Issues

)}

{groupedByIssues[singleGroup as keyof IIssue].length}

{groupedByIssues[singleGroup] ? ( groupedByIssues[singleGroup].length > 0 ? ( groupedByIssues[singleGroup].map((issue) => { const assignees = [ ...(issue?.assignees_list ?? []), ...(issue?.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 (
{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.start_date && (
{issue.start_date ? renderShortNumericDateFormat(issue.start_date) : "N/A"}
Started at
{renderShortNumericDateFormat(issue.start_date ?? "")}
)} {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")}
)} openCreateIssueModal(issue, "edit")} > Edit removeIssueFromModule(issue.bridge ?? "")} > Remove from module handleDeleteIssue(issue.id)} > Delete permanently
); }) ) : (

No issues.

) ) : (
)}
Add issue } optionsPosition="left" withoutBorder > { openCreateIssueModal(); if (selectedGroup !== null) { setPreloadedData({ state: stateId !== null ? stateId : undefined, [selectedGroup]: singleGroup, actionType: "createIssue", }); } }} > Create new openIssuesListModal()}> Add an existing issue
)}
); })}
); }; export default ModulesListView;