From 8945be5ea89365f8a686a0e65b5a7d5b61c2ca20 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Fri, 3 Oct 2025 13:54:38 +0900 Subject: (김준회) 부서별 권한관리, swp 코멘트 기능, 벤더 po, shi-api 동기화 로직 수정 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plant/document-comment-dialog.tsx | 183 +++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 lib/vendor-document-list/plant/document-comment-dialog.tsx (limited to 'lib/vendor-document-list/plant/document-comment-dialog.tsx') diff --git a/lib/vendor-document-list/plant/document-comment-dialog.tsx b/lib/vendor-document-list/plant/document-comment-dialog.tsx new file mode 100644 index 00000000..3dc3d321 --- /dev/null +++ b/lib/vendor-document-list/plant/document-comment-dialog.tsx @@ -0,0 +1,183 @@ +"use client" + +import React from "react" +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { Button } from "@/components/ui/button" +import { Textarea } from "@/components/ui/textarea" +import { Label } from "@/components/ui/label" +import { ScrollArea } from "@/components/ui/scroll-area" +import { Loader2, MessageSquare } from "lucide-react" +import { toast } from "sonner" +import { useSession } from "next-auth/react" +import { addDocumentComment } from "./document-stages-service" +import { useRouter } from "next/navigation" +import { cn } from "@/lib/utils" + +interface DocumentCommentDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + documentId: number + docNumber: string + currentComment: string | null +} + +export function DocumentCommentDialog({ + open, + onOpenChange, + documentId, + docNumber, + currentComment, +}: DocumentCommentDialogProps) { + const [newComment, setNewComment] = React.useState("") + const [isSubmitting, setIsSubmitting] = React.useState(false) + const { data: session } = useSession() + const router = useRouter() + + // 기존 코멘트를 줄 단위로 파싱 + const existingComments = React.useMemo(() => { + if (!currentComment) return [] + return currentComment.split('\n').filter(line => line.trim() !== '') + }, [currentComment]) + + const handleSubmit = async () => { + if (!newComment.trim()) { + toast.error("코멘트 내용을 입력해주세요.") + return + } + + if (!session?.user?.name || !session?.user?.email) { + toast.error("사용자 정보를 가져올 수 없습니다.") + return + } + + setIsSubmitting(true) + try { + const result = await addDocumentComment({ + documentId, + newComment: newComment.trim(), + userInfo: { + name: session.user.name, + email: session.user.email, + }, + }) + + if (result.success) { + toast.success("코멘트가 추가되었습니다.") + setNewComment("") + onOpenChange(false) + router.refresh() + } else { + toast.error(result.error || "코멘트 추가 중 오류가 발생했습니다.") + } + } catch (error) { + console.error("Error adding comment:", error) + toast.error("코멘트 추가 중 오류가 발생했습니다.") + } finally { + setIsSubmitting(false) + } + } + + const handleClose = () => { + if (!isSubmitting) { + setNewComment("") + onOpenChange(false) + } + } + + return ( + + + + + + Document Comment + + + 문서번호: {docNumber} + + + +
+ {/* 기존 코멘트 표시 영역 (읽기 전용) */} +
+ + + {existingComments.length > 0 ? ( +
+ {existingComments.map((comment, index) => ( +
+ {comment} +
+ ))} +
+ ) : ( +
+ 기존 코멘트가 없습니다. +
+ )} +
+
+ + {/* 새 코멘트 입력 영역 */} +
+ +