update
This commit is contained in:
@ -269,7 +269,7 @@ const DashboardHomePage = () => {
|
|||||||
|
|
||||||
<div className="flex space-x-4 mt-5">
|
<div className="flex space-x-4 mt-5">
|
||||||
{bankaccount?.data && bankaccount?.data.length > 0
|
{bankaccount?.data && bankaccount?.data.length > 0
|
||||||
&& getAuth()?.statusbalance=='Y'
|
// && getAuth()?.statusbalance=='Y'
|
||||||
? (
|
? (
|
||||||
bankaccount?.data.map((bankaccountdatas: { id_balance:string,amount: string, credit_limit: string, monthly_limit: string; wallet: string; }, index: number) => (
|
bankaccount?.data.map((bankaccountdatas: { id_balance:string,amount: string, credit_limit: string, monthly_limit: string; wallet: string; }, index: number) => (
|
||||||
<BankSaldo
|
<BankSaldo
|
||||||
|
|||||||
@ -3,8 +3,9 @@ import {
|
|||||||
Dialog,
|
Dialog,
|
||||||
DialogBody,
|
DialogBody,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle
|
||||||
} from '@/components/ui/dialog';
|
} from '@/components/ui/dialog';
|
||||||
import { useCallApi } from '@/hooks';
|
import { useCallApi } from '@/hooks';
|
||||||
import { apiConfig } from '@/config/api.config';
|
import { apiConfig } from '@/config/api.config';
|
||||||
@ -19,24 +20,6 @@ import {
|
|||||||
} from '@/components/ui/select';
|
} from '@/components/ui/select';
|
||||||
import { DefaultTooltip, KeenIcon } from '@/components';
|
import { DefaultTooltip, KeenIcon } from '@/components';
|
||||||
|
|
||||||
interface WalletTransaction {
|
|
||||||
ID: string;
|
|
||||||
transaction_code: string;
|
|
||||||
transaction_type: {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
};
|
|
||||||
type: string;
|
|
||||||
amount: number;
|
|
||||||
pre_amount: number;
|
|
||||||
post_amount: number;
|
|
||||||
category: string;
|
|
||||||
notes: string;
|
|
||||||
date: string;
|
|
||||||
msisdn_reff?: string;
|
|
||||||
purpose?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ShowDetailWalletDialogProps {
|
interface ShowDetailWalletDialogProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
@ -58,6 +41,77 @@ const getDefaultDateRange = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ShowDetailWalletDialog: React.FC<ShowDetailWalletDialogProps> = ({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
idbalance,
|
||||||
|
}) => {
|
||||||
|
const { GetData } = useCallApi();
|
||||||
|
|
||||||
|
const [dateRange, setDateRange] = useState(getDefaultDateRange());
|
||||||
|
const [selectedTransferType, setSelectedTransferType] = useState<string | null>(null);
|
||||||
|
const [transferType, setTransferType] = useState<TransferType[]>([]);
|
||||||
|
const [selectedCategory, setSelectedCategory] = useState<string | null>(null);
|
||||||
|
const [searchValue, setSearchValue] = useState('');
|
||||||
|
const [category, setCategory] = useState<string[]>([]);
|
||||||
|
const [transaction, setTransaction] = useState<any[]>([]);
|
||||||
|
const [filters, setFilters] = useState<any>({});
|
||||||
|
|
||||||
|
const fetchTransferType = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
const response = await GetData(`${apiConfig.service_transaction}/transactiontype/list`, {
|
||||||
|
limit: 100,
|
||||||
|
page: 1,
|
||||||
|
with_deleted: false,
|
||||||
|
order_field: 'created_at',
|
||||||
|
order_direction: 'ASC',
|
||||||
|
});
|
||||||
|
setTransferType(response?.data?.list || []);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching transfer types', error);
|
||||||
|
}
|
||||||
|
}, [GetData]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchTransferType();
|
||||||
|
}, [fetchTransferType]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const uniqueCategories = Array.from(
|
||||||
|
new Set(transaction.map((tx) => tx.category).filter((cat) => !!cat))
|
||||||
|
);
|
||||||
|
setCategory(uniqueCategories);
|
||||||
|
}, [transaction]);
|
||||||
|
|
||||||
|
const handleTransferTypeChange = (value: string) => {
|
||||||
|
setSelectedTransferType(value === 'all' ? null : value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCategoryChange = (value: string) => {
|
||||||
|
setSelectedCategory(value === '' ? null : value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClearAllFilters = () => {
|
||||||
|
setDateRange(getDefaultDateRange());
|
||||||
|
setSelectedTransferType(null);
|
||||||
|
setSelectedCategory(null);
|
||||||
|
setSearchValue('');
|
||||||
|
setFilters({});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleApplyFilters = () => {
|
||||||
|
const appliedFilters: any = {};
|
||||||
|
|
||||||
|
if (dateRange.from) appliedFilters.date_from = dateRange.from+" 00:00:00";
|
||||||
|
if (dateRange.to) appliedFilters.date_to = dateRange.to+" 23:59:59";
|
||||||
|
if (selectedTransferType) appliedFilters.transaction_type_id = selectedTransferType;
|
||||||
|
if (selectedCategory) appliedFilters.category = selectedCategory;
|
||||||
|
if (searchValue) appliedFilters.transaction_code = searchValue;
|
||||||
|
|
||||||
|
setFilters(appliedFilters);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
accessorKey: 'transaction_code',
|
accessorKey: 'transaction_code',
|
||||||
@ -143,137 +197,35 @@ const columns = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const ShowDetailWalletDialog: React.FC<ShowDetailWalletDialogProps> = ({
|
const getTransactionLists = useCallback(
|
||||||
open,
|
async (page: number, limit: number, sorting: any, _columnFilters: any) => {
|
||||||
onClose,
|
// console.log(idbalance);
|
||||||
idbalance,
|
|
||||||
}) => {
|
|
||||||
const { GetData } = useCallApi();
|
|
||||||
const [data, setData] = useState<WalletTransaction[]>([]);
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
const [dateRange, setDateRange] = useState(getDefaultDateRange());
|
|
||||||
const [selectedTransferType, setSelectedTransferType] = useState<string | null>(null);
|
|
||||||
const [selectedCategory, setSelectedCategory] = useState<string | null>(null);
|
|
||||||
const [searchValue, setSearchValue] = useState('');
|
|
||||||
const [transferType, setTransferType] = useState<TransferType[]>([]);
|
|
||||||
const [category, setCategory] = useState<string[]>([]);
|
|
||||||
|
|
||||||
const fetchTransferType = async () => {
|
|
||||||
try {
|
try {
|
||||||
const response = await GetData(`${apiConfig.service_transaction}/transactiontype/list`, {
|
const response = await GetData(`${apiConfig.service_wallet}/dashboard/balance/list-balance-detail/${idbalance}`, {
|
||||||
limit: 100,
|
|
||||||
page: 1,
|
|
||||||
with_deleted: false,
|
|
||||||
order_field: 'created_at',
|
|
||||||
order_direction: 'ASC',
|
|
||||||
});
|
|
||||||
setTransferType(response?.data?.list || []);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching transfer types', error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getDetailList = useCallback(
|
|
||||||
async (
|
|
||||||
limit: number,
|
|
||||||
page: number,
|
|
||||||
with_deleted: boolean,
|
|
||||||
order_field: string,
|
|
||||||
order_direction: string,
|
|
||||||
filter: any
|
|
||||||
): Promise<WalletTransaction[]> => {
|
|
||||||
if (!idbalance) return [];
|
|
||||||
try {
|
|
||||||
const response = await GetData(
|
|
||||||
`${apiConfig.service_wallet}/dashboard/balance/list-balance-detail/${idbalance}`,
|
|
||||||
{
|
|
||||||
limit,
|
limit,
|
||||||
page,
|
page: page + 1,
|
||||||
with_deleted,
|
with_deleted: false,
|
||||||
order_field,
|
order_field: "created_at",
|
||||||
order_direction,
|
order_direction: 'DESC',
|
||||||
filter: JSON.stringify(filter),
|
filter: filters
|
||||||
}
|
|
||||||
);
|
|
||||||
return response?.data?.list || [];
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching wallet detail:', error);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[GetData, idbalance]
|
|
||||||
);
|
|
||||||
|
|
||||||
const fetchData = useCallback(
|
|
||||||
async (params: {
|
|
||||||
pageIndex: number;
|
|
||||||
pageSize: number;
|
|
||||||
sorting: Array<{ id: string; desc: boolean }>;
|
|
||||||
columnFilters: any[];
|
|
||||||
}): Promise<{ data: WalletTransaction[] }> => {
|
|
||||||
// setIsLoading(true);
|
|
||||||
const order_field = params.sorting.length ? params.sorting[0].id : 'date';
|
|
||||||
const order_direction = params.sorting.length && params.sorting[0].desc ? 'DESC' : 'ASC';
|
|
||||||
const result = await getDetailList(
|
|
||||||
params.pageSize,
|
|
||||||
params.pageIndex + 1,
|
|
||||||
false,
|
|
||||||
order_field,
|
|
||||||
order_direction,
|
|
||||||
params.columnFilters
|
|
||||||
);
|
|
||||||
setData(result);
|
|
||||||
setIsLoading(false);
|
|
||||||
return { data: result };
|
|
||||||
},
|
|
||||||
[getDetailList]
|
|
||||||
);
|
|
||||||
|
|
||||||
// Ambil unique category dari data transaksi setelah data di-fetch
|
|
||||||
useEffect(() => {
|
|
||||||
const uniqueCategories = Array.from(
|
|
||||||
new Set(data.map((tx) => tx.category).filter((cat) => !!cat))
|
|
||||||
);
|
|
||||||
setCategory(uniqueCategories);
|
|
||||||
}, [data]);
|
|
||||||
|
|
||||||
const handleTransferTypeChange = (value: string) => {
|
|
||||||
setSelectedTransferType(value === 'all' ? null : value);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCategoryChange = (value: string) => {
|
|
||||||
setSelectedCategory(value === '' ? null : value);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClearAllFilters = () => {
|
|
||||||
setDateRange(getDefaultDateRange());
|
|
||||||
setSelectedTransferType(null);
|
|
||||||
setSelectedCategory(null);
|
|
||||||
setSearchValue('');
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
fetchTransferType();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!open) return;
|
|
||||||
|
|
||||||
const filters = [];
|
|
||||||
|
|
||||||
if (dateRange.from) filters.push({ id: 'date', value: { gte: dateRange.from } });
|
|
||||||
if (dateRange.to) filters.push({ id: 'date', value: { lte: dateRange.to } });
|
|
||||||
if (selectedTransferType) filters.push({ id: 'transaction_type.id', value: selectedTransferType });
|
|
||||||
if (selectedCategory) filters.push({ id: 'category', value: selectedCategory });
|
|
||||||
if (searchValue) filters.push({ id: 'transaction_code', value: searchValue });
|
|
||||||
|
|
||||||
fetchData({
|
|
||||||
pageIndex: 0,
|
|
||||||
pageSize: 10,
|
|
||||||
sorting: [{ id: 'date', desc: true }],
|
|
||||||
columnFilters: filters,
|
|
||||||
});
|
});
|
||||||
}, [dateRange, selectedTransferType, selectedCategory, searchValue, open]);
|
|
||||||
|
// console.log(filters);
|
||||||
|
|
||||||
|
if (!response || !response.data) {
|
||||||
|
console.warn('No data received:', response);
|
||||||
|
return { data: [], totalCount: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
setTransaction(response.data.list);
|
||||||
|
return { data: response.data.list, totalCount: response.data.total_count };
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching transaction', error);
|
||||||
|
return { data: [], totalCount: 0 };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[GetData, idbalance, filters]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onClose}>
|
<Dialog open={open} onOpenChange={onClose}>
|
||||||
@ -281,9 +233,10 @@ const ShowDetailWalletDialog: React.FC<ShowDetailWalletDialogProps> = ({
|
|||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Details Wallet Statement</DialogTitle>
|
<DialogTitle>Details Wallet Statement</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
<DialogDescription />
|
||||||
|
|
||||||
<DialogBody>
|
<DialogBody>
|
||||||
<div className="py-4 max-h-[70vh] overflow-y-auto">
|
<div className="flex flex-wrap gap-2 lg:gap-5 w-full mb-4">
|
||||||
{/* <div className="flex flex-wrap gap-2 lg:gap-5 w-full mb-4">
|
|
||||||
<div className="flex flex-wrap gap-3 w-full">
|
<div className="flex flex-wrap gap-3 w-full">
|
||||||
<label className="input input-sm w-full sm:w-[160px]">
|
<label className="input input-sm w-full sm:w-[160px]">
|
||||||
From
|
From
|
||||||
@ -354,25 +307,24 @@ const ShowDetailWalletDialog: React.FC<ShowDetailWalletDialogProps> = ({
|
|||||||
<KeenIcon icon="arrow-circle-left" />
|
<KeenIcon icon="arrow-circle-left" />
|
||||||
</Button>
|
</Button>
|
||||||
</DefaultTooltip>
|
</DefaultTooltip>
|
||||||
</div>
|
|
||||||
</div> */}
|
|
||||||
|
|
||||||
|
<Button variant="outline" className="h-8" onClick={handleApplyFilters}>
|
||||||
|
Filter Data
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="py-4 max-h-[70vh] overflow-y-auto">
|
||||||
<DataGridProvider
|
<DataGridProvider
|
||||||
|
key={JSON.stringify(filters)}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={data}
|
|
||||||
pagination={{ size: 10 }}
|
pagination={{ size: 10 }}
|
||||||
toolbar={null}
|
|
||||||
layout={{ card: true }}
|
layout={{ card: true }}
|
||||||
sorting={[{ id: 'date', desc: true }]}
|
sorting={[{ id: 'id', desc: false }]}
|
||||||
serverSide={false}
|
serverSide={true}
|
||||||
onFetchData={async (params) => {
|
onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) =>
|
||||||
return await fetchData({
|
getTransactionLists(pageIndex, pageSize, sorting, columnFilters)
|
||||||
pageIndex: params.pageIndex,
|
}
|
||||||
pageSize: params.pageSize,
|
|
||||||
sorting: params.sorting ?? [],
|
|
||||||
columnFilters: params.columnFilters ?? [],
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</DialogBody>
|
</DialogBody>
|
||||||
|
|||||||
Reference in New Issue
Block a user