From 1dc24d48e52f2e490f5603ceb02842586ecae533 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Thu, 24 Jul 2025 11:06:32 +0000 Subject: (대표님) 정기평가 피드백 반영, 설계 피드백 반영, (최겸) 기술영업 피드백 반영 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../status/create-gtc-document-dialog.tsx | 272 +++++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 lib/gtc-contract/status/create-gtc-document-dialog.tsx (limited to 'lib/gtc-contract/status/create-gtc-document-dialog.tsx') diff --git a/lib/gtc-contract/status/create-gtc-document-dialog.tsx b/lib/gtc-contract/status/create-gtc-document-dialog.tsx new file mode 100644 index 00000000..6791adfa --- /dev/null +++ b/lib/gtc-contract/status/create-gtc-document-dialog.tsx @@ -0,0 +1,272 @@ +"use client" + +import * as React from "react" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" +import { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter } from "@/components/ui/dialog" +import { Button } from "@/components/ui/button" +import { Textarea } from "@/components/ui/textarea" + +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +import { + Popover, + PopoverTrigger, + PopoverContent, +} from "@/components/ui/popover" +import { + Command, + CommandInput, + CommandList, + CommandGroup, + CommandItem, + CommandEmpty, +} from "@/components/ui/command" +import { Check, ChevronsUpDown, Loader, Plus } from "lucide-react" +import { cn } from "@/lib/utils" +import { toast } from "sonner" + +import { createGtcDocumentSchema, type CreateGtcDocumentSchema } from "@/lib/gtc-contract/validations" +import { createGtcDocument, getProjectsForSelect } from "@/lib/gtc-contract/service" +import { type Project } from "@/db/schema/projects" + +export function CreateGtcDocumentDialog() { + const [open, setOpen] = React.useState(false) + const [projects, setProjects] = React.useState([]) + const [isCreatePending, startCreateTransition] = React.useTransition() + + React.useEffect(() => { + if (open) { + getProjectsForSelect().then((res) => { + setProjects(res) + }) + } + }, [open]) + + const form = useForm({ + resolver: zodResolver(createGtcDocumentSchema), + defaultValues: { + type: "standard", + projectId: null, + revision: 0, + editReason: "", + }, + }) + + const watchedType = form.watch("type") + + async function onSubmit(data: CreateGtcDocumentSchema) { + startCreateTransition(async () => { + try { + const result = await createGtcDocument(data) + + if (result.error) { + toast.error(`에러: ${result.error}`) + return + } + + form.reset() + setOpen(false) + toast.success("GTC 문서가 생성되었습니다.") + } catch (error) { + toast.error("문서 생성 중 오류가 발생했습니다.") + } + }) + } + + function handleDialogOpenChange(nextOpen: boolean) { + if (!nextOpen) { + form.reset() + } + setOpen(nextOpen) + } + + return ( + + + + + + + + Create New GTC Document + + 새 GTC 문서 정보를 입력하고 Create 버튼을 누르세요. + + + +
+ +
+ {/* 구분 (Type) */} + ( + + 구분 + + + + + + )} + /> + + {/* 프로젝트 선택 (프로젝트 타입인 경우만) */} + {watchedType === "project" && ( + { + const selectedProject = projects.find( + (p) => p.id === field.value + ) + const [popoverOpen, setPopoverOpen] = React.useState(false) + + return ( + + 프로젝트 + + + + + + + + + + + 프로젝트를 찾을 수 없습니다. + + {projects.map((project) => { + const label = `${project.name} (${project.code})` + return ( + { + field.onChange(project.id) + setPopoverOpen(false) + }} + > + {label} + + + ) + })} + + + + + + + + + ) + }} + /> + )} + + {/* 편집 사유 */} + ( + + 편집 사유 (선택사항) + +