summaryrefslogtreecommitdiff
path: root/lib/rfqs/vendor-table/vendors-table.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rfqs/vendor-table/vendors-table.tsx')
-rw-r--r--lib/rfqs/vendor-table/vendors-table.tsx77
1 files changed, 53 insertions, 24 deletions
diff --git a/lib/rfqs/vendor-table/vendors-table.tsx b/lib/rfqs/vendor-table/vendors-table.tsx
index 838342bf..ae9cba41 100644
--- a/lib/rfqs/vendor-table/vendors-table.tsx
+++ b/lib/rfqs/vendor-table/vendors-table.tsx
@@ -2,6 +2,7 @@
import * as React from "react"
import { useRouter } from "next/navigation"
+import { useSession } from "next-auth/react" // Next-auth session hook 추가
import type {
DataTableAdvancedFilterField,
DataTableFilterField,
@@ -22,6 +23,7 @@ import { InviteVendorsDialog } from "./invite-vendors-dialog"
import { CommentSheet, MatchedVendorComment } from "./comments-sheet"
import { MatchedVendorRow } from "@/config/vendorRfbColumnsConfig"
import { RfqType } from "@/lib/rfqs/validations"
+import { toast } from "sonner"
interface VendorsTableProps {
promises: Promise<[Awaited<ReturnType<typeof getMatchedVendors>>]>
@@ -29,8 +31,11 @@ interface VendorsTableProps {
rfqType: RfqType
}
-export function MatchedVendorsTable({ promises, rfqId, rfqType}: VendorsTableProps) {
+export function MatchedVendorsTable({ promises, rfqId, rfqType }: VendorsTableProps) {
const { featureFlags } = useFeatureFlags()
+ const { data: session } = useSession() // 세션 정보 가져오기
+
+
// 1) Suspense로 받아온 데이터
const [{ data, pageCount }] = React.use(promises)
@@ -47,10 +52,13 @@ export function MatchedVendorsTable({ promises, rfqId, rfqType}: VendorsTablePr
const router = useRouter()
// 3) CommentSheet 에 넣을 상태
- // => “댓글”은 MatchedVendorComment[] 로 관리해야 함
+ // => "댓글"은 MatchedVendorComment[] 로 관리해야 함
const [initialComments, setInitialComments] = React.useState<
MatchedVendorComment[]
>([])
+
+ const [isLoadingComments, setIsLoadingComments] = React.useState(false)
+
const [commentSheetOpen, setCommentSheetOpen] = React.useState(false)
const [selectedVendorIdForComments, setSelectedVendorIdForComments] =
React.useState<number | null>(null)
@@ -64,29 +72,42 @@ export function MatchedVendorsTable({ promises, rfqId, rfqType}: VendorsTablePr
// 5) 댓글 시트 오픈 함수
async function openCommentSheet(vendorId: number) {
+ // Clear previous comments
setInitialComments([])
-
+
+ // Start loading
+ setIsLoadingComments(true)
+
+ // Open the sheet immediately with loading state
+ setSelectedVendorIdForComments(vendorId)
+ setCommentSheetOpen(true)
+
// (a) 현재 Row의 comments 불러옴
const comments = rowAction?.row.original.comments
- if (comments && comments.length > 0) {
- // (b) 각 comment마다 첨부파일 fetch
- const commentWithAttachments: MatchedVendorComment[] = await Promise.all(
- comments.map(async (c) => {
- const attachments = await fetchRfqAttachmentsbyCommentId(c.id)
- return {
- ...c,
- attachments,
- }
- })
- )
- setInitialComments(commentWithAttachments)
+
+ try {
+ if (comments && comments.length > 0) {
+ // (b) 각 comment마다 첨부파일 fetch
+ const commentWithAttachments: MatchedVendorComment[] = await Promise.all(
+ comments.map(async (c) => {
+ const attachments = await fetchRfqAttachmentsbyCommentId(c.id)
+ return {
+ ...c,
+ attachments,
+ }
+ })
+ )
+ setInitialComments(commentWithAttachments)
+ }
+ } catch (error) {
+ console.error("Error loading comments:", error)
+ toast.error("Failed to load comments")
+ } finally {
+ // End loading regardless of success/failure
+ setIsLoadingComments(false)
}
-
- // (c) vendorId state
- setSelectedVendorIdForComments(vendorId)
- setCommentSheetOpen(true)
}
-
+
// 6) 컬럼 정의 (memo)
const columns = React.useMemo(
() => getColumns({ setRowAction, router, openCommentSheet }),
@@ -140,9 +161,16 @@ export function MatchedVendorsTable({ promises, rfqId, rfqType}: VendorsTablePr
clearOnDefault: true,
})
+ // 세션에서 userId 추출하고 숫자로 변환
+ const currentUserId = session?.user?.id ? parseInt(session.user.id, 10) : 0
+
+ console.log(currentUserId,"currentUserId")
+
return (
- <>
- <DataTable table={table}>
+ <div style={{ maxWidth: '80vw' }}>
+ <DataTable
+ table={table}
+ >
<DataTableAdvancedToolbar
table={table}
filterFields={advancedFilterFields}
@@ -169,13 +197,14 @@ export function MatchedVendorsTable({ promises, rfqId, rfqType}: VendorsTablePr
initialComments={initialComments}
rfqId={rfqId}
vendorId={selectedVendorIdForComments ?? 0}
- currentUserId={1}
+ currentUserId={currentUserId}
+ isLoading={isLoadingComments} // Pass the loading state
onCommentsUpdated={(updatedComments) => {
// Row 의 comments 필드도 업데이트
if (!rowAction?.row) return
rowAction.row.original.comments = updatedComments
}}
/>
- </>
+ </div>
)
} \ No newline at end of file