summaryrefslogtreecommitdiff
path: root/lib/vendors/bid-history-table/bid-history-table.tsx
blob: e41db58aeb2a3801a984787d8f4818090a68ce93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
"use client";

import * as React from "react";
import { useRouter } from "next/navigation";
import type {
  DataTableAdvancedFilterField,
  DataTableFilterField,
  DataTableRowAction,
} from "@/types/table";

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 { getColumns } from "./bid-history-table-columns";
import { getBidHistory } from "../service";
import { TooltipProvider } from "@/components/ui/tooltip";

export interface BidHistoryRow {
  id: number;
  biddingId: number;
  biddingNumber: string | null;
  revision: number | null;
  contractType: "unit_price" | "general" | "sale";
  biddingType: "equipment" | "construction" | "service" | "lease" | "steel_stock" | "piping" | "transport" | "waste" | "sale";
  biddingStatus: "bidding_generated" | "request_for_quotation" | "received_quotation" | "set_target_price" | "bidding_opened" | "bidding_closed" | "evaluation_of_bidding" | "bidding_disposal" | "vendor_selected";
  projectCode: string | null;
  projectName: string | null;
  itemName: string | null;
  materialGroup: string | null;
  materialGroupName: string | null;
  biddingTitle: string | null;
  poNumber: string | null;
  contractNumber: string | null;
  biddingRequestDate: Date | null;
  biddingDeadline: Date | null;
  biddingManager: string | null;
  currency: string | null;
  finalBidPrice: string | null;
  expectedAmount: string | null;
  awardRatio: string | null;
  preQuotePrice: string | null;
  createdAt: Date;
  updatedAt: Date;
}

interface BidHistoryTableProps {
  promises: Promise<
    [
      Awaited<ReturnType<typeof getBidHistory>>,
    ]
  >;
  lng: string;
}

export function VendorBidHistoryTable({ promises, lng }: BidHistoryTableProps) {
  const router = useRouter();

  // SSR을 위해 React.use() 사용 - 서버에서 렌더링된 데이터를 클라이언트에서 사용
  const [{ data = [], pageCount = 0 }] = React.use(promises);

  const [, setRowAction] = React.useState<DataTableRowAction<BidHistoryRow> | null>(null);

  const handleViewDetails = React.useCallback((biddingId: number) => {
    router.push(`/${lng}/evcp/bid/${biddingId}/detail`);
  }, [router, lng]);

  const columns = React.useMemo(() => getColumns({
    setRowAction,
    onViewDetails: handleViewDetails,
  }), [setRowAction, handleViewDetails]);

  const filterFields: DataTableFilterField<BidHistoryRow>[] = [
    {
      id: "biddingNumber",
      label: "입찰번호",
      placeholder: "입찰번호로 검색...",
    },
    {
      id: "contractType",
      label: "계약구분",
      options: [
        { label: "단가", value: "unit_price" },
        { label: "일반", value: "general" },
        { label: "매각", value: "sale" }
      ],
    },
    {
      id: "biddingType",
      label: "입찰유형",
      options: [
        { label: "기자재", value: "equipment" },
        { label: "공사", value: "construction" },
        { label: "용역", value: "service" },
        { label: "임차", value: "lease" },
        { label: "운송", value: "transport" },
        { label: "폐기물", value: "waste" },
        { label: "매각", value: "sale" }
      ],
    },
    {
      id: "biddingStatus",
      label: "입찰상태",
      options: [
        { label: "입찰생성", value: "bidding_generated" },
        { label: "사전견적요청", value: "request_for_quotation" },
        { label: "사전견적접수", value: "received_quotation" },
        { label: "내정가산정", value: "set_target_price" },
        { label: "입찰공고", value: "bidding_opened" },
        { label: "입찰마감", value: "bidding_closed" },
        { label: "입찰평가중", value: "evaluation_of_bidding" },
        { label: "유찰", value: "bidding_disposal" },
        { label: "업체선정", value: "vendor_selected" }
      ],
    },
    {
      id: "projectName",
      label: "프로젝트명",
      placeholder: "프로젝트명으로 검색...",
    }
  ];

  const advancedFilterFields: DataTableAdvancedFilterField<BidHistoryRow>[] = [
    { id: "biddingNumber", label: "입찰번호", type: "text" },
    { id: "projectCode", label: "프로젝트코드", type: "text" },
    { id: "projectName", label: "프로젝트명", type: "text" },
    {
      id: "contractType",
      label: "계약구분",
      type: "multi-select",
      options: [
        { label: "단가", value: "unit_price" },
        { label: "일반", value: "general" },
        { label: "매각", value: "sale" }
      ],
    },
    {
      id: "biddingType",
      label: "입찰유형",
      type: "multi-select",
      options: [
        { label: "기자재", value: "equipment" },
        { label: "공사", value: "construction" },
        { label: "용역", value: "service" },
        { label: "임차", value: "lease" },
        { label: "형강스톡", value: "steel_stock" },
        { label: "배관", value: "piping" },
        { label: "운송", value: "transport" },
        { label: "폐기물", value: "waste" },
        { label: "매각", value: "sale" }
      ],
    },
    {
      id: "biddingStatus",
      label: "입찰상태",
      type: "multi-select",
      options: [
        { label: "입찰생성", value: "bidding_generated" },
        { label: "사전견적요청", value: "request_for_quotation" },
        { label: "사전견적접수", value: "received_quotation" },
        { label: "내정가산정", value: "set_target_price" },
        { label: "입찰공고", value: "bidding_opened" },
        { label: "입찰마감", value: "bidding_closed" },
        { label: "입찰평가중", value: "evaluation_of_bidding" },
        { label: "유찰", value: "bidding_disposal" },
        { label: "업체선정", value: "vendor_selected" }
      ],
    },
    { id: "biddingManager", label: "입찰담당자", type: "text" },
    { id: "biddingRequestDate", label: "입찰요청일", type: "date" },
    { id: "biddingDeadline", label: "입찰마감일", type: "date" },
    { id: "createdAt", label: "생성일", type: "date" },
  ];

  const { table } = useDataTable({
    data,
    columns,
    pageCount,
    filterFields,
    enablePinning: true,
    enableAdvancedFilter: true,
    initialState: {
      sorting: [{ id: "createdAt", desc: true }],
      columnPinning: { right: ["actions"] },
    },
    getRowId: (originalRow, index) => originalRow?.id ? String(originalRow.id) : String(index),
    shallow: false,
    clearOnDefault: true,
  });

  return (
    <>
      <TooltipProvider>
        <DataTable
          table={table}
        >
          <DataTableAdvancedToolbar
            table={table}
            filterFields={advancedFilterFields}
            shallow={false}
          >
          </DataTableAdvancedToolbar>
        </DataTable>
      </TooltipProvider>
    </>
  );
}