"use client"; import { FC, useState, useRef } from "react"; import { observer } from "mobx-react"; import { ChevronDown, Plus } from "lucide-react"; import { EUserPermissions, EUserPermissionsLevel } from "@plane/constants"; import { IState, TStateGroups } from "@plane/types"; // components import { StateGroupIcon } from "@plane/ui"; import { cn } from "@plane/utils"; import { StateList, StateCreate } from "@/components/project-states"; // hooks import { useUserPermissions } from "@/hooks/store"; type TGroupItem = { workspaceSlug: string; projectId: string; groupKey: TStateGroups; groupsExpanded: Partial[]; handleGroupCollapse: (groupKey: TStateGroups) => void; handleExpand: (groupKey: TStateGroups) => void; groupedStates: Record; states: IState[]; }; export const GroupItem: FC = observer((props) => { const { workspaceSlug, projectId, groupKey, groupedStates, states, groupsExpanded, handleExpand, handleGroupCollapse, } = props; // store hooks const { allowPermissions } = useUserPermissions(); // state const [createState, setCreateState] = useState(false); // derived values const currentStateExpanded = groupsExpanded.includes(groupKey); // refs const dropElementRef = useRef(null); const isEditable = allowPermissions([EUserPermissions.ADMIN], EUserPermissionsLevel.PROJECT); return (
(!currentStateExpanded ? handleExpand(groupKey) : handleGroupCollapse(groupKey))} >
{groupKey}
!createState && setCreateState(true)} >
{groupedStates[groupKey].length > 0 && currentStateExpanded && (
)} {isEditable && createState && (
setCreateState(false)} />
)}
); });