update filter on transaction history
This commit is contained in:
@ -8,7 +8,7 @@ import {
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
SelectValue
|
||||
} from '@/components/ui/select';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { useCallApi } from '@/hooks';
|
||||
@ -20,11 +20,11 @@ const ListToolbar = () => {
|
||||
const [searchValue, setSearchValue] = useState<string>('');
|
||||
const [typeSearchValue, setSearchTypeValue] = 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 [status, setStatus] = useState<string>(
|
||||
(table.getState().columnFilters.find(f => f.id === 'status')?.value as string) ?? ''
|
||||
(table.getState().columnFilters.find((f) => f.id === 'status')?.value as string) ?? ''
|
||||
);
|
||||
|
||||
const { GetData } = useCallApi();
|
||||
@ -54,7 +54,9 @@ const ListToolbar = () => {
|
||||
table.getColumn('transaction_date')?.setFilterValue(trxDate);
|
||||
|
||||
table.setColumnFilters((prev) => {
|
||||
const others = prev.filter(f => f.id !== 'kind' && f.id !== 'searchtype' && f.id !== 'code' && f.id !== 'status');
|
||||
const others = prev.filter(
|
||||
(f) => f.id !== 'kind' && f.id !== 'searchtype' && f.id !== 'code' && f.id !== 'status'
|
||||
);
|
||||
const filters: any[] = [...others];
|
||||
|
||||
if (typeValue) filters.push({ id: 'kind', value: typeValue });
|
||||
@ -67,56 +69,53 @@ const ListToolbar = () => {
|
||||
table.setPageIndex(0);
|
||||
}, [trxDate, typeValue, typeSearchValue, searchValue, status, table]);
|
||||
|
||||
const exporDataToExcel = async (
|
||||
typeSearchValue: string,
|
||||
searchValue: string,
|
||||
trxDate: any,
|
||||
typeValue: string,
|
||||
status: string
|
||||
) => {
|
||||
try {
|
||||
const formattedFilter: any = {};
|
||||
const exporDataToExcel = async (
|
||||
typeSearchValue: string,
|
||||
searchValue: string,
|
||||
trxDate: any,
|
||||
typeValue: string,
|
||||
status: string
|
||||
) => {
|
||||
try {
|
||||
const formattedFilter: any = {};
|
||||
|
||||
// Tambahkan filter tanggal (selalu ada)
|
||||
if (trxDate.from && trxDate.to) {
|
||||
formattedFilter["Transactions.transaction_date"] = {
|
||||
from: `${trxDate.from} 00:00:00`,
|
||||
to: `${trxDate.to} 23:59:59`,
|
||||
};
|
||||
}
|
||||
|
||||
// Tambahkan filter berdasarkan searchType (sama seperti di search)
|
||||
if (typeSearchValue && searchValue) {
|
||||
if (typeSearchValue === 'msisdn') {
|
||||
formattedFilter['origin_customer.msisdn'] = { like: `%${searchValue}%` };
|
||||
} else if (typeSearchValue === 'fullname') {
|
||||
formattedFilter['origin_customer.fullname'] = { like: `%${searchValue}%` };
|
||||
} else if (typeSearchValue === 'trxid') {
|
||||
formattedFilter['Transactions.code'] = { like: `%${searchValue}%` };
|
||||
// Tambahkan filter tanggal (selalu ada)
|
||||
if (trxDate.from && trxDate.to) {
|
||||
formattedFilter['Transactions.transaction_date'] = {
|
||||
from: `${trxDate.from} 00:00:00`,
|
||||
to: `${trxDate.to} 23:59:59`
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Tambahkan filter jenis transaksi jika ada
|
||||
if (typeValue) {
|
||||
formattedFilter['Transactions.kind'] = typeValue;
|
||||
}
|
||||
// Tambahkan filter berdasarkan searchType (sama seperti di search)
|
||||
if (typeSearchValue && searchValue) {
|
||||
if (typeSearchValue === 'msisdn') {
|
||||
formattedFilter['origin_customer.msisdn'] = { like: `%${searchValue}%` };
|
||||
} else if (typeSearchValue === 'fullname') {
|
||||
formattedFilter['origin_customer.fullname'] = { like: `%${searchValue}%` };
|
||||
} else if (typeSearchValue === 'trxid') {
|
||||
formattedFilter['Transactions.code'] = { like: `%${searchValue}%` };
|
||||
}
|
||||
}
|
||||
|
||||
// Tambahkan filter status jika ada
|
||||
if (status) {
|
||||
formattedFilter['Transactions.status'] = status;
|
||||
}
|
||||
// Tambahkan filter jenis transaksi jika ada
|
||||
if (typeValue) {
|
||||
formattedFilter['Transactions.kind'] = typeValue;
|
||||
}
|
||||
|
||||
// Tambahkan filter status jika ada
|
||||
if (status) {
|
||||
formattedFilter['Transactions.status'] = status;
|
||||
}
|
||||
|
||||
const filterParam = encodeURIComponent(JSON.stringify(formattedFilter));
|
||||
|
||||
const response = await fetch(
|
||||
`${API_URL}/transaction/export?filter=${filterParam}`,
|
||||
{
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${getAuth()?.access_token}`,
|
||||
},
|
||||
const response = await fetch(`${API_URL}/transaction/export?filter=${filterParam}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${getAuth()?.access_token}`
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch file');
|
||||
@ -143,9 +142,7 @@ const ListToolbar = () => {
|
||||
<input
|
||||
type="date"
|
||||
value={trxDate.from}
|
||||
onChange={(event) =>
|
||||
settrxDate({ ...trxDate, from: event.target.value })
|
||||
}
|
||||
onChange={(event) => settrxDate({ ...trxDate, from: event.target.value })}
|
||||
name="from"
|
||||
/>
|
||||
</label>
|
||||
@ -155,9 +152,7 @@ const ListToolbar = () => {
|
||||
<input
|
||||
type="date"
|
||||
value={trxDate.to}
|
||||
onChange={(event) =>
|
||||
settrxDate({ ...trxDate, to: event.target.value })
|
||||
}
|
||||
onChange={(event) => settrxDate({ ...trxDate, to: event.target.value })}
|
||||
name="to"
|
||||
/>
|
||||
</label>
|
||||
|
||||
@ -340,7 +340,7 @@ const TransactionProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
let enddate: string | undefined;
|
||||
// let transactioncode = '';
|
||||
let type = '';
|
||||
let status = '';
|
||||
let status = '';
|
||||
let searchType = '';
|
||||
let codeValue = '';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user