import { useRef, useState } from "react"; import { observer } from "mobx-react-lite"; import { ChevronUp, PenSquare, Search } from "lucide-react"; // hooks import { useApplication, useEventTracker, useProject, useUser } from "hooks/store"; import useLocalStorage from "hooks/use-local-storage"; // components import { CreateUpdateIssueModal } from "components/issues"; // constants import { EUserWorkspaceRoles } from "constants/workspace"; import { EIssuesStoreType } from "constants/issue"; // 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, setValue } = useLocalStorage>>("draftedIssue", {}); //useState control for displaying draft issue button instead of group hover const [isDraftButtonOpen, setIsDraftButtonOpen] = useState(false); const timeoutRef = useRef(); const isSidebarCollapsed = themeStore.sidebarCollapsed; const isAuthorizedUser = !!currentWorkspaceRole && currentWorkspaceRole >= EUserWorkspaceRoles.MEMBER; const disabled = joinedProjectIds.length === 0; const onMouseEnter = () => { //if renet before timout 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 ( <> setIsDraftIssueModalOpen(false)} data={workspaceDraftIssue ?? {}} // storeType={storeType} isDraft={true} />
{isAuthorizedUser && (
{!disabled && workspaceDraftIssue && ( <>
)}
)}
); });