import { useRef, useState } from "react"; import { observer } from "mobx-react"; import { ChevronUp, PenSquare, Search } from "lucide-react"; // types import { TIssue } from "@plane/types"; // components import { CreateUpdateIssueModal } from "@/components/issues"; // constants import { EIssuesStoreType } from "@/constants/issue"; import { EUserWorkspaceRoles } from "@/constants/workspace"; // hooks import { useAppRouter, useAppTheme, useCommandPalette, useEventTracker, useProject, useUser } from "@/hooks/store"; import useLocalStorage from "@/hooks/use-local-storage"; export const WorkspaceSidebarQuickAction = observer(() => { // states const [isDraftIssueModalOpen, setIsDraftIssueModalOpen] = useState(false); // store hooks const { toggleCreateIssueModal, toggleCommandPaletteModal } = useCommandPalette(); const { sidebarCollapsed: isSidebarCollapsed } = useAppTheme(); const { workspaceSlug } = useAppRouter(); const { setTrackElement } = useEventTracker(); const { joinedProjectIds } = useProject(); const { membership: { currentWorkspaceRole }, } = useUser(); const { storedValue, setValue } = useLocalStorage>>("draftedIssue", {}); //useState control for displaying draft issue button instead of group hover const [isDraftButtonOpen, setIsDraftButtonOpen] = useState(false); // eslint-disable-next-line @typescript-eslint/no-explicit-any const timeoutRef = useRef(); const isAuthorizedUser = !!currentWorkspaceRole && currentWorkspaceRole >= EUserWorkspaceRoles.MEMBER; const disabled = joinedProjectIds.length === 0; const onMouseEnter = () => { // if enter before time out clear the timeout timeoutRef?.current && clearTimeout(timeoutRef.current); setIsDraftButtonOpen(true); }; const onMouseLeave = () => { timeoutRef.current = setTimeout(() => { setIsDraftButtonOpen(false); }, 300); }; const workspaceDraftIssue = workspaceSlug ? storedValue?.[workspaceSlug] ?? undefined : undefined; const removeWorkspaceDraftIssue = () => { const draftIssues = storedValue ?? {}; if (workspaceSlug && draftIssues[workspaceSlug]) delete draftIssues[workspaceSlug]; setValue(draftIssues); return Promise.resolve(); }; return ( <> setIsDraftIssueModalOpen(false)} data={workspaceDraftIssue ?? {}} onSubmit={() => removeWorkspaceDraftIssue()} isDraft />
{isAuthorizedUser && (
{!disabled && workspaceDraftIssue && ( <>
)}
)}
); });