summaryrefslogtreecommitdiff
path: root/lib/vendor-investigation/table/investigation-table.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vendor-investigation/table/investigation-table.tsx')
-rw-r--r--lib/vendor-investigation/table/investigation-table.tsx177
1 files changed, 98 insertions, 79 deletions
diff --git a/lib/vendor-investigation/table/investigation-table.tsx b/lib/vendor-investigation/table/investigation-table.tsx
index 56aa7962..40b849fc 100644
--- a/lib/vendor-investigation/table/investigation-table.tsx
+++ b/lib/vendor-investigation/table/investigation-table.tsx
@@ -15,14 +15,9 @@ import { useFeatureFlags } from "./feature-flags-provider"
import { getColumns } from "./investigation-table-columns"
import { getVendorsInvestigation } from "../service"
import { VendorsTableToolbarActions } from "./investigation-table-toolbar-actions"
-import {
- VendorInvestigationsViewWithContacts,
- ContactItem,
- PossibleItem
-} from "@/config/vendorInvestigationsColumnsConfig"
+import { VendorInvestigationsViewWithContacts } from "@/config/vendorInvestigationsColumnsConfig"
import { UpdateVendorInvestigationSheet } from "./update-investigation-sheet"
-import { ItemsDrawer } from "./items-dialog"
-import { ContactsDialog } from "./contract-dialog"
+import { VendorDetailsDialog } from "./vendor-details-dialog"
interface VendorsTableProps {
promises: Promise<
@@ -38,38 +33,13 @@ export function VendorsInvestigationTable({ promises }: VendorsTableProps) {
// Get data from Suspense
const [rawResponse] = React.use(promises)
- // Transform the data to match the expected types
+ // Transform the data to match the expected types (simplified)
const transformedData: VendorInvestigationsViewWithContacts[] = React.useMemo(() => {
return rawResponse.data.map(item => {
- // Parse contacts field if it's a string
- let contacts: ContactItem[] = []
- if (typeof item.contacts === 'string') {
- try {
- contacts = JSON.parse(item.contacts) as ContactItem[]
- } catch (e) {
- console.error('Failed to parse contacts:', e)
- }
- } else if (Array.isArray(item.contacts)) {
- contacts = item.contacts
- }
-
- // Parse possibleItems field if it's a string
- let possibleItems: PossibleItem[] = []
- if (typeof item.possibleItems === 'string') {
- try {
- possibleItems = JSON.parse(item.possibleItems) as PossibleItem[]
- } catch (e) {
- console.error('Failed to parse possibleItems:', e)
- }
- } else if (Array.isArray(item.possibleItems)) {
- possibleItems = item.possibleItems
- }
-
- // Return a new object with the transformed fields
+ // Add id field for backward compatibility (maps to investigationId)
return {
...item,
- contacts,
- possibleItems
+ id: item.investigationId, // Map investigationId to id for backward compatibility
} as VendorInvestigationsViewWithContacts
})
}, [rawResponse.data])
@@ -81,51 +51,102 @@ export function VendorsInvestigationTable({ promises }: VendorsTableProps) {
// Add state for row actions
const [rowAction, setRowAction] = React.useState<DataTableRowAction<VendorInvestigationsViewWithContacts> | null>(null)
- // Add state for contacts dialog
- const [contactsDialogOpen, setContactsDialogOpen] = React.useState(false)
- const [selectedContacts, setSelectedContacts] = React.useState<ContactItem[]>([])
- const [selectedContactInvestigationId, setSelectedContactInvestigationId] = React.useState<number | null>(null)
+ // Add state for vendor details dialog
+ const [vendorDetailsOpen, setVendorDetailsOpen] = React.useState(false)
+ const [selectedVendorId, setSelectedVendorId] = React.useState<number | null>(null)
- // Add state for items drawer
- const [itemsDrawerOpen, setItemsDrawerOpen] = React.useState(false)
- const [selectedItems, setSelectedItems] = React.useState<PossibleItem[]>([])
- const [selectedItemInvestigationId, setSelectedItemInvestigationId] = React.useState<number | null>(null)
-
- // Create handlers for opening the contacts dialog and items drawer
- const openContactsModal = React.useCallback((investigationId: number, contacts: ContactItem[]) => {
- setSelectedContactInvestigationId(investigationId)
- setSelectedContacts(contacts || [])
- setContactsDialogOpen(true)
- }, [])
-
- const openItemsDrawer = React.useCallback((investigationId: number, items: PossibleItem[]) => {
- setSelectedItemInvestigationId(investigationId)
- setSelectedItems(items || [])
- setItemsDrawerOpen(true)
+ // Create handler for opening vendor details modal
+ const openVendorDetailsModal = React.useCallback((vendorId: number) => {
+ setSelectedVendorId(vendorId)
+ setVendorDetailsOpen(true)
}, [])
// Get router
const router = useRouter()
- // Call getColumns() with all required functions
+ // Call getColumns() with required functions (simplified)
const columns = React.useMemo(
() => getColumns({
setRowAction,
- openContactsModal,
- openItemsDrawer
+ openVendorDetailsModal
}),
- [setRowAction, openContactsModal, openItemsDrawer]
+ [setRowAction, openVendorDetailsModal]
)
+ // 기본 필터 필드들
const filterFields: DataTableFilterField<VendorInvestigationsViewWithContacts>[] = [
- { id: "vendorCode", label: "Vendor Code" },
+ { id: "vendorCode", label: "협력사 코드" },
+ { id: "vendorName", label: "협력사명" },
+ { id: "investigationStatus", label: "실사 상태" },
]
+ // 고급 필터 필드들
const advancedFilterFields: DataTableAdvancedFilterField<VendorInvestigationsViewWithContacts>[] = [
- { id: "vendorName", label: "Vendor Name", type: "text" },
- { id: "vendorCode", label: "Vendor Code", type: "text" },
+ // 협력업체 필터
+ { id: "vendorName", label: "협력사명", type: "text" },
+ { id: "vendorCode", label: "협력사 코드", type: "text" },
+
+ // 실사 상태 필터
+ {
+ id: "investigationStatus",
+ label: "실사 상태",
+ type: "select",
+ options: [
+ { label: "계획됨", value: "PLANNED" },
+ { label: "진행 중", value: "IN_PROGRESS" },
+ { label: "완료됨", value: "COMPLETED" },
+ { label: "취소됨", value: "CANCELED" },
+ ]
+ },
+ {
+ id: "evaluationType",
+ label: "평가 유형",
+ type: "select",
+ options: [
+ { label: "실사의뢰평가", value: "SITE_AUDIT" },
+ { label: "QM자체평가", value: "QM_SELF_AUDIT" },
+ ]
+ },
+ {
+ id: "evaluationResult",
+ label: "평가 결과",
+ type: "select",
+ options: [
+ { label: "승인", value: "APPROVED" },
+ { label: "보완", value: "SUPPLEMENT" },
+ { label: "불가", value: "REJECTED" },
+ ]
+ },
+
+ // 점수 필터
+ { id: "evaluationScore", label: "평가 점수", type: "number" },
+
+ // 담당자 필터
+ { id: "requesterName", label: "의뢰자", type: "text" },
+ { id: "qmManagerName", label: "QM 담당자", type: "text" },
+
+ // 첨부파일 필터
+ {
+ id: "hasAttachments",
+ label: "첨부파일 유무",
+ type: "select",
+ options: [
+ { label: "첨부파일 있음", value: "true" },
+ { label: "첨부파일 없음", value: "false" },
+ ]
+ },
+
+ // 주요 날짜 필터
+ { id: "forecastedAt", label: "실사 예정일", type: "date" },
+ { id: "requestedAt", label: "실사 의뢰일", type: "date" },
+ { id: "confirmedAt", label: "실사 확정일", type: "date" },
+ { id: "completedAt", label: "실제 실사일", type: "date" },
+
+ // 메모 필터
+ { id: "investigationNotes", label: "QM 의견", type: "text" },
]
+ // 데이터 테이블 초기화
const { table } = useDataTable({
data: transformedData,
columns,
@@ -134,10 +155,17 @@ export function VendorsInvestigationTable({ promises }: VendorsTableProps) {
enablePinning: true,
enableAdvancedFilter: true,
initialState: {
- sorting: [{ id: "investigationCreatedAt", desc: true }],
+ sorting: [{ id: "createdAt", desc: true }],
columnPinning: { right: ["actions"] },
+ columnVisibility: {
+ // 자주 사용하지 않는 컬럼들은 기본적으로 숨김
+ // investigationAddress: false,
+ // investigationMethod: false,
+ // requestedAt: false,
+ // confirmedAt: false,
+ }
},
- getRowId: (originalRow) => String(originalRow.investigationId),
+ getRowId: (originalRow) => String(originalRow.investigationId ?? originalRow.id),
shallow: false,
clearOnDefault: true,
})
@@ -162,21 +190,12 @@ export function VendorsInvestigationTable({ promises }: VendorsTableProps) {
onOpenChange={() => setRowAction(null)}
investigation={rowAction?.row.original ?? null}
/>
-
- {/* Contacts Dialog */}
- <ContactsDialog
- open={contactsDialogOpen}
- onOpenChange={setContactsDialogOpen}
- investigationId={selectedContactInvestigationId}
- contacts={selectedContacts}
- />
-
- {/* Items Drawer */}
- <ItemsDrawer
- open={itemsDrawerOpen}
- onOpenChange={setItemsDrawerOpen}
- investigationId={selectedItemInvestigationId}
- items={selectedItems}
+
+ {/* Vendor Details Dialog */}
+ <VendorDetailsDialog
+ open={vendorDetailsOpen}
+ onOpenChange={setVendorDetailsOpen}
+ vendorId={selectedVendorId}
/>
</>
)