import { useRouter } from "next/router"; // lucide icons import { CircleDashed, Plus } from "lucide-react"; // components import { CreateUpdateIssueModal } from "components/issues"; import { ExistingIssuesListModal } from "components/core"; import { CustomMenu } from "@plane/ui"; // mobx import { observer } from "mobx-react-lite"; // hooks import { useEventTracker } from "hooks/store"; // types import { TIssue, ISearchIssueResponse } from "@plane/types"; import useToast from "hooks/use-toast"; import { useState } from "react"; import { TCreateModalStoreTypes } from "constants/issue"; interface IHeaderGroupByCard { icon?: React.ReactNode; title: string; count: number; issuePayload: Partial; disableIssueCreation?: boolean; storeType: TCreateModalStoreTypes; addIssuesToView?: (issueIds: string[]) => Promise; } export const HeaderGroupByCard = observer( ({ icon, title, count, issuePayload, disableIssueCreation, storeType, addIssuesToView }: IHeaderGroupByCard) => { const router = useRouter(); const { workspaceSlug, projectId, moduleId, cycleId } = router.query; // hooks const { setTrackElement } = useEventTracker(); const [isOpen, setIsOpen] = useState(false); const [openExistingIssueListModal, setOpenExistingIssueListModal] = useState(false); const isDraftIssue = router.pathname.includes("draft-issue"); const { setToastAlert } = useToast(); const renderExistingIssueModal = moduleId || cycleId; const ExistingIssuesListModalPayload = moduleId ? { module: moduleId.toString() } : { cycle: true }; const handleAddIssuesToView = async (data: ISearchIssueResponse[]) => { if (!workspaceSlug || !projectId) return; const issues = data.map((i) => i.id); try { addIssuesToView && addIssuesToView(issues); } catch (error) { setToastAlert({ type: "error", title: "Error!", message: "Selected issues could not be added to the cycle. Please try again.", }); } }; return ( <>
{icon ? icon : }
{title}
{count || 0}
{!disableIssueCreation && (renderExistingIssueModal ? ( } > { setTrackElement("List layout"); setIsOpen(true); }} > Create issue { setTrackElement("List layout"); setOpenExistingIssueListModal(true); }} > Add an existing issue ) : (
{ setTrackElement("List layout"); setIsOpen(true); }} >
))} setIsOpen(false)} data={issuePayload} storeType={storeType} isDraft={isDraftIssue} /> {renderExistingIssueModal && ( setOpenExistingIssueListModal(false)} searchParams={ExistingIssuesListModalPayload} handleOnSubmit={handleAddIssuesToView} /> )}
); } );