diff --git a/src/components/Tables/SalesHistoryTable/index.tsx b/src/components/Tables/SalesHistoryTable/index.tsx index c9b01022..6470a3e6 100644 --- a/src/components/Tables/SalesHistoryTable/index.tsx +++ b/src/components/Tables/SalesHistoryTable/index.tsx @@ -1,125 +1,62 @@ -import { - Button, - Paper, - Stack, - Table, - TableBody, - TableContainer, - TableFooter, - TableHead, - TablePagination, - TableRow, -} from '@mui/material'; +import { Stack } from '@mui/material'; +import { TableComponent } from '@region-x/components'; +import { TableData } from '@region-x/components/dist/types/types'; import { useState } from 'react'; -import { getTimeStringLong } from '@/utils/functions'; - import { SaleDetailsModal } from '@/components'; import { SalesHistoryItem } from '@/models'; -import { StyledTableCell, StyledTableRow } from '../common'; - interface SalesHistoryTableProps { data: SalesHistoryItem[]; } export const SalesHistoryTable = ({ data }: SalesHistoryTableProps) => { - // table pagination - const [page, setPage] = useState(0); - const [rowsPerPage, setRowsPerPage] = useState(10); const [saleDetailsModalOpen, openSaleDetailsModal] = useState(false); const [saleSelected, selectSale] = useState(null); - const handleChangePage = ( - _event: React.MouseEvent | null, - newPage: number - ) => { - setPage(newPage); - }; + const formatTableData = (data: SalesHistoryItem[]): Record[] => { + const formattedData: Record[] = data.map((row, index) => { + return { + SaleId: { + cellType: 'jsx', + data: ( + { + selectSale(data[index]); + openSaleDetailsModal(true); + }} + > + {row.saleCycle} + + ), + }, + RegionBegin: { + cellType: 'text', + data: row.regionBegin.toString(), + }, + RegionEnd: { + cellType: 'text', + data: row.regionEnd.toString(), + }, + SaleStart: { + cellType: 'text', + data: row.startBlock.toString(), + }, + SaleEnd: { + cellType: 'text', + data: row.endBlock ? row.endBlock.toString() : '-', + }, + }; + }); - const handleChangeRowsPerPage = ( - event: React.ChangeEvent - ) => { - setRowsPerPage(parseInt(event.target.value, 10)); - setPage(0); + return formattedData; }; return ( - - - - - Sale Id - Region Begin - Region End - Sale Start - Sale End - - - - {(rowsPerPage > 0 - ? data.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage) - : data - ).map((info, index) => ( - - - - - {info.regionBegin} - {info.regionEnd} - - {getTimeStringLong(info.startTimestamp)} - - - {info.endTimestamp ? getTimeStringLong(info.endTimestamp) : 'Not yet ended'} - - - ))} - -
-
- - - - - - - -
-
+ {saleSelected !== null ? (