import React from "react"; import { useRouter } from "next/router"; import useSWR, { mutate } from "swr"; // services import modulesService from "services/modules.service"; // ui import { Spinner, CustomSelect, Tooltip } from "components/ui"; // helper import { truncateText } from "helpers/string.helper"; // icons import { RectangleGroupIcon } from "@heroicons/react/24/outline"; // types import { IIssue, IModule, UserAuth } from "types"; // fetch-keys import { ISSUE_DETAILS, MODULE_ISSUES, MODULE_LIST } from "constants/fetch-keys"; type Props = { issueDetail: IIssue | undefined; handleModuleChange: (module: IModule) => void; userAuth: UserAuth; }; export const SidebarModuleSelect: React.FC = ({ issueDetail, handleModuleChange, userAuth, }) => { const router = useRouter(); const { workspaceSlug, projectId, issueId } = router.query; const { data: modules } = useSWR( workspaceSlug && projectId ? MODULE_LIST(projectId as string) : null, workspaceSlug && projectId ? () => modulesService.getModules(workspaceSlug as string, projectId as string) : null ); const removeIssueFromModule = (bridgeId: string, moduleId: string) => { if (!workspaceSlug || !projectId) return; modulesService .removeIssueFromModule(workspaceSlug as string, projectId as string, moduleId, bridgeId) .then((res) => { mutate(ISSUE_DETAILS(issueId as string)); mutate(MODULE_ISSUES(moduleId)); }) .catch((e) => { console.log(e); }); }; const issueModule = issueDetail?.issue_module; const isNotAllowed = userAuth.isGuest || userAuth.isViewer; return (

Module

m.id === issueModule?.module)?.name ?? "None"}`}> {truncateText(`${modules?.find((m) => m.id === issueModule?.module)?.name ?? "None"}`, 15)} } value={issueModule?.module_detail?.id} onChange={(value: any) => { !value ? removeIssueFromModule(issueModule?.id ?? "", issueModule?.module ?? "") : handleModuleChange(modules?.find((m) => m.id === value) as IModule); }} width="w-full" position="right" maxHeight="rg" disabled={isNotAllowed} > {modules ? ( modules.length > 0 ? ( <> {modules.map((option) => ( {truncateText(option.name, 15)} ))} None ) : (
No modules found
) ) : ( )}
); };