2023-12-28 23:26:59 +02:00
|
|
|
import Grid from "@mui/material/Unstable_Grid2";
|
|
|
|
import {Stack} from "@mui/material";
|
|
|
|
import {useEffect, useState} from "react";
|
|
|
|
import {DataGrid} from "@mui/x-data-grid";
|
|
|
|
import utils from "@/utils.js";
|
2023-12-30 12:50:07 +02:00
|
|
|
import {ArrowDownward, ArrowUpward, PriceChange} from "@mui/icons-material";
|
2023-12-28 23:26:59 +02:00
|
|
|
|
|
|
|
const COLUMNS = [
|
|
|
|
{
|
|
|
|
field: "isInflow",
|
|
|
|
headerName: "Inflow/Outflow",
|
|
|
|
type: "boolean",
|
|
|
|
width: 150,
|
|
|
|
sortable: false,
|
|
|
|
filterable: false,
|
2023-12-30 12:50:07 +02:00
|
|
|
renderCell: (params) => {
|
|
|
|
return params.value ? (
|
|
|
|
<>
|
|
|
|
<PriceChange style={{ color: '#4d4' }} />
|
|
|
|
<ArrowUpward style={{ color: '#4d4' }} />
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<PriceChange style={{ color: '#d44' }} />
|
|
|
|
<ArrowDownward style={{ color: '#d44' }} />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2023-12-28 23:26:59 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "amount",
|
|
|
|
headerName: "Amount",
|
|
|
|
type: "currency",
|
|
|
|
maxWidth: 150,
|
|
|
|
flex: true,
|
|
|
|
sortable: true,
|
|
|
|
filterable: false,
|
2023-12-30 12:50:07 +02:00
|
|
|
valueFormatter: val => `${(val.value).toLocaleString(undefined, { minimumFractionDigits: 2 })} лв.`
|
2023-12-28 23:26:59 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "description",
|
|
|
|
headerName: "Description",
|
|
|
|
type: "string",
|
|
|
|
minWidth: 150,
|
|
|
|
flex: true,
|
|
|
|
sortable: true,
|
|
|
|
filterable: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
field: "timestamp",
|
|
|
|
headerName: "Timestamp",
|
|
|
|
type: "datetime",
|
|
|
|
maxWidth: 250,
|
|
|
|
flex: true,
|
|
|
|
sortable: true,
|
|
|
|
filterable: false,
|
2023-12-30 12:50:07 +02:00
|
|
|
valueFormatter: val => new Date(val.value).toLocaleString("bg-BG")
|
2023-12-28 23:26:59 +02:00
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export default function TransactionsPage() {
|
|
|
|
|
|
|
|
const [pageOptions, setPageOptions] = useState({
|
|
|
|
page: 0,
|
2023-12-30 12:50:07 +02:00
|
|
|
pageSize: 50,
|
2023-12-28 23:26:59 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const [sortOptions, setSortOptions] = useState([
|
|
|
|
{
|
|
|
|
field: "timestamp",
|
|
|
|
sort: "asc"
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
const [transactions, setTransactions] = useState({});
|
|
|
|
|
|
|
|
useEffect(() => {
|
2023-12-30 12:50:07 +02:00
|
|
|
utils.showSpinner();
|
|
|
|
|
2023-12-28 23:26:59 +02:00
|
|
|
// Multi-sorting requires the MUI data grid pro license :)
|
|
|
|
let sortBy = sortOptions.map((sort) => `&sort=${sort.field},${sort.sort}`).join("")
|
|
|
|
|
|
|
|
console.log(sortBy)
|
|
|
|
|
|
|
|
utils.performRequest(`/api/processed-transactions?page=${pageOptions.page}&size=${pageOptions.pageSize}${sortBy}`)
|
|
|
|
.then(resp => resp.json())
|
2023-12-30 12:50:07 +02:00
|
|
|
.then(({result}) => {
|
|
|
|
setTransactions(result);
|
|
|
|
utils.hideSpinner();
|
|
|
|
});
|
2023-12-28 23:26:59 +02:00
|
|
|
}, [pageOptions, sortOptions]);
|
|
|
|
|
|
|
|
return (
|
2023-12-30 12:50:07 +02:00
|
|
|
<Stack
|
|
|
|
>
|
|
|
|
<Grid
|
|
|
|
container
|
|
|
|
columnSpacing={1}
|
|
|
|
>
|
|
|
|
<Grid
|
|
|
|
sx={{
|
|
|
|
height: "1200px"
|
|
|
|
}}
|
|
|
|
xs={12}
|
|
|
|
lg={12}
|
|
|
|
>
|
2023-12-28 23:26:59 +02:00
|
|
|
<DataGrid
|
2023-12-30 12:50:07 +02:00
|
|
|
sx={{
|
|
|
|
overflowY: "scroll"
|
|
|
|
}}
|
2023-12-28 23:26:59 +02:00
|
|
|
columns={COLUMNS}
|
|
|
|
rows={transactions.content ?? []}
|
|
|
|
rowCount={transactions.totalElements ?? 0}
|
2023-12-30 12:50:07 +02:00
|
|
|
pageSizeOptions={[25, 50, 100]}
|
2023-12-28 23:26:59 +02:00
|
|
|
paginationMode={"server"}
|
|
|
|
sortingMode={"server"}
|
|
|
|
paginationModel={pageOptions}
|
|
|
|
onPaginationModelChange={(model, details) => setPageOptions(model)}
|
|
|
|
sortModel={sortOptions}
|
|
|
|
onSortModelChange={(model, change) => setSortOptions(model)}
|
|
|
|
/>
|
|
|
|
</Grid>
|
|
|
|
</Grid>
|
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
}
|