Merge branch 'master' of https://git.shiblysolution.id/TPAY/dashboard
This commit is contained in:
@ -95,7 +95,22 @@ const ApprovalTransactionProvider = ({ children }: { children: React.ReactNode }
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'origin_customer.fullname',
|
accessorKey: 'origin_customer.fullname',
|
||||||
header: ({ column }) => <DataGridColumnHeader title="Full Name" column={column} />,
|
header: ({ column }) => <DataGridColumnHeader title="Origin Customer Full Name" column={column} />,
|
||||||
|
enableSorting: false,
|
||||||
|
enableHiding: false,
|
||||||
|
meta: {
|
||||||
|
headerClassName: 'w-[250px]',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorFn: (row) => {
|
||||||
|
const purchase = row?.purchase?.destination_customer.fullname;
|
||||||
|
const transfer = row?.transfer?.destination_customer.fullname;
|
||||||
|
|
||||||
|
return purchase ?? transfer ?? "-";
|
||||||
|
},
|
||||||
|
id: 'destination_customer.fullname',
|
||||||
|
header: ({ column }) => <DataGridColumnHeader title="Destination Customer Full Name" column={column} />,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
meta: {
|
meta: {
|
||||||
@ -270,7 +285,7 @@ const ApprovalTransactionProvider = ({ children }: { children: React.ReactNode }
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ✅ Declare formattedFilter early
|
// ✅ Declare formattedFilter early
|
||||||
const formattedFilter: any = {
|
const formattedFilter: any = {
|
||||||
"Transactions.transaction_date": {
|
"Transactions.transaction_date": {
|
||||||
|
|||||||
@ -10,35 +10,33 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from '@/components/ui/select';
|
} from '@/components/ui/select';
|
||||||
|
import { apiConfig } from '@/config/api.config';
|
||||||
|
import { useCallApi } from '@/hooks';
|
||||||
|
import { getAuth } from '@/auth';
|
||||||
|
|
||||||
const ListToolbar = () => {
|
const ListToolbar = () => {
|
||||||
const { table, reload } = useDataGrid();
|
const { table, reload } = useDataGrid();
|
||||||
|
|
||||||
const [trxDate, settrxDate] = useState({ from: '', to: '' });
|
const [trxDate, settrxDate] = useState({ from: '', to: '' });
|
||||||
const [searchValue, setSearchValue] = useState<string>();
|
const [searchValue, setSearchValue] = useState<string>(''); // default: empty string
|
||||||
|
const [typeSearchValue, setSearchTypeValue] = useState<string>(''); // default: empty string
|
||||||
// const [statusValue, setStatusValue] = useState<string>(
|
|
||||||
// (table.getColumn('status')?.getFilterValue() as string) ?? ''
|
|
||||||
// );
|
|
||||||
|
|
||||||
const [typeValue, setTypeValue] = useState<string>(
|
const [typeValue, setTypeValue] = useState<string>(
|
||||||
(table.getState().columnFilters.find(f => f.id === 'kind')?.value as string) ?? ''
|
(table.getState().columnFilters.find(f => f.id === 'kind')?.value as string) ?? ''
|
||||||
);
|
);
|
||||||
|
|
||||||
const [typeSearchValue, setSearchTypeValue] = useState<string>();
|
const { GetData } = useCallApi();
|
||||||
|
const API_URL = apiConfig.transaction;
|
||||||
|
|
||||||
const formatDate = (date: Date): string => {
|
const formatDate = (date: Date): string => {
|
||||||
return date.toISOString().split('T')[0];
|
return date.toISOString().split('T')[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
// useEffect(() => {
|
const today = new Date();
|
||||||
// const timer = setTimeout(() => {
|
settrxDate({
|
||||||
// table.getColumn('status')?.setFilterValue(statusValue);
|
from: formatDate(today),
|
||||||
// table.setPageIndex(0);
|
to: formatDate(today),
|
||||||
// }, 200);
|
});
|
||||||
// return () => clearTimeout(timer);
|
}, []);
|
||||||
// }, [statusValue, table]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
@ -51,10 +49,8 @@ const ListToolbar = () => {
|
|||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [typeValue, table]);
|
}, [typeValue, table]);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
// Add search type filter to column filters
|
|
||||||
table.setColumnFilters((prev) => [
|
table.setColumnFilters((prev) => [
|
||||||
...prev.filter((f) => f.id !== 'searchtype'),
|
...prev.filter((f) => f.id !== 'searchtype'),
|
||||||
{ id: 'searchtype', value: typeSearchValue },
|
{ id: 'searchtype', value: typeSearchValue },
|
||||||
@ -64,26 +60,14 @@ const ListToolbar = () => {
|
|||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [typeSearchValue, table]);
|
}, [typeSearchValue, table]);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
table.getColumn('code')?.setFilterValue(searchValue);
|
table.getColumn('code')?.setFilterValue(searchValue);
|
||||||
table.setPageIndex(0);
|
table.setPageIndex(0);
|
||||||
}, 200);
|
}, 200);
|
||||||
|
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [searchValue, table]);
|
}, [searchValue, table]);
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const today = new Date();
|
|
||||||
// const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
|
|
||||||
settrxDate({
|
|
||||||
from: formatDate(today),
|
|
||||||
to: formatDate(today),
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleFilterData = useCallback(() => {
|
const handleFilterData = useCallback(() => {
|
||||||
try {
|
try {
|
||||||
table.getColumn('transaction_date')?.setFilterValue(trxDate);
|
table.getColumn('transaction_date')?.setFilterValue(trxDate);
|
||||||
@ -99,6 +83,58 @@ const ListToolbar = () => {
|
|||||||
}
|
}
|
||||||
}, [trxDate]);
|
}, [trxDate]);
|
||||||
|
|
||||||
|
const exporDataToExcel = async (
|
||||||
|
typeSearchValue: string,
|
||||||
|
searchValue: string,
|
||||||
|
trxDate: any,
|
||||||
|
typeValue: string
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const formattedFilter: any = {
|
||||||
|
"Transactions.transaction_date": {
|
||||||
|
from: `${trxDate.from} 00:00:00`,
|
||||||
|
to: `${trxDate.to} 23:59:59`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeSearchValue === 'msisdn') {
|
||||||
|
formattedFilter['origin_customer.msisdn'] = searchValue;
|
||||||
|
} else if (typeSearchValue === 'fullname') {
|
||||||
|
formattedFilter['origin_customer.fullname'] = searchValue;
|
||||||
|
} else if (typeSearchValue === 'trxid') {
|
||||||
|
formattedFilter['Transactions.code'] = searchValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeValue) {
|
||||||
|
formattedFilter["Transactions.kind"] = typeValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterParam = encodeURIComponent(JSON.stringify(formattedFilter));
|
||||||
|
|
||||||
|
const response = await fetch(`${API_URL}/transaction/export?filter=${filterParam}`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${getAuth()?.access_token}`, // ganti dengan token kamu
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to fetch file');
|
||||||
|
}
|
||||||
|
|
||||||
|
const blob = await response.blob();
|
||||||
|
const contentDisposition = response.headers.get('content-disposition');
|
||||||
|
const filenameMatch = contentDisposition?.match(/filename="?(.+)"?/);
|
||||||
|
const filename = filenameMatch ? filenameMatch[1] : 'transaction_history.xlsx';
|
||||||
|
|
||||||
|
return { blob, filename };
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error exporting data:', error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="card-header flex-wrap gap-2 border-b-0 px-5">
|
<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 justify-between items-center">
|
<div className="flex flex-wrap gap-2 lg:gap-5 w-full justify-between items-center">
|
||||||
@ -107,7 +143,6 @@ const ListToolbar = () => {
|
|||||||
From
|
From
|
||||||
<input
|
<input
|
||||||
type="date"
|
type="date"
|
||||||
placeholder="From"
|
|
||||||
value={trxDate.from}
|
value={trxDate.from}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
settrxDate({ ...trxDate, from: event.target.value })
|
settrxDate({ ...trxDate, from: event.target.value })
|
||||||
@ -120,7 +155,6 @@ const ListToolbar = () => {
|
|||||||
To
|
To
|
||||||
<input
|
<input
|
||||||
type="date"
|
type="date"
|
||||||
placeholder="To"
|
|
||||||
value={trxDate.to}
|
value={trxDate.to}
|
||||||
onChange={(event) =>
|
onChange={(event) =>
|
||||||
settrxDate({ ...trxDate, to: event.target.value })
|
settrxDate({ ...trxDate, to: event.target.value })
|
||||||
@ -129,27 +163,9 @@ const ListToolbar = () => {
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
{/* <Select
|
|
||||||
value={statusValue}
|
|
||||||
onValueChange={(value) => {
|
|
||||||
setStatusValue(value);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<SelectTrigger className="input input-sm w-[160px] h-[31px]">
|
|
||||||
<SelectValue placeholder="Select Status" />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
<SelectItem value="C">COMPLETE</SelectItem>
|
|
||||||
<SelectItem value="F">FAILED</SelectItem>
|
|
||||||
<SelectItem value="O">ON PROCESS</SelectItem>
|
|
||||||
</SelectContent>
|
|
||||||
</Select> */}
|
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
value={typeValue}
|
value={typeValue}
|
||||||
onValueChange={(value) => {
|
onValueChange={(value) => setTypeValue(value)}
|
||||||
setTypeValue(value);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<SelectTrigger className="input input-sm w-[250px] h-[31px]">
|
<SelectTrigger className="input input-sm w-[250px] h-[31px]">
|
||||||
<SelectValue placeholder="Select Transaction Type" />
|
<SelectValue placeholder="Select Transaction Type" />
|
||||||
@ -160,15 +176,13 @@ const ListToolbar = () => {
|
|||||||
<SelectItem value="W">WITHDRAW</SelectItem>
|
<SelectItem value="W">WITHDRAW</SelectItem>
|
||||||
<SelectItem value="U">TOP UP</SelectItem>
|
<SelectItem value="U">TOP UP</SelectItem>
|
||||||
<SelectItem value="R">RETURN</SelectItem>
|
<SelectItem value="R">RETURN</SelectItem>
|
||||||
<SelectItem value='N'>TOP UP PARTNER</SelectItem>
|
<SelectItem value="N">TOP UP PARTNER</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
value={typeSearchValue}
|
value={typeSearchValue}
|
||||||
onValueChange={(value) => {
|
onValueChange={(value) => setSearchTypeValue(value)}
|
||||||
setSearchTypeValue(value);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<SelectTrigger className="input input-sm w-[250px] h-[31px]">
|
<SelectTrigger className="input input-sm w-[250px] h-[31px]">
|
||||||
<SelectValue placeholder="Select Search Type" />
|
<SelectValue placeholder="Select Search Type" />
|
||||||
@ -184,37 +198,59 @@ const ListToolbar = () => {
|
|||||||
<KeenIcon icon="magnifier" />
|
<KeenIcon icon="magnifier" />
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder={`Search ${typeSearchValue || ''}`} // Use typeSearchValue if it's set, else fallback to an empty string
|
placeholder={`Search ${typeSearchValue || ''}`}
|
||||||
value={searchValue}
|
value={searchValue}
|
||||||
onChange={(event) => setSearchValue(event.target.value)}
|
onChange={(event) => setSearchValue(event.target.value)}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="ml-auto">
|
<div className="ml-auto flex gap-2">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className="h-7.5"
|
||||||
|
onClick={async () => {
|
||||||
|
const result = await exporDataToExcel(
|
||||||
|
typeSearchValue || '',
|
||||||
|
searchValue || '',
|
||||||
|
trxDate || {},
|
||||||
|
typeValue || ''
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
const url = window.URL.createObjectURL(result.blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = result.filename;
|
||||||
|
a.click();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
} else {
|
||||||
|
toast.error('Failed to export data');
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Export Data
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<DefaultTooltip title={'Refresh'} placement={'top'}>
|
<DefaultTooltip title={'Refresh'} placement={'top'}>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="h-7.5"
|
className="h-7.5"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
// Preserve trxDate values (from, to) and reset others
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
// const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
|
|
||||||
|
|
||||||
// Only reset filters excluding from and to
|
|
||||||
setSearchValue('');
|
setSearchValue('');
|
||||||
setSearchTypeValue('');
|
setSearchTypeValue('');
|
||||||
// setStatusValue('');
|
|
||||||
setTypeValue('');
|
setTypeValue('');
|
||||||
settrxDate({
|
settrxDate({
|
||||||
from: formatDate(today),
|
from: formatDate(today),
|
||||||
to: formatDate(today),
|
to: formatDate(today),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reset other filters except for date range
|
|
||||||
table.setColumnFilters([
|
table.setColumnFilters([
|
||||||
{ id: 'code', value: '' },
|
{ id: 'code', value: '' },
|
||||||
// { id: 'status', value: '' },
|
|
||||||
{ id: 'kind', value: '' },
|
{ id: 'kind', value: '' },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@ -107,13 +107,28 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'origin_customer.fullname',
|
accessorKey: 'origin_customer.fullname',
|
||||||
header: ({ column }) => <DataGridColumnHeader title="Full Name" column={column} />,
|
header: ({ column }) => <DataGridColumnHeader title="Origin Customer Full Name" column={column} />,
|
||||||
enableSorting: false,
|
enableSorting: false,
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
meta: {
|
meta: {
|
||||||
headerClassName: 'w-[250px]'
|
headerClassName: 'w-[250px]'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
accessorFn: (row) => {
|
||||||
|
const purchase = row?.purchase?.destination_customer.fullname;
|
||||||
|
const transfer = row?.transfer?.destination_customer.fullname;
|
||||||
|
|
||||||
|
return purchase ?? transfer ?? "-";
|
||||||
|
},
|
||||||
|
id: 'destination_customer.fullname',
|
||||||
|
header: ({ column }) => <DataGridColumnHeader title="Destination Customer Full Name" column={column} />,
|
||||||
|
enableSorting: false,
|
||||||
|
enableHiding: false,
|
||||||
|
meta: {
|
||||||
|
headerClassName: 'w-[250px]',
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
accessorFn: (row) => {
|
accessorFn: (row) => {
|
||||||
const purchaseAmount = row?.purchase?.amount;
|
const purchaseAmount = row?.purchase?.amount;
|
||||||
|
|||||||
Reference in New Issue
Block a user