add actions on transactions table
This commit is contained in:
parent
9e72c2b0a5
commit
5dec15f670
@ -1,6 +1,5 @@
|
|||||||
import { GridColDef } from "@mui/x-data-grid";
|
import { GridColDef } from "@mui/x-data-grid";
|
||||||
|
|
||||||
|
|
||||||
export const depositTransactionDummyData = [
|
export const depositTransactionDummyData = [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
@ -9,6 +8,12 @@ export const depositTransactionDummyData = [
|
|||||||
transactionId: 1049131973,
|
transactionId: 1049131973,
|
||||||
depositMethod: "Card",
|
depositMethod: "Card",
|
||||||
status: "Completed",
|
status: "Completed",
|
||||||
|
options: [
|
||||||
|
{ value: "Pending", label: "Pending" },
|
||||||
|
{ value: "Completed", label: "Completed" },
|
||||||
|
{ value: "Inprogress", label: "Inprogress" },
|
||||||
|
{ value: "Error", label: "Error" },
|
||||||
|
],
|
||||||
amount: 4000,
|
amount: 4000,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
dateTime: "2025-06-18 10:10:30",
|
dateTime: "2025-06-18 10:10:30",
|
||||||
@ -22,6 +27,12 @@ export const depositTransactionDummyData = [
|
|||||||
transactionId: 1049131973,
|
transactionId: 1049131973,
|
||||||
depositMethod: "Card",
|
depositMethod: "Card",
|
||||||
status: "Completed",
|
status: "Completed",
|
||||||
|
options: [
|
||||||
|
{ value: "Pending", label: "Pending" },
|
||||||
|
{ value: "Completed", label: "Completed" },
|
||||||
|
{ value: "Inprogress", label: "Inprogress" },
|
||||||
|
{ value: "Error", label: "Error" },
|
||||||
|
],
|
||||||
amount: 4000,
|
amount: 4000,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
dateTime: "2025-06-18 10:10:30",
|
dateTime: "2025-06-18 10:10:30",
|
||||||
@ -34,7 +45,13 @@ export const depositTransactionDummyData = [
|
|||||||
merchandId: 100987997,
|
merchandId: 100987997,
|
||||||
transactionId: 1049131973,
|
transactionId: 1049131973,
|
||||||
depositMethod: "Card",
|
depositMethod: "Card",
|
||||||
status: "Complete",
|
status: "Completed",
|
||||||
|
options: [
|
||||||
|
{ value: "Pending", label: "Pending" },
|
||||||
|
{ value: "Completed", label: "Completed" },
|
||||||
|
{ value: "Inprogress", label: "Inprogress" },
|
||||||
|
{ value: "Error", label: "Error" },
|
||||||
|
],
|
||||||
amount: 4000,
|
amount: 4000,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
dateTime: "2025-06-18 10:10:30",
|
dateTime: "2025-06-18 10:10:30",
|
||||||
@ -48,6 +65,12 @@ export const depositTransactionDummyData = [
|
|||||||
transactionId: 1049136973,
|
transactionId: 1049136973,
|
||||||
depositMethod: "Card",
|
depositMethod: "Card",
|
||||||
status: "Completed",
|
status: "Completed",
|
||||||
|
options: [
|
||||||
|
{ value: "Pending", label: "Pending" },
|
||||||
|
{ value: "Completed", label: "Completed" },
|
||||||
|
{ value: "Inprogress", label: "Inprogress" },
|
||||||
|
{ value: "Error", label: "Error" },
|
||||||
|
],
|
||||||
amount: 4000,
|
amount: 4000,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
dateTime: "2025-06-18 10:10:30",
|
dateTime: "2025-06-18 10:10:30",
|
||||||
@ -61,6 +84,12 @@ export const depositTransactionDummyData = [
|
|||||||
transactionId: 1049131973,
|
transactionId: 1049131973,
|
||||||
depositMethod: "Card",
|
depositMethod: "Card",
|
||||||
status: "Completed",
|
status: "Completed",
|
||||||
|
options: [
|
||||||
|
{ value: "Pending", label: "Pending" },
|
||||||
|
{ value: "Completed", label: "Completed" },
|
||||||
|
{ value: "Inprogress", label: "Inprogress" },
|
||||||
|
{ value: "Error", label: "Error" },
|
||||||
|
],
|
||||||
amount: 4000,
|
amount: 4000,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
dateTime: "2025-06-18 10:10:30",
|
dateTime: "2025-06-18 10:10:30",
|
||||||
@ -74,6 +103,12 @@ export const depositTransactionDummyData = [
|
|||||||
transactionId: 1049131973,
|
transactionId: 1049131973,
|
||||||
depositMethod: "Card",
|
depositMethod: "Card",
|
||||||
status: "Pending",
|
status: "Pending",
|
||||||
|
options: [
|
||||||
|
{ value: "Pending", label: "Pending" },
|
||||||
|
{ value: "Completed", label: "Completed" },
|
||||||
|
{ value: "Inprogress", label: "Inprogress" },
|
||||||
|
{ value: "Error", label: "Error" },
|
||||||
|
],
|
||||||
amount: 4000,
|
amount: 4000,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
dateTime: "2025-06-18 10:10:30",
|
dateTime: "2025-06-18 10:10:30",
|
||||||
@ -87,6 +122,12 @@ export const depositTransactionDummyData = [
|
|||||||
transactionId: 1049136973,
|
transactionId: 1049136973,
|
||||||
depositMethod: "Card",
|
depositMethod: "Card",
|
||||||
status: "Pending",
|
status: "Pending",
|
||||||
|
options: [
|
||||||
|
{ value: "Pending", label: "Pending" },
|
||||||
|
{ value: "Completed", label: "Completed" },
|
||||||
|
{ value: "Inprogress", label: "Inprogress" },
|
||||||
|
{ value: "Error", label: "Error" },
|
||||||
|
],
|
||||||
amount: 4000,
|
amount: 4000,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
dateTime: "2025-06-18 10:10:30",
|
dateTime: "2025-06-18 10:10:30",
|
||||||
@ -100,6 +141,12 @@ export const depositTransactionDummyData = [
|
|||||||
transactionId: 1049131973,
|
transactionId: 1049131973,
|
||||||
depositMethod: "Card",
|
depositMethod: "Card",
|
||||||
status: "Pending",
|
status: "Pending",
|
||||||
|
options: [
|
||||||
|
{ value: "Pending", label: "Pending" },
|
||||||
|
{ value: "Completed", label: "Completed" },
|
||||||
|
{ value: "Inprogress", label: "Inprogress" },
|
||||||
|
{ value: "Error", label: "Error" },
|
||||||
|
],
|
||||||
amount: 4000,
|
amount: 4000,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
dateTime: "2025-06-12 10:10:30",
|
dateTime: "2025-06-12 10:10:30",
|
||||||
@ -113,6 +160,12 @@ export const depositTransactionDummyData = [
|
|||||||
transactionId: 1049131973,
|
transactionId: 1049131973,
|
||||||
depositMethod: "Bank Transfer",
|
depositMethod: "Bank Transfer",
|
||||||
status: "Inprogress",
|
status: "Inprogress",
|
||||||
|
options: [
|
||||||
|
{ value: "Pending", label: "Pending" },
|
||||||
|
{ value: "Completed", label: "Completed" },
|
||||||
|
{ value: "Inprogress", label: "Inprogress" },
|
||||||
|
{ value: "Error", label: "Error" },
|
||||||
|
],
|
||||||
amount: 4000,
|
amount: 4000,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
dateTime: "2025-06-17 10:10:30",
|
dateTime: "2025-06-17 10:10:30",
|
||||||
@ -126,6 +179,12 @@ export const depositTransactionDummyData = [
|
|||||||
transactionId: 1049131973,
|
transactionId: 1049131973,
|
||||||
depositMethod: "Bank Transfer",
|
depositMethod: "Bank Transfer",
|
||||||
status: "Inprogress",
|
status: "Inprogress",
|
||||||
|
options: [
|
||||||
|
{ value: "Pending", label: "Pending" },
|
||||||
|
{ value: "Completed", label: "Completed" },
|
||||||
|
{ value: "Inprogress", label: "Inprogress" },
|
||||||
|
{ value: "Error", label: "Error" },
|
||||||
|
],
|
||||||
amount: 4000,
|
amount: 4000,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
dateTime: "2025-06-17 10:10:30",
|
dateTime: "2025-06-17 10:10:30",
|
||||||
@ -139,6 +198,12 @@ export const depositTransactionDummyData = [
|
|||||||
transactionId: 1049131973,
|
transactionId: 1049131973,
|
||||||
depositMethod: "Bank Transfer",
|
depositMethod: "Bank Transfer",
|
||||||
status: "Error",
|
status: "Error",
|
||||||
|
options: [
|
||||||
|
{ value: "Pending", label: "Pending" },
|
||||||
|
{ value: "Completed", label: "Completed" },
|
||||||
|
{ value: "Inprogress", label: "Inprogress" },
|
||||||
|
{ value: "Error", label: "Error" },
|
||||||
|
],
|
||||||
amount: 4000,
|
amount: 4000,
|
||||||
currency: "EUR",
|
currency: "EUR",
|
||||||
dateTime: "2025-06-17 10:10:30",
|
dateTime: "2025-06-17 10:10:30",
|
||||||
@ -153,39 +218,39 @@ export const depositTransactionsColumns: GridColDef[] = [
|
|||||||
{ field: "transactionId", headerName: "Transaction ID", width: 130 },
|
{ field: "transactionId", headerName: "Transaction ID", width: 130 },
|
||||||
{ field: "depositMethod", headerName: "Deposit Method", width: 130 },
|
{ field: "depositMethod", headerName: "Deposit Method", width: 130 },
|
||||||
{ field: "status", headerName: "Status", width: 130 },
|
{ field: "status", headerName: "Status", width: 130 },
|
||||||
|
{ field: "actions", headerName: "Actions", width: 150 },
|
||||||
{ field: "amount", headerName: "Amount", width: 130 },
|
{ field: "amount", headerName: "Amount", width: 130 },
|
||||||
{ field: "currency", headerName: "Currency", width: 130 },
|
{ field: "currency", headerName: "Currency", width: 130 },
|
||||||
{ field: "dateTime", headerName: "Date / Time", width: 130 },
|
{ field: "dateTime", headerName: "Date / Time", width: 130 },
|
||||||
{ field: "errorInfo", headerName: "Error Info", width: 130 },
|
{ field: "errorInfo", headerName: "Error Info", width: 130 },
|
||||||
{ field: "fraudScore", headerName: "Fraud Score", width: 130 },
|
{ field: "fraudScore", headerName: "Fraud Score", width: 130 },
|
||||||
]
|
];
|
||||||
|
|
||||||
|
|
||||||
export const depositTransactionsSearchLabels = [
|
export const depositTransactionsSearchLabels = [
|
||||||
{ label: "User", field: "userId", type: "text" },
|
{ label: "User", field: "userId", type: "text" },
|
||||||
{ label: "Transaction ID", field: "transactionId", type: "text" },
|
{ label: "Transaction ID", field: "transactionId", type: "text" },
|
||||||
{
|
{
|
||||||
label: "Transaction Reference ID",
|
label: "Transaction Reference ID",
|
||||||
field: "transactionReferenceId",
|
field: "transactionReferenceId",
|
||||||
type: "text",
|
type: "text",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Currency",
|
label: "Currency",
|
||||||
field: "currency",
|
field: "currency",
|
||||||
type: "select",
|
type: "select",
|
||||||
options: ["USD", "EUR", "GBP"]
|
options: ["USD", "EUR", "GBP"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Status",
|
label: "Status",
|
||||||
field: "status",
|
field: "status",
|
||||||
type: "select",
|
type: "select",
|
||||||
options: ["Pending","Inprogress", "Completed", "Failed"]
|
options: ["Pending", "Inprogress", "Completed", "Failed"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Payment Method",
|
label: "Payment Method",
|
||||||
field: "depositMethod",
|
field: "depositMethod",
|
||||||
type: "select",
|
type: "select",
|
||||||
options: ["Card", "Bank Transfer"]
|
options: ["Card", "Bank Transfer"],
|
||||||
},
|
},
|
||||||
{ label: "Date / Time", field: "dateTime", type: "date" },
|
{ label: "Date / Time", field: "dateTime", type: "date" },
|
||||||
]
|
];
|
||||||
|
|||||||
@ -17,23 +17,24 @@ import {
|
|||||||
TextField,
|
TextField,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import FileUploadIcon from "@mui/icons-material/FileUpload";
|
import FileUploadIcon from "@mui/icons-material/FileUpload";
|
||||||
import { DataGrid } from "@mui/x-data-grid";
|
import { DataGrid, GridColDef, GridRenderCellParams } from "@mui/x-data-grid";
|
||||||
import AdvancedSearch from "../../AdvancedSearch/AdvancedSearch";
|
import AdvancedSearch from "../../AdvancedSearch/AdvancedSearch";
|
||||||
import SearchFilters from "@/app/components/searchFilter/SearchFilters";
|
import SearchFilters from "@/app/components/searchFilter/SearchFilters";
|
||||||
import { exportData } from "@/app/utils/exportData";
|
import { exportData } from "@/app/utils/exportData";
|
||||||
import { ITransaction } from "./types";
|
import { ITransaction } from "./types";
|
||||||
|
|
||||||
const paginationModel = { page: 0, pageSize: 50 };
|
|
||||||
|
|
||||||
interface IDepositProps {
|
interface IDepositProps {
|
||||||
res: ITransaction
|
res: ITransaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TransactionsTable = ({ res }: IDepositProps) => {
|
const TransactionsTable = ({ res }: IDepositProps) => {
|
||||||
const {filteredTransactions, transactionsColumns, transactionsSearchLabels} = res;
|
const {
|
||||||
const router = useRouter()
|
filteredTransactions,
|
||||||
const searchParams = useSearchParams()
|
transactionsColumns,
|
||||||
|
transactionsSearchLabels,
|
||||||
|
} = res;
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [fileType, setFileType] = useState<"csv" | "xls" | "xlsx">("csv");
|
const [fileType, setFileType] = useState<"csv" | "xls" | "xlsx">("csv");
|
||||||
@ -41,14 +42,58 @@ const TransactionsTable = ({ res }: IDepositProps) => {
|
|||||||
|
|
||||||
const filters = Object.fromEntries(searchParams.entries());
|
const filters = Object.fromEntries(searchParams.entries());
|
||||||
|
|
||||||
|
|
||||||
const handleClickField = (field: string, value: string) => {
|
const handleClickField = (field: string, value: string) => {
|
||||||
const params = new URLSearchParams(searchParams.toString())
|
const params = new URLSearchParams(searchParams.toString());
|
||||||
params.set(field, value)
|
params.set(field, value);
|
||||||
router.push(`?${params.toString()}`)
|
router.push(`?${params.toString()}`);
|
||||||
router.refresh()
|
router.refresh();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleStatusChange = (id: number, newStatus: string) => {
|
||||||
|
setRows(
|
||||||
|
rows.map((row) => (row.id === id ? { ...row, status: newStatus } : row)),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const [rows, setRows] = useState(filteredTransactions);
|
||||||
|
const getColumnsWithDropdown = (columns: GridColDef[]) => {
|
||||||
|
return columns.map((col) => {
|
||||||
|
if (col.field === "actions") {
|
||||||
|
return {
|
||||||
|
...col,
|
||||||
|
renderCell: (params: GridRenderCellParams) => {
|
||||||
|
const row = filteredTransactions.find((r) => r.id === params.id);
|
||||||
|
const options = row?.options;
|
||||||
|
|
||||||
|
if (!options) return params.value;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
value={params.value ?? row.status}
|
||||||
|
onChange={(e) =>
|
||||||
|
handleStatusChange(params.id as number, e.target.value)
|
||||||
|
}
|
||||||
|
size="small"
|
||||||
|
sx={{
|
||||||
|
width: "100%",
|
||||||
|
"& .MuiOutlinedInput-notchedOutline": { border: "none" },
|
||||||
|
"& .MuiSelect-select": { py: 0.5 },
|
||||||
|
}}
|
||||||
|
onClick={(e) => e.stopPropagation()} // Prevent row click when selecting
|
||||||
|
>
|
||||||
|
{options.map((option: { value: string; label: string }) => (
|
||||||
|
<MenuItem key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return col;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper>
|
<Paper>
|
||||||
@ -78,13 +123,22 @@ const TransactionsTable = ({ res }: IDepositProps) => {
|
|||||||
|
|
||||||
<DataGrid
|
<DataGrid
|
||||||
rows={filteredTransactions}
|
rows={filteredTransactions}
|
||||||
columns={transactionsColumns}
|
columns={getColumnsWithDropdown(transactionsColumns) as GridColDef[]}
|
||||||
initialState={{ pagination: { paginationModel } }}
|
initialState={{
|
||||||
|
pagination: { paginationModel: { pageSize: 50 } },
|
||||||
|
}}
|
||||||
pageSizeOptions={[50, 100]}
|
pageSizeOptions={[50, 100]}
|
||||||
sx={{ border: 0, cursor: 'pointer' }}
|
sx={{
|
||||||
|
border: 0,
|
||||||
|
cursor: "pointer",
|
||||||
|
"& .MuiDataGrid-cell": {
|
||||||
|
py: 1,
|
||||||
|
},
|
||||||
|
}}
|
||||||
onCellClick={(params) => {
|
onCellClick={(params) => {
|
||||||
handleClickField(params.field, params.value as string)
|
if (params.field !== "actions") {
|
||||||
|
handleClickField(params.field, params.value as string);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
@ -117,13 +171,24 @@ const TransactionsTable = ({ res }: IDepositProps) => {
|
|||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={() => setOpen(false)}>Cancel</Button>
|
<Button onClick={() => setOpen(false)}>Cancel</Button>
|
||||||
<Button variant="contained" onClick={() => exportData(filteredTransactions as unknown as ITransaction[], transactionsColumns, fileType, onlyCurrentTable, setOpen)}>
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
onClick={() =>
|
||||||
|
exportData(
|
||||||
|
filteredTransactions as unknown as ITransaction[],
|
||||||
|
transactionsColumns,
|
||||||
|
fileType,
|
||||||
|
onlyCurrentTable,
|
||||||
|
setOpen,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
Export
|
Export
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</Paper>
|
</Paper>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default TransactionsTable
|
export default TransactionsTable;
|
||||||
|
|||||||
@ -4,6 +4,11 @@ interface IDepositTransactionsColumns {
|
|||||||
width: number;
|
width: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IOptions {
|
||||||
|
value: string;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface IFilteredTransactions {
|
interface IFilteredTransactions {
|
||||||
id: number;
|
id: number;
|
||||||
userId: number;
|
userId: number;
|
||||||
@ -11,6 +16,7 @@ interface IFilteredTransactions {
|
|||||||
transactionId: number;
|
transactionId: number;
|
||||||
depositMethod: string;
|
depositMethod: string;
|
||||||
status: string;
|
status: string;
|
||||||
|
options: IOptions[];
|
||||||
amount: number;
|
amount: number;
|
||||||
currency: string;
|
currency: string;
|
||||||
dateTime: string;
|
dateTime: string;
|
||||||
@ -25,7 +31,6 @@ interface IDepositTransactionsSearchLabels {
|
|||||||
options?: string[];
|
options?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export interface ITransaction {
|
export interface ITransaction {
|
||||||
filteredTransactions: IFilteredTransactions[];
|
filteredTransactions: IFilteredTransactions[];
|
||||||
transactionsColumns: IDepositTransactionsColumns[];
|
transactionsColumns: IDepositTransactionsColumns[];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user