import React, { useState } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // react-beautiful-dnd import { Draggable } from "react-beautiful-dnd"; // services import workspaceService from "services/workspace.service"; // components import SingleIssue from "components/common/board-view/single-issue"; import StrictModeDroppable from "components/dnd/StrictModeDroppable"; import BoardHeader from "components/common/board-view/board-header"; // ui import { CustomMenu } from "components/ui"; // icons import { PlusIcon } from "@heroicons/react/24/outline"; // types import { IIssue, IWorkspaceMember, NestedKeyOf, Properties, UserAuth } from "types"; // fetch-keys import { WORKSPACE_MEMBERS } from "constants/fetch-keys"; type Props = { properties: Properties; groupedByIssues: { [key: string]: IIssue[]; }; selectedGroup: NestedKeyOf | null; groupTitle: string; createdBy: string | null; bgColor?: string; openCreateIssueModal: (issue?: IIssue, actionType?: "create" | "edit" | "delete") => void; openIssuesListModal: () => void; handleDeleteIssue: React.Dispatch>; setPreloadedData: React.Dispatch< React.SetStateAction< | (Partial & { actionType: "createIssue" | "edit" | "delete"; }) | null > >; stateId: string | null; userAuth: UserAuth; }; const SingleModuleBoard: React.FC = ({ properties, groupedByIssues, selectedGroup, groupTitle, createdBy, bgColor, openCreateIssueModal, openIssuesListModal, handleDeleteIssue, setPreloadedData, stateId, userAuth, }) => { // Collapse/Expand const [isCollapsed, setIsCollapsed] = useState(true); const router = useRouter(); const { workspaceSlug, moduleId } = router.query; if (selectedGroup === "priority") groupTitle === "high" ? (bgColor = "#dc2626") : groupTitle === "medium" ? (bgColor = "#f97316") : groupTitle === "low" ? (bgColor = "#22c55e") : (bgColor = "#ff0000"); const { data: people } = useSWR( workspaceSlug ? WORKSPACE_MEMBERS : null, workspaceSlug ? () => workspaceService.workspaceMembers(workspaceSlug as string) : null ); return (
{ openCreateIssueModal(); if (selectedGroup !== null) { setPreloadedData({ state: stateId !== null ? stateId : undefined, [selectedGroup]: groupTitle, actionType: "createIssue", }); } }} bgColor={bgColor ?? ""} createdBy={createdBy} groupTitle={groupTitle} groupedByIssues={groupedByIssues} isCollapsed={isCollapsed} setIsCollapsed={setIsCollapsed} selectedGroup={selectedGroup} /> {(provided, snapshot) => (
{groupedByIssues[groupTitle].map((issue, index: number) => { const assignees = [ ...(issue?.assignees_list ?? []), ...(issue?.assignees ?? []), ]?.map((assignee) => { const tempPerson = people?.find((p) => p.member.id === assignee)?.member; return tempPerson; }); return ( {(provided, snapshot) => (
)}
); })} {provided.placeholder} Add issue } className="mt-1" optionsPosition="left" noBorder > { openCreateIssueModal(); if (selectedGroup !== null) { setPreloadedData({ state: stateId !== null ? stateId : undefined, [selectedGroup]: groupTitle, actionType: "createIssue", }); } }} > Create new openIssuesListModal()}> Add an existing issue
)}
); }; export default SingleModuleBoard;