From 2c02afd48a4d9276a4f5c132e088540a578d0972 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Tue, 30 Sep 2025 10:08:53 +0000 Subject: (대표님) 폼리스트, spreadjs 관련 변경사항, 벤더문서 뷰 쿼리 수정, 이메일 템플릿 추가 등 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../table/document-class-option-add-dialog.tsx | 161 +++++++++++++++++++-- 1 file changed, 152 insertions(+), 9 deletions(-) (limited to 'lib/docu-list-rule/document-class') diff --git a/lib/docu-list-rule/document-class/table/document-class-option-add-dialog.tsx b/lib/docu-list-rule/document-class/table/document-class-option-add-dialog.tsx index 93681c09..31337675 100644 --- a/lib/docu-list-rule/document-class/table/document-class-option-add-dialog.tsx +++ b/lib/docu-list-rule/document-class/table/document-class-option-add-dialog.tsx @@ -5,7 +5,7 @@ import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import { toast } from "sonner" import * as z from "zod" -import { Plus } from "lucide-react" +import { Plus, Check, ChevronsUpDown } from "lucide-react" import { Button } from "@/components/ui/button" import { @@ -25,12 +25,62 @@ import { FormLabel, FormMessage, } from "@/components/ui/form" -import { Input } from "@/components/ui/input" +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, +} from "@/components/ui/command" +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover" +import { cn } from "@/lib/utils" +import { useParams } from "next/navigation" import { createDocumentClassOptionItem } from "@/lib/docu-list-rule/document-class/service" +import { getProjectCode } from "@/lib/projects/service" + +// API 응답 타입 +interface ScheduleSetting { + COL_NM: string + DC_OBX_USE_YN: string + PROJ_COL_NM: string + PROJ_COL_NM_EN: string + SCD_VIEW_MGNT: string + USE_YN1: string + USE_YN2: string +} + +// 프로젝트 일정 설정을 가져오는 함수 +async function getProjectKindScheduleSetting(projectCode: string): Promise { + try { + const response = await fetch( + `http://60.100.99.217/DDP/Services/VNDRService.svc/GetProjectKindScheduleSetting?PROJ_NO=${projectCode}`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + } + ) + + if (!response.ok) { + throw new Error('Failed to fetch schedule settings') + } + + const data = await response.json() + return data.GetProjectKindScheduleSettingResult || [] + } catch (error) { + console.error('Error fetching schedule settings:', error) + return [] + } +} const createOptionSchema = z.object({ - optionCode: z.string().min(1, "코드는 필수입니다."), + optionCode: z.string().min(1, "옵션을 선택해주세요."), }) type CreateOptionSchema = z.infer @@ -42,7 +92,12 @@ interface DocumentClassOptionAddDialogProps { export function DocumentClassOptionAddDialog({ documentClassId, onSuccess }: DocumentClassOptionAddDialogProps) { const [open, setOpen] = React.useState(false) + const [comboboxOpen, setComboboxOpen] = React.useState(false) const [isPending, startTransition] = React.useTransition() + const [scheduleSettings, setScheduleSettings] = React.useState([]) + const [isLoading, setIsLoading] = React.useState(false) + const params = useParams() + const projectId = Number(params?.projectId) const form = useForm({ resolver: zodResolver(createOptionSchema), @@ -51,6 +106,35 @@ export function DocumentClassOptionAddDialog({ documentClassId, onSuccess }: Doc }, }) + // Dialog가 열릴 때 데이터 로드 + React.useEffect(() => { + if (open && projectId) { + loadScheduleSettings() + } + }, [open, projectId]) + + const loadScheduleSettings = async () => { + setIsLoading(true) + try { + // 먼저 projectId로 프로젝트 코드 가져오기 + const projectCode = await getProjectCode(projectId) + + if (!projectCode) { + toast.error("프로젝트 코드를 찾을 수 없습니다.") + return + } + + // 프로젝트 코드로 일정 설정 가져오기 + const settings = await getProjectKindScheduleSetting(projectCode) + setScheduleSettings(settings) + } catch (error) { + console.error("Error loading schedule settings:", error) + toast.error("옵션 목록을 불러오는 중 오류가 발생했습니다.") + } finally { + setIsLoading(false) + } + } + const handleSubmit = (data: CreateOptionSchema) => { startTransition(async () => { try { @@ -79,6 +163,10 @@ export function DocumentClassOptionAddDialog({ documentClassId, onSuccess }: Doc form.reset() } + const selectedOption = scheduleSettings.find( + (setting) => setting.COL_NM === form.watch("optionCode") + ) + return ( @@ -100,11 +188,66 @@ export function DocumentClassOptionAddDialog({ documentClassId, onSuccess }: Doc control={form.control} name="optionCode" render={({ field }) => ( - - 코드 - - - + + 옵션 선택 + + + + + + + + + + + {isLoading ? "로딩 중..." : "검색 결과가 없습니다."} + + + {scheduleSettings.map((setting) => ( + { + form.setValue("optionCode", setting.COL_NM) + setComboboxOpen(false) + }} + > + +
+ {setting.COL_NM} + + {setting.PROJ_COL_NM} + +
+
+ ))} +
+
+
+
)} @@ -122,4 +265,4 @@ export function DocumentClassOptionAddDialog({ documentClassId, onSuccess }: Doc
) -} \ No newline at end of file +} \ No newline at end of file -- cgit v1.2.3