do fetch newest balance after post data on dibursement and topup request

This commit is contained in:
Wikzyy
2025-04-30 16:41:57 +07:00
parent b1b0892d4e
commit 45974aaa97
2 changed files with 51 additions and 50 deletions

View File

@ -42,6 +42,22 @@ const TransactionDisbursement = () => {
message: '' message: ''
}); });
const fetchWallets = async () => {
try {
const response = await GetData(
`${API_URL_WALLET}/dashboard/balance/account/${parsedUser.customer.id}`,
{}
);
if (response?.status === true) {
setWallets(response.data || []);
} else {
toast.warning(response?.message || 'Failed to fetch wallet data');
}
} catch (error) {
toast.warning('Failed to fetch wallet data');
}
};
const fetchCustomerMsisdn = async (sorting: any, filterValue: string) => { const fetchCustomerMsisdn = async (sorting: any, filterValue: string) => {
const filter: any = const filter: any =
filterValue.trim().length === 0 ? {} : { msisdn: { like: `%${filterValue}%` } }; filterValue.trim().length === 0 ? {} : { msisdn: { like: `%${filterValue}%` } };
@ -74,38 +90,6 @@ const TransactionDisbursement = () => {
} }
}; };
useEffect(() => {
const fetchWallets = async () => {
try {
const response = await GetData(
`${API_URL_WALLET}/dashboard/balance/account/${parsedUser.customer.id}`,
{}
);
if (response?.status === true) {
setWallets(response.data || []);
} else {
toast.warning(response?.message || 'Failed to fetch wallet data');
}
} catch (error) {
toast.warning('Failed to fetch wallet data');
}
};
fetchWallets();
fetchCustomerMsisdn([{ id: 'msisdn', desc: false }], '');
const handleClickOutside = (event: any) => {
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
setDropdownOpen(false);
}
};
document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, []);
const doPostData = async (form: typeof initialForm) => { const doPostData = async (form: typeof initialForm) => {
setIsSubmitting(true); setIsSubmitting(true);
@ -173,6 +157,22 @@ const TransactionDisbursement = () => {
setSearchTerm(msisdn); setSearchTerm(msisdn);
}; };
useEffect(() => {
fetchWallets();
fetchCustomerMsisdn([{ id: 'msisdn', desc: false }], '');
const handleClickOutside = (event: any) => {
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
setDropdownOpen(false);
}
};
document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
}, []);
const filteredMsisdn = customerMsisdn const filteredMsisdn = customerMsisdn
.filter((item) => item.label.toLowerCase().includes(searchTerm.toLowerCase())) .filter((item) => item.label.toLowerCase().includes(searchTerm.toLowerCase()))
.slice(0, 10); .slice(0, 10);

View File

@ -34,25 +34,21 @@ const TransactionTopup = () => {
const API_URL = apiConfig.transaction; const API_URL = apiConfig.transaction;
const API_URL_WALLET = apiConfig.service_wallet; const API_URL_WALLET = apiConfig.service_wallet;
useEffect(() => { const fetchWallets = async () => {
const fetchWallets = async () => { try {
try { const response = await GetData(
const response = await GetData( `${API_URL_WALLET}/dashboard/balance/account/${parsedUser.customer.id}`,
`${API_URL_WALLET}/dashboard/balance/account/${parsedUser.customer.id}`, {}
{} );
); if (response?.status === true) {
if (response?.status === true) { setWallets(response.data || []);
setWallets(response.data || []); } else {
} else { toast.warning(response?.message || 'Failed to fetch wallet data');
toast.warning(response?.message || 'Failed to fetch wallet data');
}
} catch (error) {
toast.warning('Failed to fetch wallet data');
} }
}; } catch (error) {
toast.warning('Failed to fetch wallet data');
fetchWallets(); }
}, []); };
const doPostData = async (form: typeof initialState) => { const doPostData = async (form: typeof initialState) => {
setIsSubmitting(true); setIsSubmitting(true);
@ -75,6 +71,7 @@ const TransactionTopup = () => {
} finally { } finally {
setIsSubmitting(false); setIsSubmitting(false);
setShowConfirmation(false); setShowConfirmation(false);
fetchWallets();
ResetForm(); ResetForm();
} }
}; };
@ -103,6 +100,10 @@ const TransactionTopup = () => {
setAlert({ show: false, message: '' }); setAlert({ show: false, message: '' });
}; };
useEffect(() => {
fetchWallets();
}, []);
return ( return (
<> <>
<Helmet> <Helmet>