mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
feat(bank/nui): New transactions list component with pagination
This commit is contained in:
1 parent
15276fe959
commit
e71d377538
1 file changed
+57
-88
@@ -2,60 +2,40 @@ 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 { Typography, makeStyles, Button } from "@material-ui/core";
|
||||
|
||||
import useStyles from '../bank.styles';
|
||||
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
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: "8.5em"
|
||||
}
|
||||
}))
|
||||
import { useTransactions } from "../../hooks/useTransactions";
|
||||
|
||||
const columns = [
|
||||
{ id: 'type', label: 'Type', minWidth: 100 },
|
||||
{ id: 'amount', label: 'Amount', minWidth: 100 },
|
||||
{ id: "type", label: "Type", minWidth: 100 },
|
||||
{ id: "amount", label: "Amount", minWidth: 100 },
|
||||
{
|
||||
id: 'message',
|
||||
label: 'Message',
|
||||
id: "message",
|
||||
label: "Message",
|
||||
minWidth: 170,
|
||||
align: 'left',
|
||||
format: (value: number) => value.toLocaleString('en-US')
|
||||
align: "left",
|
||||
format: (value: number) => value.toLocaleString("en-US"),
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
export const TransactionList = ({ transactions }) => {
|
||||
|
||||
export const TransactionList = () => {
|
||||
const { transactionList } = useTransactions();
|
||||
const { t } = useTranslation();
|
||||
const classes = useStyles();
|
||||
const [page, setPage] = useState(0);
|
||||
const [rowsPerPage, setRowsPerPage] = useState(4);
|
||||
const [rowsPerPage, setRowsPerPage] = useState(5);
|
||||
|
||||
const TransactionTypes = {
|
||||
Deposit: classes.depositType,
|
||||
Withdraw: classes.withdrawType,
|
||||
};
|
||||
|
||||
|
||||
const handleChangePage = (event, newPage) => {
|
||||
setPage(newPage);
|
||||
@@ -65,52 +45,41 @@ export const TransactionList = ({ transactions }) => {
|
||||
setRowsPerPage(+event.target.value);
|
||||
setPage(0);
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Paper className={classes.list}>
|
||||
<TableContainer style={{ minHeight: 280, maxHeight: 280 }}>
|
||||
<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>
|
||||
</>
|
||||
<div id="transaction-section">
|
||||
<div className={classes.header}>
|
||||
<h2 className={classes.title}>{t("APPS_BANK_ACCOUNT_TRANSACTIONS")}</h2>
|
||||
</div>
|
||||
|
||||
<div className={classes.transcationDiv}>
|
||||
{transactionList
|
||||
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
|
||||
.map((transaction: any) => (
|
||||
<div className={classes.transactions}>
|
||||
<div>
|
||||
<h1 className={classes.tranSource}>{transaction.source}</h1>
|
||||
<p className={classes.tranType}>{transaction.type}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className={TransactionTypes[transaction.type]}>
|
||||
{transaction.type == "Deposit" ? "+" : "-"}
|
||||
{transaction.amount}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<TablePagination
|
||||
rowsPerPageOptions={[3, 5]}
|
||||
className={classes.pagination}
|
||||
component="div"
|
||||
count={transactionList.length}
|
||||
rowsPerPage={rowsPerPage}
|
||||
page={page}
|
||||
onChangePage={handleChangePage}
|
||||
onChangeRowsPerPage={handleChangeRowsPerPage}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user