From 67bb1ad7d7e001e19c8d1dd9153a5f663e2afa03 Mon Sep 17 00:00:00 2001
From: 0-Zz-ang <s1998319@gmail.com>
Date: Thu, 7 Aug 2025 18:02:54 +0900
Subject: (박서영)docu-list-rule Project_code적용
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../table/document-class-add-dialog.tsx            | 76 ++++++++++++++++++++--
 1 file changed, 69 insertions(+), 7 deletions(-)

(limited to 'lib/docu-list-rule/document-class/table/document-class-add-dialog.tsx')

diff --git a/lib/docu-list-rule/document-class/table/document-class-add-dialog.tsx b/lib/docu-list-rule/document-class/table/document-class-add-dialog.tsx
index ef9c50a8..dfd1d7f2 100644
--- a/lib/docu-list-rule/document-class/table/document-class-add-dialog.tsx
+++ b/lib/docu-list-rule/document-class/table/document-class-add-dialog.tsx
@@ -26,11 +26,19 @@ import {
   FormMessage,
 } from "@/components/ui/form"
 import { Input } from "@/components/ui/input"
-
+import {
+  Select,
+  SelectContent,
+  SelectItem,
+  SelectTrigger,
+  SelectValue,
+} from "@/components/ui/select"
 
 import { createDocumentClassCodeGroup } from "@/lib/docu-list-rule/document-class/service"
+import { getProjectLists } from "@/lib/projects/service"
 
 const createDocumentClassSchema = z.object({
+  projectId: z.string().min(1, "프로젝트는 필수입니다."),
   value: z.string().min(1, "Value는 필수입니다."),
   description: z.string().optional(),
 })
@@ -46,20 +54,49 @@ export function DocumentClassAddDialog({
 }: DocumentClassAddDialogProps) {
   const [open, setOpen] = React.useState(false)
   const [isPending, startTransition] = React.useTransition()
+  const [projects, setProjects] = React.useState<Array<{ id: number; code: string; name: string }>>([])
 
   const form = useForm<CreateDocumentClassSchema>({
     resolver: zodResolver(createDocumentClassSchema),
     defaultValues: {
+      projectId: "",
       value: "",
       description: "",
     },
     mode: "onChange"
   })
 
+  // 프로젝트 목록 로드
+  React.useEffect(() => {
+    if (open) {
+      const loadProjects = async () => {
+        try {
+          const result = await getProjectLists({ 
+            page: 1, 
+            perPage: 1000,
+            search: "",
+            sort: [],
+            filters: [],
+            joinOperator: "and",
+            flags: []
+          })
+          if (result.data) {
+            setProjects(result.data)
+          }
+        } catch (error) {
+          console.error("Failed to load projects:", error)
+          toast.error("프로젝트 목록을 불러오는데 실패했습니다.")
+        }
+      }
+      loadProjects()
+    }
+  }, [open])
+
   async function onSubmit(input: CreateDocumentClassSchema) {
     startTransition(async () => {
       try {
-                                    const result = await createDocumentClassCodeGroup({
+        const result = await createDocumentClassCodeGroup({
+          projectId: parseInt(input.projectId),
           value: input.value,
           description: input.description,
         })
@@ -94,14 +131,39 @@ export function DocumentClassAddDialog({
       </DialogTrigger>
       <DialogContent className="sm:max-w-[425px]">
         <DialogHeader>
-                  <DialogTitle>Document Class 추가</DialogTitle>
-        <DialogDescription>
-          새로운 Document Class를 추가합니다.
-          <span className="text-red-500 mt-1 block text-sm">* 표시된 항목은 필수 입력사항입니다.</span>
-        </DialogDescription>
+          <DialogTitle>Document Class 추가</DialogTitle>
+          <DialogDescription>
+            새로운 Document Class를 추가합니다.
+            <span className="text-red-500 mt-1 block text-sm">* 표시된 항목은 필수 입력사항입니다.</span>
+          </DialogDescription>
         </DialogHeader>
         <Form {...form}>
           <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
+            <FormField
+              control={form.control}
+              name="projectId"
+              render={({ field }) => (
+                <FormItem>
+                  <FormLabel>프로젝트 *</FormLabel>
+                  <Select onValueChange={field.onChange} defaultValue={field.value}>
+                    <FormControl>
+                      <SelectTrigger>
+                        <SelectValue placeholder="프로젝트를 선택하세요" />
+                      </SelectTrigger>
+                    </FormControl>
+                    <SelectContent>
+                      {projects.map((project) => (
+                        <SelectItem key={project.id} value={project.id.toString()}>
+                          {project.code} - {project.name}
+                        </SelectItem>
+                      ))}
+                    </SelectContent>
+                  </Select>
+                  <FormMessage />
+                </FormItem>
+              )}
+            />
+
             <FormField
               control={form.control}
               name="value"
-- 
cgit v1.2.3

