Merge branch 'master' of https://git.shiblysolution.id/TPAY/dashboard
This commit is contained in:
@ -6,6 +6,7 @@ interface apiConfigProps {
|
||||
service_wallet: string;
|
||||
transaction: string;
|
||||
nationality: string;
|
||||
service_disbursement: string;
|
||||
}
|
||||
|
||||
const API_URL = import.meta.env.VITE_APP_API_URL;
|
||||
@ -18,6 +19,7 @@ const apiConfig: apiConfigProps = {
|
||||
service_transaction: `${API_URL}/tt`,
|
||||
service_wallet: `${API_URL}/w`,
|
||||
transaction: `${API_URL}/x`,
|
||||
service_disbursement: `${API_URL}/s`,
|
||||
nationality: `https://tpay.shiblysolution.id/cms/api/mobile/list-country/
|
||||
`
|
||||
};
|
||||
|
||||
@ -57,6 +57,24 @@ const useCallApi = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
const PostDataFile = useCallback(async (url: string, field: any, config = {}) => {
|
||||
try {
|
||||
const response = await axios.post(url, field, config);
|
||||
const result = response.data;
|
||||
|
||||
if (result.status) {
|
||||
return { status: true, message: result.data };
|
||||
}
|
||||
return { status: false, message: result.message };
|
||||
} catch (error: any) {
|
||||
const { response } = error;
|
||||
return {
|
||||
status: false,
|
||||
message: response?.data?.error ?? response?.data?.message ?? 'Something went wrong'
|
||||
};
|
||||
}
|
||||
}, []);
|
||||
|
||||
const PutData = useCallback(async (url: string, field: any) => {
|
||||
try {
|
||||
const response = await axios.put(url, field);
|
||||
@ -85,7 +103,7 @@ const useCallApi = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
return { GetData, PostData, PutData, DeleteData, GetExportData };
|
||||
return { GetData, PostData, PutData, DeleteData, GetExportData, PostDataFile };
|
||||
};
|
||||
|
||||
export { useCallApi };
|
||||
|
||||
@ -0,0 +1,39 @@
|
||||
import { Container, DataGridInner } from '@/components';
|
||||
import { TransactionProvider } from './hooks/TransactionContext';
|
||||
import { Breadcrumbs, Link } from '@mui/material';
|
||||
import { Helmet } from 'react-helmet';
|
||||
import { UploadBatchDialog } from './blocks/UploadBatchDialog';
|
||||
|
||||
const HistoryTransactionDisbursement = () => {
|
||||
return (
|
||||
<>
|
||||
<Helmet>
|
||||
<title>TPAY | History Disbursement</title>
|
||||
</Helmet>
|
||||
<TransactionProvider>
|
||||
<Container className="mb-7">
|
||||
<h1 className="text-xl font-medium leading-none text-gray-900 mb-5">DISBURSEMENT</h1>
|
||||
<Breadcrumbs sx={{ mb: 2 }}>
|
||||
<Link underline="none" color="inherit" href="/">
|
||||
<span className="text-sm hover:underline">Dashboard</span>
|
||||
</Link>
|
||||
|
||||
<Link underline="none" color="inherit">
|
||||
<span className="text-sm">Disbursement</span>
|
||||
</Link>
|
||||
|
||||
<Link underline="none" color="inherit">
|
||||
<span className="text-sm">History Transaction</span>
|
||||
</Link>
|
||||
</Breadcrumbs>
|
||||
<div className="grid gap-5 lg:gap-7.5">
|
||||
<DataGridInner />
|
||||
</div>
|
||||
<UploadBatchDialog />
|
||||
</Container>
|
||||
</TransactionProvider>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default HistoryTransactionDisbursement;
|
||||
@ -0,0 +1,137 @@
|
||||
import { useTransactionContext } from '../hooks/useTransactionContext';
|
||||
import { useCallApi } from '@/hooks';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
Dialog,
|
||||
DialogBody,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from '@/components/ui/dialog';
|
||||
|
||||
const API_URL = apiConfig.service_disbursement;
|
||||
|
||||
type StatusCode = 'W' | 'P' | 'F' | 'D' | 'Y';
|
||||
|
||||
interface StatusInfo {
|
||||
label: string;
|
||||
bg: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
const statusMap: Record<StatusCode, StatusInfo> = {
|
||||
W: { label: 'Waiting', bg: 'bg-yellow-100', text: 'text-yellow-600' },
|
||||
P: { label: 'Pending', bg: 'bg-blue-100', text: 'text-blue-600' },
|
||||
F: { label: 'Fail', bg: 'bg-red-100', text: 'text-red-600' },
|
||||
D: { label: 'Done', bg: 'bg-green-100', text: 'text-green-600' },
|
||||
Y: { label: 'Active', bg: 'bg-green-100', text: 'text-green-600' },
|
||||
};
|
||||
|
||||
export const renderStatusBadge = (statusRaw: string | null | undefined) => {
|
||||
const status = statusRaw as StatusCode;
|
||||
const { label, bg, text } = statusMap[status] ?? {
|
||||
label: 'Unknown',
|
||||
bg: 'bg-gray-100',
|
||||
text: 'text-gray-600',
|
||||
};
|
||||
|
||||
return (
|
||||
<span className={`px-2 py-1 text-xs font-semibold rounded-full ${bg} ${text}`}>
|
||||
{label}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
const DetailTransaction = () => {
|
||||
const { GetData } = useCallApi();
|
||||
const {
|
||||
showDetailDialog,
|
||||
setShowDetailDialog,
|
||||
selectedTransactionId
|
||||
} = useTransactionContext();
|
||||
|
||||
const [transactionDetails, setTransactionDetails] = useState<any>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchTransactionDetails = async () => {
|
||||
console.log(selectedTransactionId)
|
||||
if (selectedTransactionId) {
|
||||
try {
|
||||
const response = await GetData(`${API_URL}/transaction/history/${selectedTransactionId}`, {
|
||||
id: selectedTransactionId
|
||||
});
|
||||
// console.log(response?.data);
|
||||
setTransactionDetails(response?.data);
|
||||
} catch (error) {
|
||||
console.error('Error fetching transaction', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (showDetailDialog && selectedTransactionId) {
|
||||
fetchTransactionDetails();
|
||||
}
|
||||
}, [showDetailDialog, selectedTransactionId, GetData]);
|
||||
|
||||
const [activeTab, setActiveTab] = useState('detail'); // 'detail', 'log', 'approve'
|
||||
|
||||
return (
|
||||
<Dialog open={showDetailDialog} onOpenChange={setShowDetailDialog}>
|
||||
<DialogContent className="container-fixed max-w-[1024px] flex flex-col p-5 overflow-hidden">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Transaction Details</DialogTitle>
|
||||
</DialogHeader>
|
||||
<DialogBody>
|
||||
{/* Tab Content */}
|
||||
<div className="py-4 overflow-y-auto max-h-[400px]">
|
||||
<div className="space-y-4">
|
||||
<div className="border rounded-lg overflow-x-auto">
|
||||
<table className="min-w-full table-auto">
|
||||
<thead>
|
||||
<tr className="bg-gray-100">
|
||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Username</th>
|
||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Name</th>
|
||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Transfer Amount</th>
|
||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Description</th>
|
||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Invoice Number</th>
|
||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Process Date</th>
|
||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Response</th>
|
||||
<th className="px-4 py-2 text-left text-sm text-gray-500">Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{transactionDetails?.log && transactionDetails?.log.length > 0 ? (
|
||||
transactionDetails.log.map((log: { customer: any, amount: number, remark: string, reference: string, response_date: string, payment_response: string, status: string}, index: number) => (
|
||||
<tr key={index} className="border-t">
|
||||
<td className="px-4 py-2 text-sm text-gray-500">{log.customer.username ?? '-'}</td>
|
||||
<td className="px-4 py-2 text-sm text-gray-500">{log.customer.fullname ?? '-'}</td>
|
||||
<td className="px-4 py-2 text-sm text-gray-500">{log.amount ?? '-'}</td>
|
||||
<td className="px-4 py-2 text-sm text-gray-500">{log.remark ?? '-'}</td>
|
||||
<td className="px-4 py-2 text-sm text-gray-500">{log.reference ?? '-'}</td>
|
||||
<td className="px-4 py-2 text-sm text-gray-500">{log.response_date ?? '-'}</td>
|
||||
<td className="px-4 py-2 text-sm text-gray-500">{log.payment_response ?? '-'}</td>
|
||||
<td className="px-4 py-2 text-sm text-gray-500">{renderStatusBadge(log.status) ?? '-'}</td>
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td colSpan={8} className="px-4 py-2 text-center text-sm text-gray-500">
|
||||
No logs available
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</DialogBody>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default DetailTransaction;
|
||||
@ -0,0 +1,70 @@
|
||||
import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components';
|
||||
import { useTransactionContext } from '../hooks/useTransactionContext';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useCallback, useState, useEffect } from 'react';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
const ListToolbar = () => {
|
||||
const { table, reload } = useDataGrid();
|
||||
const { handleUploadBatchDialog } = useTransactionContext();
|
||||
|
||||
// Set the initial state for trxDate
|
||||
const [trxDate, settrxDate] = useState({ from: '', to: '' });
|
||||
|
||||
// Function to format date to YYYY-MM-DD
|
||||
const formatDate = (date: Date): string => {
|
||||
return date.toISOString().split('T')[0];
|
||||
};
|
||||
|
||||
// useEffect to set the default date values
|
||||
useEffect(() => {
|
||||
const today = new Date();
|
||||
const nextWeek = new Date(today);
|
||||
nextWeek.setDate(today.getDate() + 7);
|
||||
|
||||
settrxDate({
|
||||
from: formatDate(today), // Set 'from' to today
|
||||
to: formatDate(nextWeek), // Set 'to' to 7 days later
|
||||
});
|
||||
}, []);
|
||||
|
||||
const handleFilterData = useCallback(() => {
|
||||
try {
|
||||
table.getColumn('transaction_date')?.setFilterValue(trxDate);
|
||||
} catch (error) {
|
||||
toast.error('Error applying filter');
|
||||
console.error('Error applying filter:', error);
|
||||
}
|
||||
}, [trxDate, table]);
|
||||
|
||||
useEffect(() => {
|
||||
if (trxDate.from && trxDate.to) {
|
||||
handleFilterData();
|
||||
}
|
||||
}, [trxDate]);
|
||||
|
||||
return (
|
||||
<div className="card-header flex-wrap gap-2 border-b-0 px-5">
|
||||
<div className="flex flex-wrap gap-2 lg:gap-5 w-full">
|
||||
<div className="flex justify-between w-full items-center">
|
||||
<div className="flex gap-3 items-center ml-auto">
|
||||
<Button
|
||||
variant="outline"
|
||||
className="h-7.5 text-[0.8rem]"
|
||||
onClick={() => handleUploadBatchDialog(true)}
|
||||
>
|
||||
Upload Batch
|
||||
</Button>
|
||||
<DefaultTooltip title={'Refresh'} placement={'top'}>
|
||||
<Button variant="outline" className="h-7.5" onClick={() => reload()}>
|
||||
<KeenIcon icon="arrows-circle" />
|
||||
</Button>
|
||||
</DefaultTooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ListToolbar;
|
||||
@ -0,0 +1,194 @@
|
||||
import { MouseEvent, useCallback, useEffect, useRef, useState } from 'react';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue
|
||||
} from '@/components/ui/select';
|
||||
|
||||
import {
|
||||
Dialog,
|
||||
DialogBody,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from '@/components/ui/dialog';
|
||||
import { useTransactionContext } from '../hooks';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { Alert, KeenIcon, useDataGrid } from '@/components';
|
||||
import { toast } from 'sonner';
|
||||
import { useCallApi } from '@/hooks';
|
||||
import { doSaveLogActivity } from '@/actions/GlobalActions';
|
||||
import clsx from 'clsx';
|
||||
|
||||
const API_URL = apiConfig.service_disbursement;
|
||||
|
||||
const UploadBatchDialog = () => {
|
||||
const parentRef = useRef<any | null>(null);
|
||||
const { showUploadBatchDialog, handleUploadBatchDialog } = useTransactionContext();
|
||||
const { reload } = useDataGrid();
|
||||
const { PostData, PostDataFile, GetData } = useCallApi();
|
||||
const [alert, setAlert] = useState({
|
||||
show: false,
|
||||
message: ''
|
||||
});
|
||||
const initialState: {
|
||||
execution_date: string,
|
||||
file: File | null;
|
||||
} = {
|
||||
execution_date: '',
|
||||
file: null
|
||||
}
|
||||
const [formField, setFormField] = useState(initialState);
|
||||
|
||||
const resetForm = () => {
|
||||
setFormField(initialState);
|
||||
setAlert({ show: false, message: '' });
|
||||
};
|
||||
|
||||
/* actions */
|
||||
const doUploadBatch = useCallback(
|
||||
async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('execution_date', formField.execution_date);
|
||||
if (formField.file) {
|
||||
formData.append('file', formField.file);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await PostDataFile(`${API_URL}/upload-excel`, formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
}
|
||||
});
|
||||
|
||||
if (response?.status) {
|
||||
handleUploadBatchDialog(false);
|
||||
resetForm();
|
||||
reload();
|
||||
|
||||
const createActivity = {
|
||||
module: 'Disbursement',
|
||||
description: `Create New Disbursement => ${formField.file?.name}`,
|
||||
action: 'C'
|
||||
};
|
||||
|
||||
doSaveLogActivity(createActivity);
|
||||
toast.success('Success Create Disbursement');
|
||||
} else {
|
||||
toast.error('Failed to create disbursement');
|
||||
setAlert({ show: true, message: response?.message ?? 'Failed to create disbursement.' });
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error('Error uploading batch');
|
||||
setAlert({ show: true, message: 'Something went wrong. Please try again.' });
|
||||
}
|
||||
},
|
||||
[formField]
|
||||
);
|
||||
|
||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
console.log('Form data before submit:', formField);
|
||||
|
||||
if (
|
||||
formField.execution_date.trim() === '' ||
|
||||
formField.file === null
|
||||
) {
|
||||
setAlert({ show: true, message: 'Please fill in all required fields.' });
|
||||
return;
|
||||
}
|
||||
|
||||
doUploadBatch(e);
|
||||
// console.log(formField);
|
||||
setAlert({ show: false, message: '' });
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (showUploadBatchDialog === false) {
|
||||
resetForm();
|
||||
}
|
||||
}, [showUploadBatchDialog]);
|
||||
|
||||
return (
|
||||
<Dialog open={showUploadBatchDialog} onOpenChange={(open) => handleUploadBatchDialog(open)}>
|
||||
<DialogContent className="container-fixed max-w-[768px] flex flex-col p-5 overflow-hidden [&>button]:hidden">
|
||||
<DialogHeader className="p-0 border-0">
|
||||
<DialogTitle></DialogTitle>
|
||||
<DialogDescription></DialogDescription>
|
||||
<div className="flex items-center justify-between flex-wrap grow">
|
||||
<div className="flex flex-col justify-center">
|
||||
<h1 className="text-xl font-semibold leading-none text-gray-900">Upload Batch</h1>
|
||||
<div className="flex items-center gap-2 text-sm font-normal text-gray-700"></div>
|
||||
</div>
|
||||
<div
|
||||
className="cursor-pointer hover:opacity-100 opacity-50"
|
||||
onClick={() => {
|
||||
handleUploadBatchDialog(false);
|
||||
resetForm();
|
||||
}}
|
||||
>
|
||||
<KeenIcon icon="cross" className="text-1.5xl" />
|
||||
</div>
|
||||
</div>
|
||||
</DialogHeader>
|
||||
<DialogBody className="scrollable-y px-0 pb-0" ref={parentRef}>
|
||||
<div className="flex flex-col px-0">
|
||||
{alert.show && (
|
||||
<Alert variant="danger" className="mb-3">
|
||||
<h3>{alert.message}</h3>
|
||||
</Alert>
|
||||
)}
|
||||
<form action="" onSubmit={handleSubmit}>
|
||||
<div className="card-body grid gap-5 p-0">
|
||||
<div className="w-full">
|
||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label className="form-label flex items-center gap-1 max-w-56">Execution Date</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="datetime-local"
|
||||
autoComplete="off"
|
||||
value={formField.execution_date}
|
||||
required
|
||||
onChange={({ target }) =>
|
||||
setFormField((prev) => ({ ...prev, execution_date: target.value }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||
<label className="form-label flex items-center gap-1 max-w-56">File</label>
|
||||
<Input
|
||||
className="input"
|
||||
type="file"
|
||||
autoComplete="off"
|
||||
required
|
||||
onChange={({ target }) =>
|
||||
setFormField((prev) => ({ ...prev, file: target.files?.[0] ?? null }))
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-end pt-2.5">
|
||||
<Button className="btn btn-primary" type="submit">
|
||||
Save Changes
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</DialogBody>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export { UploadBatchDialog };
|
||||
@ -0,0 +1,289 @@
|
||||
import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components';
|
||||
import { Toaster } from '@/components/ui/sonner';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import axios from 'axios';
|
||||
import React, { createContext, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useCallApi } from '@/hooks';
|
||||
import ListToolbar from '../blocks/ListToolbar';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useNavigate } from 'react-router';
|
||||
import moment from 'moment';
|
||||
import DetailTransaction from '../blocks/DetailTransaction';
|
||||
|
||||
interface TransactionProps {
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface ContextProps {
|
||||
getTransactionLists: (
|
||||
limit: number,
|
||||
page: number,
|
||||
with_deleted: boolean,
|
||||
order_field: any,
|
||||
order_direction: any,
|
||||
filter: any
|
||||
) => Promise<{ data: TransactionProps[]; totalCount: number } | undefined>;
|
||||
showDetailDialog: boolean;
|
||||
setShowDetailDialog: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
selectedTransactionId: number | null;
|
||||
setSelectedTransactionId: React.Dispatch<React.SetStateAction<number | null>>;
|
||||
showUploadBatchDialog: boolean;
|
||||
handleUploadBatchDialog: (show: boolean) => void;
|
||||
}
|
||||
|
||||
const initialProps: ContextProps = {
|
||||
getTransactionLists: async () => ({ data: [], totalCount: 0 }),
|
||||
showDetailDialog: false,
|
||||
setShowDetailDialog: () => { },
|
||||
selectedTransactionId: null,
|
||||
setSelectedTransactionId: () => { },
|
||||
showUploadBatchDialog: false,
|
||||
handleUploadBatchDialog: (show: boolean) => {},
|
||||
};
|
||||
|
||||
type StatusCode = 'W' | 'P' | 'F' | 'D' | 'Y';
|
||||
|
||||
interface StatusInfo {
|
||||
label: string;
|
||||
bg: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
const statusMap: Record<StatusCode, StatusInfo> = {
|
||||
W: { label: 'Waiting', bg: 'bg-yellow-100', text: 'text-yellow-600' },
|
||||
P: { label: 'Pending', bg: 'bg-blue-100', text: 'text-blue-600' },
|
||||
F: { label: 'Fail', bg: 'bg-red-100', text: 'text-red-600' },
|
||||
D: { label: 'Done', bg: 'bg-green-100', text: 'text-green-600' },
|
||||
Y: { label: 'Active', bg: 'bg-green-100', text: 'text-green-600' },
|
||||
};
|
||||
|
||||
|
||||
const ManageTransactionContext = createContext<ContextProps>(initialProps);
|
||||
const API_URL = apiConfig.service_disbursement;
|
||||
|
||||
const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
const [showDetailDialog, setShowDetailDialog] = useState(false);
|
||||
const [selectedTransactionId, setSelectedTransactionId] = useState<number | null>(null);
|
||||
const [showUploadBatchDialog, setShowUploadBatchDialog] = useState(false);
|
||||
const [transaction, setTransaction] = useState<TransactionProps[]>([]);
|
||||
const { GetData } = useCallApi();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleUploadBatchDialog = useCallback((show: boolean) => {
|
||||
setShowUploadBatchDialog(show);
|
||||
}, []);
|
||||
|
||||
const columns = useMemo<ColumnDef<any>[]>(
|
||||
() => [
|
||||
// {
|
||||
// accessorKey: 'transaction_date',
|
||||
// header: ({ column }) => <DataGridColumnHeader title="Transaction Date" column={column} />,
|
||||
// enableSorting: false,
|
||||
// enableHiding: false,
|
||||
// meta: {
|
||||
// headerClassName: 'w-[250px]'
|
||||
// }
|
||||
// },
|
||||
{
|
||||
accessorKey: 'file_name',
|
||||
header: ({ column }) => <DataGridColumnHeader title="File Name" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
meta: {
|
||||
headerClassName: 'w-[250px]'
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => {
|
||||
return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(row.amount);
|
||||
},
|
||||
id: 'amount',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Amount" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
meta: {
|
||||
headerClassName: 'w-[250px]',
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'total_record',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Total Record" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
meta: {
|
||||
headerClassName: 'w-[250px]'
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'total_success',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Success Record" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
meta: {
|
||||
headerClassName: 'w-[250px]'
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'total_fail',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Fail Record" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
meta: {
|
||||
headerClassName: 'w-[250px]'
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'total_pending',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Pending Record" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
meta: {
|
||||
headerClassName: 'w-[250px]'
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.status,
|
||||
id: 'status',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Status" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => {
|
||||
const status = row.original.status as StatusCode;
|
||||
const { label, bg, text } = statusMap[status] ?? {
|
||||
label: 'Unknown',
|
||||
bg: 'bg-gray-100',
|
||||
text: 'text-gray-600',
|
||||
};
|
||||
|
||||
return (
|
||||
<span
|
||||
className={`px-2 py-1 text-xs font-semibold rounded-full ${bg} ${text}`}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
headerClassName: 'w-[100px]',
|
||||
cellClassName: 'text-center',
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.execution_date,
|
||||
id: 'execution_date',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Execution Date" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => moment(row.original.execution_date).format('YYYY-MM-DD HH:mm:ss')
|
||||
},
|
||||
{
|
||||
accessorFn: (row) => row.done_date,
|
||||
id: 'done_date',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Done Date" column={column} />,
|
||||
enableSorting: true,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => row.original.done_date ? moment(row.original.done_date).format('YYYY-MM-DD HH:mm:ss') : ''
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: ({ column }) => <DataGridColumnHeader title="Actions" column={column} />,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: (data) => {
|
||||
const row = data.row.original;
|
||||
return (
|
||||
<div key={`actions-${row.id}`}>
|
||||
<button
|
||||
className="btn btn-sm btn-icon btn-clear btn-light"
|
||||
onClick={() => {
|
||||
setSelectedTransactionId(row.id);
|
||||
setShowDetailDialog(true);
|
||||
}}
|
||||
>
|
||||
<KeenIcon icon="eye" />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
meta: {
|
||||
headerClassName: 'w-[100px]',
|
||||
cellClassName: 'text-center'
|
||||
}
|
||||
}
|
||||
],
|
||||
[]);
|
||||
|
||||
const getTransactionLists = async (page: number, limit: number, sorting: any, filter: any) => {
|
||||
try {
|
||||
let startdate;
|
||||
let enddate;
|
||||
let formattedFilter;
|
||||
|
||||
if (filter == undefined || filter.length == 0) {
|
||||
const today = new Date();
|
||||
const nextWeek = new Date();
|
||||
nextWeek.setDate(today.getDate() + 7);
|
||||
|
||||
startdate = today.toISOString().split('T')[0];
|
||||
enddate = nextWeek.toISOString().split('T')[0];
|
||||
} else if (filter != undefined || filter.length != 0) {
|
||||
startdate = filter[0].value.from;
|
||||
enddate = filter[0].value.to;
|
||||
}
|
||||
|
||||
formattedFilter = {
|
||||
|
||||
};
|
||||
|
||||
const response = await GetData(`${API_URL}/transaction/history`, {
|
||||
limit,
|
||||
page: page + 1,
|
||||
with_deleted: false,
|
||||
order_field: "id",
|
||||
order_direction: 'DESC',
|
||||
filter: JSON.stringify(formattedFilter)
|
||||
});
|
||||
|
||||
setTransaction(response?.data.list);
|
||||
return { data: response?.data.list, totalCount: response?.data.total_count };
|
||||
} catch (error) {
|
||||
console.error('Error fetching transaction', error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ManageTransactionContext.Provider
|
||||
value={{
|
||||
getTransactionLists,
|
||||
showDetailDialog,
|
||||
setShowDetailDialog,
|
||||
selectedTransactionId,
|
||||
setSelectedTransactionId,
|
||||
handleUploadBatchDialog,
|
||||
showUploadBatchDialog
|
||||
}}
|
||||
>
|
||||
<Toaster expand visibleToasts={9} duration={3000} />
|
||||
<DetailTransaction />
|
||||
|
||||
<DataGridProvider
|
||||
columns={columns}
|
||||
pagination={{ size: 10 }}
|
||||
toolbar={<ListToolbar />}
|
||||
layout={{ card: true }}
|
||||
sorting={[{ id: 'id', desc: false }]}
|
||||
serverSide={true}
|
||||
onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) =>
|
||||
getTransactionLists(pageIndex, pageSize, sorting, columnFilters)
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</DataGridProvider>
|
||||
</ManageTransactionContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export { TransactionProvider, ManageTransactionContext };
|
||||
export type { TransactionProps };
|
||||
@ -0,0 +1,2 @@
|
||||
export * from './TransactionContext';
|
||||
export * from './useTransactionContext';
|
||||
@ -0,0 +1,12 @@
|
||||
import { useContext } from 'react';
|
||||
import { ManageTransactionContext } from './TransactionContext';
|
||||
|
||||
const useTransactionContext = () => {
|
||||
const context = useContext(ManageTransactionContext);
|
||||
|
||||
if (!context) throw new Error('useTransactionContext must be used within AuthProvider');
|
||||
|
||||
return context;
|
||||
};
|
||||
|
||||
export { useTransactionContext };
|
||||
@ -280,7 +280,7 @@ const ManageProductsContextProvider = ({ children }: { children: React.ReactNode
|
||||
pagination={{ size: 10 }}
|
||||
toolbar={<ListToolbar />}
|
||||
layout={{ card: true }}
|
||||
sorting={[{ id: 'Product.created_at', desc: false }]}
|
||||
sorting={[{ id: 'Product.created_at', desc: true }]}
|
||||
serverSide={true}
|
||||
onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) =>
|
||||
getProductsLists(pageIndex, pageSize, sorting, columnFilters)
|
||||
|
||||
@ -40,6 +40,10 @@ import WalletHistory from '@/pages/wallet/wallet-history/WalletHistory';
|
||||
import WalletMaster from '@/pages/master/wallet/WalletMaster';
|
||||
import CurrencyMaster from '@/pages/master/currency/CurrencyMaster';
|
||||
|
||||
// DISBURSEMENT
|
||||
import HistoryTransactionDisbursement from '@/pages/disbursement/history-transaction/HistoryTransaction'
|
||||
// DISBURSEMENT
|
||||
|
||||
const AppRoutingSetup = (): ReactElement => {
|
||||
return (
|
||||
<Routes>
|
||||
@ -100,6 +104,11 @@ const AppRoutingSetup = (): ReactElement => {
|
||||
path="/settings/user-management/manage-position"
|
||||
element={<ManagePositionPage />}
|
||||
/>
|
||||
|
||||
{/* DISBURSEMENT */}
|
||||
<Route path="/disbursement/transaction-history" element={<HistoryTransactionDisbursement />} />
|
||||
{/* DISBURSEMENT */}
|
||||
|
||||
</Route>
|
||||
</Route>
|
||||
<Route path="error/*" element={<ErrorsRouting />} />
|
||||
|
||||
Reference in New Issue
Block a user