import { useState } from "react"; import { observer } from "mobx-react-lite"; import { useRouter } from "next/router"; // lucide icons import { CircleDashed, Plus } from "lucide-react"; import { TIssue, ISearchIssueResponse } from "@plane/types"; // components import { CustomMenu, TOAST_TYPE, setToast } from "@plane/ui"; import { ExistingIssuesListModal } from "@/components/core"; import { CreateUpdateIssueModal } from "@/components/issues"; // ui // mobx // hooks import { EIssuesStoreType } from "@/constants/issue"; import { useEventTracker } from "@/hooks/store"; // types interface IHeaderGroupByCard { icon?: React.ReactNode; title: string; count: number; issuePayload: Partial; disableIssueCreation?: boolean; storeType: EIssuesStoreType; 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 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 { await addIssuesToView?.(issues); setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", message: "Issues added to the cycle successfully.", }); } catch (error) { setToast({ type: TOAST_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} /> )}
); } );