import React, { useState, useEffect } from "react"; import { useRouter } from "next/router"; // hooks import useUser from "hooks/use-user"; import useDebounce from "hooks/use-debounce"; // services import { ProjectService } from "services/project"; // components import { WebViewModal } from "components/web-view"; import { LayersIcon } from "@plane/ui"; import { Loader, PrimaryButton, SecondaryButton, ToggleSwitch } from "components/ui"; // types import { ISearchIssueResponse, TProjectIssuesSearchParams } from "types"; type IssuesSelectBottomSheetProps = { isOpen: boolean; onClose: () => void; onSubmit: (data: ISearchIssueResponse[]) => Promise; searchParams: Partial; singleSelect?: boolean; }; // services const projectService = new ProjectService(); export const IssuesSelectBottomSheet: React.FC = (props) => { const { isOpen, onClose, onSubmit, searchParams, singleSelect = false } = props; const router = useRouter(); const { workspaceSlug, projectId, issueId } = router.query; const [searchTerm, setSearchTerm] = useState(""); const [issues, setIssues] = useState([]); const [isSearching, setIsSearching] = useState(false); const [selectedIssues, setSelectedIssues] = useState([]); const [isSubmitting, setIsSubmitting] = useState(false); const [isWorkspaceLevel, setIsWorkspaceLevel] = useState(false); const debouncedSearchTerm: string = useDebounce(searchTerm, 500); const { user } = useUser(); const handleClose = () => { onClose(); setSearchTerm(""); setSelectedIssues([]); setIsWorkspaceLevel(false); }; const handleSelect = async (data: ISearchIssueResponse[]) => { if (!user || !workspaceSlug || !projectId || !issueId) return; setIsSubmitting(true); await onSubmit(data).finally(() => { setIsSubmitting(false); }); handleClose(); console.log( "toast", JSON.stringify({ type: "success", message: `Issue${data.length > 1 ? "s" : ""} added successfully.`, }) ); }; useEffect(() => { if (!isOpen || !workspaceSlug || !projectId || !issueId) return; setIsSearching(true); projectService .projectIssuesSearch(workspaceSlug as string, projectId as string, { search: debouncedSearchTerm, ...searchParams, issue_id: issueId.toString(), workspace_search: isWorkspaceLevel, }) .then((res) => setIssues(res)) .finally(() => setIsSearching(false)); }, [debouncedSearchTerm, isOpen, isWorkspaceLevel, issueId, projectId, workspaceSlug, searchParams]); return ( {!isSearching && issues.length === 0 && searchTerm !== "" && debouncedSearchTerm !== "" && (

No issues found. Create a new issue with{" "}
C
.

)}
setIsWorkspaceLevel((prevData) => !prevData)} />
{isSearching && ( )} {!isSearching && ( ({ value: issue.id, label: (
{issue.project__identifier}-{issue.sequence_id} {issue.name}
), checked: selectedIssues.some((i) => i.id === issue.id), onClick() { if (singleSelect) { handleSelect([issue]); handleClose(); return; } if (selectedIssues.some((i) => i.id === issue.id)) { setSelectedIssues(selectedIssues.filter((i) => i.id !== issue.id)); } else { setSelectedIssues([...selectedIssues, issue]); } }, }))} /> )} {selectedIssues.length > 0 && ( Cancel { handleSelect(selectedIssues); }} loading={isSubmitting} > {isSubmitting ? "Adding..." : "Add selected issues"} )}
); };