mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +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 { List } from "../../../../ui/components/List";
|
||||||
import { ListItem } from "../../../../ui/components/ListItem";
|
import { ListItem } from "../../../../ui/components/ListItem";
|
||||||
import ListItemText from "@material-ui/core/ListItemText";
|
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 TablePagination from '@material-ui/core/TablePagination';
|
||||||
import Paper from '@material-ui/core/Paper';
|
|
||||||
import ChevronLeftIcon from '@material-ui/icons/ChevronLeft';
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
import { useTransactions } from "../../hooks/useTransactions";
|
||||||
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"
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{ id: 'type', label: 'Type', minWidth: 100 },
|
{ id: "type", label: "Type", minWidth: 100 },
|
||||||
{ id: 'amount', label: 'Amount', minWidth: 100 },
|
{ id: "amount", label: "Amount", minWidth: 100 },
|
||||||
{
|
{
|
||||||
id: 'message',
|
id: "message",
|
||||||
label: 'Message',
|
label: "Message",
|
||||||
minWidth: 170,
|
minWidth: 170,
|
||||||
align: 'left',
|
align: "left",
|
||||||
format: (value: number) => value.toLocaleString('en-US')
|
format: (value: number) => value.toLocaleString("en-US"),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const TransactionList = () => {
|
||||||
export const TransactionList = ({ transactions }) => {
|
const { transactionList } = useTransactions();
|
||||||
|
const { t } = useTranslation();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const [page, setPage] = useState(0);
|
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) => {
|
const handleChangePage = (event, newPage) => {
|
||||||
setPage(newPage);
|
setPage(newPage);
|
||||||
@@ -65,52 +45,41 @@ export const TransactionList = ({ transactions }) => {
|
|||||||
setRowsPerPage(+event.target.value);
|
setRowsPerPage(+event.target.value);
|
||||||
setPage(0);
|
setPage(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div id="transaction-section">
|
||||||
<Paper className={classes.list}>
|
<div className={classes.header}>
|
||||||
<TableContainer style={{ minHeight: 280, maxHeight: 280 }}>
|
<h2 className={classes.title}>{t("APPS_BANK_ACCOUNT_TRANSACTIONS")}</h2>
|
||||||
<Table stickyHeader aria-label="sticky table">
|
</div>
|
||||||
<TableHead>
|
|
||||||
<TableRow>
|
<div className={classes.transcationDiv}>
|
||||||
{columns.map((column) => (
|
{transactionList
|
||||||
<TableCell
|
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
|
||||||
key={column.id}
|
.map((transaction: any) => (
|
||||||
style={{ minWidth: column.minWidth }}
|
<div className={classes.transactions}>
|
||||||
>
|
<div>
|
||||||
{column.label}
|
<h1 className={classes.tranSource}>{transaction.source}</h1>
|
||||||
</TableCell>
|
<p className={classes.tranType}>{transaction.type}</p>
|
||||||
))}
|
</div>
|
||||||
</TableRow>
|
<div>
|
||||||
</TableHead>
|
<p className={TransactionTypes[transaction.type]}>
|
||||||
<TableBody>
|
{transaction.type == "Deposit" ? "+" : "-"}
|
||||||
{transactions.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage).map((row) => {
|
{transaction.amount}
|
||||||
return (
|
</p>
|
||||||
<TableRow hover role="checkbox" tabIndex={-1} key={row.code}>
|
</div>
|
||||||
{columns.map((column) => {
|
</div>
|
||||||
const value = row[column.id];
|
))}
|
||||||
return (
|
<TablePagination
|
||||||
<TableCell key={column.id} className={classes.cell}>
|
rowsPerPageOptions={[3, 5]}
|
||||||
{column.format && typeof value === 'number' ? column.format(value) : value}
|
className={classes.pagination}
|
||||||
</TableCell>
|
component="div"
|
||||||
);
|
count={transactionList.length}
|
||||||
})}
|
rowsPerPage={rowsPerPage}
|
||||||
</TableRow>
|
page={page}
|
||||||
);
|
onChangePage={handleChangePage}
|
||||||
})}
|
onChangeRowsPerPage={handleChangeRowsPerPage}
|
||||||
</TableBody>
|
/>
|
||||||
</Table>
|
</div>
|
||||||
</TableContainer>
|
</div>
|
||||||
<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