From 1a2241c40e10193c5ff7008a7b7b36cc1d855d96 Mon Sep 17 00:00:00 2001 From: joonhoekim <26rote@gmail.com> Date: Tue, 25 Mar 2025 15:55:45 +0900 Subject: initial commit --- lib/rfqs/vendor-table/add-vendor-dialog.tsx | 37 +++ lib/rfqs/vendor-table/comments-sheet.tsx | 303 +++++++++++++++++++++ lib/rfqs/vendor-table/feature-flags-provider.tsx | 108 ++++++++ lib/rfqs/vendor-table/invite-vendors-dialog.tsx | 177 ++++++++++++ .../vendor-list/vendor-list-table-column.tsx | 154 +++++++++++ .../vendor-table/vendor-list/vendor-list-table.tsx | 142 ++++++++++ lib/rfqs/vendor-table/vendors-table-columns.tsx | 264 ++++++++++++++++++ .../vendor-table/vendors-table-floating-bar.tsx | 137 ++++++++++ .../vendor-table/vendors-table-toolbar-actions.tsx | 84 ++++++ lib/rfqs/vendor-table/vendors-table.tsx | 181 ++++++++++++ 10 files changed, 1587 insertions(+) create mode 100644 lib/rfqs/vendor-table/add-vendor-dialog.tsx create mode 100644 lib/rfqs/vendor-table/comments-sheet.tsx create mode 100644 lib/rfqs/vendor-table/feature-flags-provider.tsx create mode 100644 lib/rfqs/vendor-table/invite-vendors-dialog.tsx create mode 100644 lib/rfqs/vendor-table/vendor-list/vendor-list-table-column.tsx create mode 100644 lib/rfqs/vendor-table/vendor-list/vendor-list-table.tsx create mode 100644 lib/rfqs/vendor-table/vendors-table-columns.tsx create mode 100644 lib/rfqs/vendor-table/vendors-table-floating-bar.tsx create mode 100644 lib/rfqs/vendor-table/vendors-table-toolbar-actions.tsx create mode 100644 lib/rfqs/vendor-table/vendors-table.tsx (limited to 'lib/rfqs/vendor-table') diff --git a/lib/rfqs/vendor-table/add-vendor-dialog.tsx b/lib/rfqs/vendor-table/add-vendor-dialog.tsx new file mode 100644 index 00000000..8ec5b9f4 --- /dev/null +++ b/lib/rfqs/vendor-table/add-vendor-dialog.tsx @@ -0,0 +1,37 @@ +"use client" + +import * as React from "react" +import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog" +import { Button } from "@/components/ui/button" +import { VendorsListTable } from "./vendor-list/vendor-list-table" + +interface VendorsListTableProps { + rfqId: number // so we know which RFQ to insert into + } + + +/** + * A dialog that contains a client-side table or infinite scroll + * for "all vendors," allowing the user to select vendors and add them to the RFQ. + */ +export function AddVendorDialog({ rfqId }: VendorsListTableProps) { + const [open, setOpen] = React.useState(false) + + return ( + + + + + + + Add Vendor to RFQ + + + + + + + ) +} \ No newline at end of file diff --git a/lib/rfqs/vendor-table/comments-sheet.tsx b/lib/rfqs/vendor-table/comments-sheet.tsx new file mode 100644 index 00000000..644869c6 --- /dev/null +++ b/lib/rfqs/vendor-table/comments-sheet.tsx @@ -0,0 +1,303 @@ +"use client" + +import * as React from "react" +import { useForm, useFieldArray } from "react-hook-form" +import { z } from "zod" +import { zodResolver } from "@hookform/resolvers/zod" +import { Loader, Download, X } from "lucide-react" +import prettyBytes from "pretty-bytes" +import { toast } from "sonner" + +import { + Sheet, + SheetClose, + SheetContent, + SheetDescription, + SheetFooter, + SheetHeader, + SheetTitle, +} from "@/components/ui/sheet" +import { Button } from "@/components/ui/button" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { Textarea } from "@/components/ui/textarea" +import { + Dropzone, + DropzoneZone, + DropzoneUploadIcon, + DropzoneTitle, + DropzoneDescription, + DropzoneInput, +} from "@/components/ui/dropzone" +import { + Table, + TableHeader, + TableRow, + TableHead, + TableBody, + TableCell, +} from "@/components/ui/table" + +import { createRfqCommentWithAttachments } from "../service" +import { formatDate } from "@/lib/utils" + + +export interface MatchedVendorComment { + id: number + commentText: string + commentedBy?: number + createdAt?: Date + attachments?: { + id: number + fileName: string + filePath: string + }[] +} + +// 1) props 정의 +interface CommentSheetProps extends React.ComponentPropsWithRef { + initialComments?: MatchedVendorComment[] + currentUserId: number + rfqId: number + vendorId: number + onCommentsUpdated?: (comments: MatchedVendorComment[]) => void +} + +// 2) 폼 스키마 +const commentFormSchema = z.object({ + commentText: z.string().min(1, "댓글을 입력하세요."), + newFiles: z.array(z.any()).optional(), // File[] +}) +type CommentFormValues = z.infer + +const MAX_FILE_SIZE = 30e6 // 30MB + +export function CommentSheet({ + rfqId, + vendorId, + initialComments = [], + currentUserId, + onCommentsUpdated, + ...props +}: CommentSheetProps) { + const [comments, setComments] = React.useState(initialComments) + const [isPending, startTransition] = React.useTransition() + + React.useEffect(() => { + setComments(initialComments) + }, [initialComments]) + + const form = useForm({ + resolver: zodResolver(commentFormSchema), + defaultValues: { + commentText: "", + newFiles: [], + }, + }) + + const { fields: newFileFields, append, remove } = useFieldArray({ + control: form.control, + name: "newFiles", + }) + + // (A) 기존 코멘트 렌더링 + function renderExistingComments() { + if (comments.length === 0) { + return

No comments yet

+ } + return ( + + + + Comment + Attachments + Created At + Created By + + + + {comments.map((c) => ( + + {c.commentText} + + {!c.attachments?.length && ( + No files + )} + {c.attachments?.length && ( +
+ {c.attachments.map((att) => ( + + ))} +
+ )} +
+ { c.createdAt ? formatDate(c.createdAt): "-"} + {c.commentedBy ?? "-"} +
+ ))} +
+
+ ) + } + + // (B) 파일 드롭 + function handleDropAccepted(files: File[]) { + append(files) + } + + // (C) Submit + async function onSubmit(data: CommentFormValues) { + if (!rfqId) return + startTransition(async () => { + try { + const res = await createRfqCommentWithAttachments({ + rfqId, + vendorId, + commentText: data.commentText, + commentedBy: currentUserId, + evaluationId: null, + files: data.newFiles, + }) + + if (!res.ok) { + throw new Error("Failed to create comment") + } + + toast.success("Comment created") + + // 임시로 새 코멘트 추가 + const newComment: MatchedVendorComment = { + id: res.commentId, // 서버 응답 + commentText: data.commentText, + commentedBy: currentUserId, + createdAt: res.createdAt, + attachments: + data.newFiles?.map((f) => ({ + id: Math.floor(Math.random() * 1e6), + fileName: f.name, + filePath: "/uploads/" + f.name, + })) || [], + } + setComments((prev) => [...prev, newComment]) + onCommentsUpdated?.([...comments, newComment]) + + form.reset() + } catch (err: any) { + console.error(err) + toast.error("Error: " + err.message) + } + }) + } + + return ( + + + + Comments + + 필요시 첨부파일과 함께 문의/코멘트를 남길 수 있습니다. + + + +
{renderExistingComments()}
+ +
+ + ( + + New Comment + +