diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-04-28 02:13:30 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-04-28 02:13:30 +0000 |
| commit | ef4c533ebacc2cdc97e518f30e9a9350004fcdfb (patch) | |
| tree | 345251a3ed0f4429716fa5edaa31024d8f4cb560 /lib/rfqs/cbe-table/cbe-table.tsx | |
| parent | 9ceed79cf32c896f8a998399bf1b296506b2cd4a (diff) | |
~20250428 작업사항
Diffstat (limited to 'lib/rfqs/cbe-table/cbe-table.tsx')
| -rw-r--r-- | lib/rfqs/cbe-table/cbe-table.tsx | 123 |
1 files changed, 68 insertions, 55 deletions
diff --git a/lib/rfqs/cbe-table/cbe-table.tsx b/lib/rfqs/cbe-table/cbe-table.tsx index b2a74466..37fbc3f4 100644 --- a/lib/rfqs/cbe-table/cbe-table.tsx +++ b/lib/rfqs/cbe-table/cbe-table.tsx @@ -8,16 +8,17 @@ import type { DataTableRowAction, } from "@/types/table" -import { toSentenceCase } from "@/lib/utils" import { useDataTable } from "@/hooks/use-data-table" import { DataTable } from "@/components/data-table/data-table" import { DataTableAdvancedToolbar } from "@/components/data-table/data-table-advanced-toolbar" -import { useFeatureFlags } from "./feature-flags-provider" -import { Vendor, vendors } from "@/db/schema/vendors" import { fetchRfqAttachmentsbyCommentId, getCBE } from "../service" -import { TbeComment } from "../tbe-table/comments-sheet" import { getColumns } from "./cbe-table-columns" import { VendorWithCbeFields } from "@/config/vendorCbeColumnsConfig" +import { CommentSheet, CbeComment } from "./comments-sheet" +import { useSession } from "next-auth/react" // Next-auth session hook 추가 +import { VendorContactsDialog } from "./vendor-contact-dialog" +import { InviteVendorsDialog } from "./invite-vendors-dialog" +import { VendorsTableToolbarActions } from "./cbe-table-toolbar-actions" interface VendorsTableProps { promises: Promise< @@ -30,56 +31,54 @@ interface VendorsTableProps { export function CbeTable({ promises, rfqId }: VendorsTableProps) { - const { featureFlags } = useFeatureFlags() // Suspense로 받아온 데이터 const [{ data, pageCount }] = React.use(promises) + const { data: session } = useSession() // 세션 정보 가져오기 + + const currentUserId = session?.user?.id ? parseInt(session.user.id, 10) : 0 + const currentUser = session?.user - console.log(data, "data") const [rowAction, setRowAction] = React.useState<DataTableRowAction<VendorWithCbeFields> | null>(null) // **router** 획득 const router = useRouter() - const [initialComments, setInitialComments] = React.useState<TbeComment[]>([]) + const [initialComments, setInitialComments] = React.useState<CbeComment[]>([]) const [commentSheetOpen, setCommentSheetOpen] = React.useState(false) - const [selectedRfqIdForComments, setSelectedRfqIdForComments] = React.useState<number | null>(null) - - const [isFileDialogOpen, setIsFileDialogOpen] = React.useState(false) - const [selectedVendorId, setSelectedVendorId] = React.useState<number | null>(null) - const [selectedTbeId, setSelectedTbeId] = React.useState<number | null>(null) + const [isLoadingComments, setIsLoadingComments] = React.useState(false) + // const [selectedRfqIdForComments, setSelectedRfqIdForComments] = React.useState<number | null>(null) - // Add handleRefresh function - const handleRefresh = React.useCallback(() => { - router.refresh(); - }, [router]); + const [selectedVendorId, setSelectedVendorId] = React.useState<number | null>(null) + const [selectedCbeId, setSelectedCbeId] = React.useState<number | null>(null) + const [isContactDialogOpen, setIsContactDialogOpen] = React.useState(false) + const [selectedVendor, setSelectedVendor] = React.useState<VendorWithCbeFields | null>(null) + // console.log("selectedVendorId", selectedVendorId) + // console.log("selectedCbeId", selectedCbeId) React.useEffect(() => { if (rowAction?.type === "comments") { // rowAction가 새로 세팅된 뒤 여기서 openCommentSheet 실행 - openCommentSheet(Number(rowAction.row.original.id)) - } else if (rowAction?.type === "files") { - // Handle files action - const vendorId = rowAction.row.original.vendorId; - const cbeId = rowAction.row.original.cbeId ?? 0; - openFilesDialog(cbeId, vendorId); - } + openCommentSheet(Number(rowAction.row.original.responseId)) + } }, [rowAction]) - async function openCommentSheet(vendorId: number) { + async function openCommentSheet(responseId: number) { setInitialComments([]) - + setIsLoadingComments(true) const comments = rowAction?.row.original.comments + // const rfqId = rowAction?.row.original.rfqId + const vendorId = rowAction?.row.original.vendorId if (comments && comments.length > 0) { - const commentWithAttachments: TbeComment[] = await Promise.all( + const commentWithAttachments: CbeComment[] = await Promise.all( comments.map(async (c) => { const attachments = await fetchRfqAttachmentsbyCommentId(c.id) return { ...c, - commentedBy: 1, // DB나 API 응답에 있다고 가정 + commentedBy: currentUserId, // DB나 API 응답에 있다고 가정 attachments, } }) @@ -88,20 +87,22 @@ export function CbeTable({ promises, rfqId }: VendorsTableProps) { setInitialComments(commentWithAttachments) } - setSelectedRfqIdForComments(vendorId) + // if(rfqId){ setSelectedRfqIdForComments(rfqId)} + if(vendorId){ setSelectedVendorId(vendorId)} + setSelectedCbeId(responseId) setCommentSheetOpen(true) + setIsLoadingComments(false) } - const openFilesDialog = (cbeId: number, vendorId: number) => { - setSelectedTbeId(cbeId) + const openVendorContactsDialog = (vendorId: number, vendor: VendorWithCbeFields) => { setSelectedVendorId(vendorId) - setIsFileDialogOpen(true) + setSelectedVendor(vendor) + setIsContactDialogOpen(true) } - // getColumns() 호출 시, router를 주입 const columns = React.useMemo( - () => getColumns({ setRowAction, router, openCommentSheet, openFilesDialog }), + () => getColumns({ setRowAction, router, openCommentSheet, openVendorContactsDialog }), [setRowAction, router] ) @@ -111,18 +112,7 @@ export function CbeTable({ promises, rfqId }: VendorsTableProps) { const advancedFilterFields: DataTableAdvancedFilterField<VendorWithCbeFields>[] = [ { id: "vendorName", label: "Vendor Name", type: "text" }, { id: "vendorCode", label: "Vendor Code", type: "text" }, - { id: "email", label: "Email", type: "text" }, - { id: "country", label: "Country", type: "text" }, - { - id: "vendorStatus", - label: "Vendor Status", - type: "multi-select", - options: vendors.status.enumValues.map((status) => ({ - label: toSentenceCase(status), - value: status, - })), - }, - { id: "rfqVendorUpdated", label: "Updated at", type: "date" }, + { id: "respondedAt", label: "Updated at", type: "date" }, ] @@ -134,32 +124,55 @@ export function CbeTable({ promises, rfqId }: VendorsTableProps) { enablePinning: true, enableAdvancedFilter: true, initialState: { - sorting: [{ id: "rfqVendorUpdated", desc: true }], - columnPinning: { right: ["actions"] }, + sorting: [{ id: "respondedAt", desc: true }], + columnPinning: { right: ["comments"] }, }, - getRowId: (originalRow) => String(originalRow.id), + getRowId: (originalRow) => String(originalRow.responseId), shallow: false, clearOnDefault: true, }) return ( <> -<div style={{ maxWidth: '80vw' }}> -<DataTable + <DataTable table={table} - // tableContainerClass="sm:max-w-[80vw] md:max-w-[80vw] lg:max-w-[80vw]" - // tableContainerClass="max-w-[80vw]" > <DataTableAdvancedToolbar table={table} filterFields={advancedFilterFields} shallow={false} > - {/* <VendorsTableToolbarActions table={table} rfqId={rfqId} /> */} + <VendorsTableToolbarActions table={table} rfqId={rfqId} /> </DataTableAdvancedToolbar> </DataTable> - </div> - + + <CommentSheet + currentUserId={currentUserId} + open={commentSheetOpen} + onOpenChange={setCommentSheetOpen} + rfqId={rfqId} + cbeId={selectedCbeId ?? 0} + vendorId={selectedVendorId ?? 0} + isLoading={isLoadingComments} + initialComments={initialComments} + /> + + <InviteVendorsDialog + vendors={rowAction?.row.original ? [rowAction?.row.original] : []} + onOpenChange={() => setRowAction(null)} + rfqId={rfqId} + open={rowAction?.type === "invite"} + showTrigger={false} + currentUser={currentUser} + /> + + <VendorContactsDialog + isOpen={isContactDialogOpen} + onOpenChange={setIsContactDialogOpen} + vendorId={selectedVendorId} + vendor={selectedVendor} + /> + </> ) }
\ No newline at end of file |
