64 lines
2.3 KiB
TypeScript
64 lines
2.3 KiB
TypeScript
"use client";
|
|
|
|
import { useRouter, usePathname } from "next/navigation";
|
|
import { KriSingleSelect } from "@/components/common/KriAutoComplete";
|
|
import { useProjectListQuery } from "@/query/project";
|
|
import { useSelectedProject } from "@/hooks/useSelectedProject";
|
|
import { projectKey } from "@/types/kart";
|
|
import { projectPagePath } from "@/lib/report-navigation";
|
|
import { QueryState } from "./QueryState";
|
|
|
|
/** Legacy ProjectSelect: search dropdown that always reads "프로젝트 선택". */
|
|
export function ProjectSelector() {
|
|
const router = useRouter();
|
|
const pathname = usePathname();
|
|
const { project: selected, select } = useSelectedProject();
|
|
const projects = useProjectListQuery();
|
|
if (projects.isError)
|
|
return (
|
|
<QueryState
|
|
error={projects.error}
|
|
onRetry={() => void projects.refetch()}
|
|
/>
|
|
);
|
|
return (
|
|
<KriSingleSelect
|
|
// Remount after each selection so the trigger returns to the legacy fixed label.
|
|
key={selected ? projectKey(selected) : ""}
|
|
items={projects.data ?? []}
|
|
value=""
|
|
getValue={projectKey}
|
|
getLabel={(item) => "(" + item.pkey + ") " + (item.title ?? "")}
|
|
onChange={(value) => {
|
|
const project = projects.data?.find(
|
|
(item) => projectKey(item) === value,
|
|
);
|
|
if (!project) return;
|
|
// Same page for the new project (legacy keeps the current menu), progress from home.
|
|
select(project);
|
|
router.push(projectPagePath(pathname));
|
|
}}
|
|
placeholder={
|
|
projects.isPending
|
|
? "목록을 불러오는 중..."
|
|
: projects.data?.length
|
|
? "프로젝트 선택"
|
|
: "조회 가능한 프로젝트가 없습니다."
|
|
}
|
|
widthClassName="w-full"
|
|
className="h-8 min-h-8 rounded-[39px] border-[#d0d0d0] bg-kart-soft px-[22px] py-0 text-sm shadow-none"
|
|
spanClassName="text-sm [&_span]:text-kart-text"
|
|
searchable
|
|
// Legacy Dropdown search: case-insensitive substring, not fuzzy.
|
|
searchMatch="contains"
|
|
resetScrollOnSearch
|
|
// Legacy react-tooltip: full "(pkey) title" on hover, right side, 65% opacity.
|
|
optionTooltip="singleLine"
|
|
optionTooltipClassName="opacity-65"
|
|
preventDeselect
|
|
hideOptionCheck
|
|
disabled={projects.isPending}
|
|
/>
|
|
);
|
|
}
|