import React, { useRef, useState } from "react"; import { useRouter } from "next/router"; import Link from "next/link"; import useSWR from "swr"; // headless ui import { Transition } from "@headlessui/react"; // services import workspaceService from "services/workspace.service"; // hooks import useTheme from "hooks/use-theme"; import useUser from "hooks/use-user"; import useOutsideClickDetector from "hooks/use-outside-click-detector"; // components import UpgradeToProModal from "./upgrade-to-pro-modal"; // ui import { CircularProgress } from "components/ui"; // icons import { ArrowLongLeftIcon, ChatBubbleOvalLeftEllipsisIcon, RocketLaunchIcon, ArrowUpCircleIcon, XMarkIcon, } from "@heroicons/react/24/outline"; import { QuestionMarkCircleIcon, DocumentIcon, DiscordIcon, GithubIcon } from "components/icons"; // fetch-keys import { WORKSPACE_DETAILS } from "constants/fetch-keys"; const helpOptions = [ { name: "Documentation", href: "https://docs.plane.so/", Icon: DocumentIcon, }, { name: "Join our Discord", href: "https://discord.com/invite/A92xrEGCge", Icon: DiscordIcon, }, { name: "Report a bug", href: "https://github.com/makeplane/plane/issues/new/choose", Icon: GithubIcon, }, { name: "Chat with us", href: null, onClick: () => (window as any).$crisp.push(["do", "chat:show"]), Icon: ChatBubbleOvalLeftEllipsisIcon, }, ]; export interface WorkspaceHelpSectionProps { setSidebarActive: React.Dispatch>; } export const WorkspaceHelpSection: React.FC = ({ setSidebarActive }) => { const [alert, setAlert] = useState(false); const [isNeedHelpOpen, setIsNeedHelpOpen] = useState(false); const helpOptionsRef = useRef(null); const router = useRouter(); const { workspaceSlug } = router.query; const { collapsed: sidebarCollapse, toggleCollapsed } = useTheme(); useOutsideClickDetector(helpOptionsRef, () => setIsNeedHelpOpen(false)); const { user } = useUser(); const [upgradeModal, setUpgradeModal] = useState(false); const { data: workspaceDetails } = useSWR( workspaceSlug ? WORKSPACE_DETAILS(workspaceSlug as string) : null, workspaceSlug ? () => workspaceService.getWorkspace(workspaceSlug as string) : null ); const issueNumber = workspaceDetails?.total_issues || 0; return ( <> setUpgradeModal(false)} user={user} issueNumber={issueNumber} /> {!sidebarCollapse && (alert || issueNumber >= 750) && (
= 750 ? "bg-red-500/10 text-red-600" : issueNumber >= 500 ? "bg-yellow-500/10 text-yellow-600" : "text-green-600" }`} >
Free Plan
{issueNumber < 750 && (
setAlert(false)} >
)}
This workspace has used {issueNumber} of its 1024 issues creation limit ( {((issueNumber / 1024) * 100).toFixed(0)} %).
)}
{alert || issueNumber >= 750 ? ( ) : ( )}
{helpOptions.map(({ name, Icon, href, onClick }) => { if (href) return ( {name} ); else return ( ); })}
); };