261021_01_ENH: 1차 마이그레이션 완료
This commit is contained in:
58
src/components/project/ProjectSelector.tsx
Normal file
58
src/components/project/ProjectSelector.tsx
Normal file
@@ -0,0 +1,58 @@
|
||||
"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
|
||||
resetScrollOnSearch
|
||||
preventDeselect
|
||||
hideOptionCheck
|
||||
disabled={projects.isPending}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user