import { Dispatch, SetStateAction, useState } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // react-beautiful-dnd import StrictModeDroppable from "components/dnd/StrictModeDroppable"; import { Draggable, DraggableProvided, DraggableStateSnapshot } from "react-beautiful-dnd"; // services import workspaceService from "services/workspace.service"; // hooks import useIssuesProperties from "hooks/use-issue-properties"; // components import BoardHeader from "components/core/board-view/board-header"; import SingleIssue from "components/core/board-view/single-issue"; // ui import { CustomMenu } from "components/ui"; // icons import { PlusIcon } from "@heroicons/react/24/outline"; // types import { IIssue, IWorkspaceMember, NestedKeyOf, UserAuth } from "types"; // fetch-keys import { WORKSPACE_MEMBERS } from "constants/fetch-keys"; type Props = { type?: "issue" | "cycle" | "module"; provided: DraggableProvided; snapshot: DraggableStateSnapshot; bgColor?: string; groupTitle: string; groupedByIssues: { [key: string]: IIssue[]; }; selectedGroup: NestedKeyOf | null; addIssueToState: () => void; handleDeleteIssue?: Dispatch> | undefined; openIssuesListModal?: (() => void) | null; userAuth: UserAuth; }; export const CommonSingleBoard: React.FC = ({ type = "issue", provided, snapshot, bgColor, groupTitle, groupedByIssues, selectedGroup, addIssueToState, handleDeleteIssue, openIssuesListModal, userAuth, }) => { // collapse/expand const [isCollapsed, setIsCollapsed] = useState(true); const router = useRouter(); const { workspaceSlug, projectId } = router.query; const [properties] = useIssuesProperties(workspaceSlug as string, projectId as string); const { data: members } = useSWR( workspaceSlug ? WORKSPACE_MEMBERS : null, workspaceSlug ? () => workspaceService.workspaceMembers(workspaceSlug as string) : null ); const createdBy = selectedGroup === "created_by" ? members?.find((m) => m.member.id === groupTitle)?.member.first_name ?? "loading..." : null; if (selectedGroup === "priority") groupTitle === "high" ? (bgColor = "#dc2626") : groupTitle === "medium" ? (bgColor = "#f97316") : groupTitle === "low" ? (bgColor = "#22c55e") : (bgColor = "#ff0000"); return (
{(provided, snapshot) => (
{groupedByIssues[groupTitle].map((childIssue, index: number) => { const assignees = [ ...(childIssue?.assignees_list ?? []), ...(childIssue?.assignees ?? []), ]?.map((assignee) => { const tempPerson = members?.find((p) => p.member.id === assignee)?.member; return tempPerson; }); return ( {(provided, snapshot) => (
)}
); })} {provided.placeholder} {type === "issue" ? ( ) : ( Add issue } className="mt-1" optionsPosition="left" noBorder > Create new {openIssuesListModal && ( Add an existing issue )} )}
)}
); };