mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +00:00
tweak(bank/nui): Use material table for transactions
This commit is contained in:
1 parent
e516de9405
commit
0b597eb3ae
1 file changed
+108
-11
@@ -1,19 +1,116 @@
|
||||
import React from "react";
|
||||
import React, { useState } from "react";
|
||||
import { List } from "../../../../ui/components/List";
|
||||
import { ListItem } from "../../../../ui/components/ListItem";
|
||||
import ListItemText from "@material-ui/core/ListItemText";
|
||||
import { Typography, makeStyles } from "@material-ui/core";
|
||||
|
||||
import Table from '@material-ui/core/Table';
|
||||
import TableBody from '@material-ui/core/TableBody';
|
||||
import TableCell from '@material-ui/core/TableCell';
|
||||
import TableContainer from '@material-ui/core/TableContainer';
|
||||
import TableHead from '@material-ui/core/TableHead';
|
||||
import TableRow from '@material-ui/core/TableRow';
|
||||
import TablePagination from '@material-ui/core/TablePagination';
|
||||
import Paper from '@material-ui/core/Paper';
|
||||
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
paper: {
|
||||
padding: theme.spacing(1),
|
||||
textAlign: 'center',
|
||||
width: "50%",
|
||||
backgroundColor: "#2d3436",
|
||||
margin: 20,
|
||||
color: "#fff",
|
||||
},
|
||||
table: {
|
||||
width: "100%",
|
||||
color: "#fff"
|
||||
},
|
||||
cell: {
|
||||
color: "#fff",
|
||||
},
|
||||
container: {
|
||||
maxHeight: 350,
|
||||
},
|
||||
list: {
|
||||
marginTop: "13em"
|
||||
}
|
||||
}))
|
||||
|
||||
const columns = [
|
||||
{ id: 'type', label: 'Type', minWidth: 100 },
|
||||
{ id: 'amount', label: 'Amount', minWidth: 100 },
|
||||
{
|
||||
id: 'message',
|
||||
label: 'Message',
|
||||
minWidth: 170,
|
||||
align: 'left',
|
||||
format: (value: number) => value.toLocaleString('en-US')
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
export const TransactionList = ({ transactions }) => {
|
||||
|
||||
const classes = useStyles();
|
||||
const [page, setPage] = useState(0);
|
||||
const [rowsPerPage, setRowsPerPage] = useState(4);
|
||||
|
||||
const handleChangePage = (event, newPage) => {
|
||||
setPage(newPage);
|
||||
};
|
||||
|
||||
const handleChangeRowsPerPage = (event) => {
|
||||
setRowsPerPage(+event.target.value);
|
||||
setPage(0);
|
||||
};
|
||||
|
||||
return (
|
||||
<List>
|
||||
{transactions.map((transaction) => (
|
||||
<ListItem key={transaction.id} divider>
|
||||
<ListItemText
|
||||
primary={transaction.amount}
|
||||
secondary={transaction.type}
|
||||
/>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
<>
|
||||
<Paper className={classes.list}>
|
||||
<TableContainer>
|
||||
<Table stickyHeader aria-label="sticky table">
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
{columns.map((column) => (
|
||||
<TableCell
|
||||
key={column.id}
|
||||
style={{ minWidth: column.minWidth }}
|
||||
>
|
||||
{column.label}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{transactions.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map((row) => {
|
||||
return (
|
||||
<TableRow hover role="checkbox" tabIndex={-1} key={row.code}>
|
||||
{columns.map((column) => {
|
||||
const value = row[column.id];
|
||||
return (
|
||||
<TableCell key={column.id} className={classes.cell}>
|
||||
{column.format && typeof value === 'number' ? column.format(value) : value}
|
||||
</TableCell>
|
||||
);
|
||||
})}
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
<TablePagination
|
||||
rowsPerPageOptions={[10, 25, 100]}
|
||||
component="div"
|
||||
count={transactions.length}
|
||||
rowsPerPage={rowsPerPage}
|
||||
page={page}
|
||||
onChangePage={handleChangePage}
|
||||
onChangeRowsPerPage={handleChangeRowsPerPage}
|
||||
/>
|
||||
</Paper>
|
||||
</>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user