From e0dfb55c5457aec489fc084c4567e791b4c65eb1 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Wed, 26 Mar 2025 00:37:41 +0000 Subject: 3/25 까지의 대표님 작업사항 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/documents/project-swicher.tsx | 138 +++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 components/documents/project-swicher.tsx (limited to 'components/documents/project-swicher.tsx') diff --git a/components/documents/project-swicher.tsx b/components/documents/project-swicher.tsx new file mode 100644 index 00000000..5c70ea88 --- /dev/null +++ b/components/documents/project-swicher.tsx @@ -0,0 +1,138 @@ +"use client" + +import * as React from "react" +import { cn } from "@/lib/utils" +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" + +interface PackageItem { + itemId: number + itemName: string +} + +interface ContractInfo { + contractId: number + contractNo: string + contractName: string + packages: PackageItem[] +} + +export interface ProjectInfo { + projectId: number + projectCode: string + projectName: string + projectType: string + contracts: ContractInfo[] +} + +interface ProjectSwitcherProps { + isCollapsed: boolean + projects: ProjectInfo[] + + // 상위가 관리하는 "현재 선택된 contractId" + selectedContractId: number | null + + // 콜백: 사용자가 "어떤 contract"를 골랐는지 + onSelectContract: (projectId: number, contractId: number) => void +} + +/** + * ProjectSwitcher: + * - 프로젝트들(contracts 포함)을 그룹화하여 Select 표시 + * - 너무 긴 계약명 등을 ellipsis로 축약 + */ +export function ProjectSwitcher({ + isCollapsed, + projects, + selectedContractId, + onSelectContract, +}: ProjectSwitcherProps) { + // Select value = stringified contractId + const selectValue = selectedContractId ? String(selectedContractId) : "" + + // 현재 선택된 계약 정보를 찾기 + const selectedContract = React.useMemo(() => { + if (!selectedContractId) return null + for (const proj of projects) { + const found = proj.contracts.find((c) => c.contractId === selectedContractId) + if (found) { + return { ...found, projectId: proj.projectId } + } + } + return null + }, [projects, selectedContractId]) + + // Trigger Label => 계약 이름 or "Select a contract" + const triggerLabel = selectedContract?.contractName ?? "Select a contract" + + function handleValueChange(val: string) { + const contractId = Number(val) + let foundProjectId = 0 + + for (const proj of projects) { + const found = proj.contracts.find((c) => c.contractId === contractId) + if (found) { + foundProjectId = proj.projectId + break + } + } + onSelectContract(foundProjectId, contractId) + } + + return ( + + ) +} \ No newline at end of file -- cgit v1.2.3