import { useRef, useState } from "react"; import { observer } from "mobx-react-lite"; import { ChevronUp, PenSquare, Search } from "lucide-react"; // components import { CreateUpdateIssueModal } from "components/issues"; // constants import { EIssuesStoreType } from "constants/issue"; import { EUserWorkspaceRoles } from "constants/workspace"; // hooks import { useApplication, useEventTracker, useProject, useUser } from "hooks/store"; import useLocalStorage from "hooks/use-local-storage"; // types import { TIssue } from "@plane/types"; export const WorkspaceSidebarQuickAction = observer(() => { // states const [isDraftIssueModalOpen, setIsDraftIssueModalOpen] = useState(false); const { router: { workspaceSlug }, theme: themeStore, commandPalette: commandPaletteStore, } = useApplication(); const { setTrackElement } = useEventTracker(); const { joinedProjectIds } = useProject(); const { membership: { currentWorkspaceRole }, } = useUser(); const { storedValue } = 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 isSidebarCollapsed = themeStore.sidebarCollapsed; 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 && ( <>
)}
)}
); });