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: ''
});
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 filter: any =
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) => {
setIsSubmitting(true);
@ -173,6 +157,22 @@ const TransactionDisbursement = () => {
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
.filter((item) => item.label.toLowerCase().includes(searchTerm.toLowerCase()))
.slice(0, 10);

View File

@ -34,25 +34,21 @@ const TransactionTopup = () => {
const API_URL = apiConfig.transaction;
const API_URL_WALLET = apiConfig.service_wallet;
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');
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');
}
};
fetchWallets();
}, []);
} catch (error) {
toast.warning('Failed to fetch wallet data');
}
};
const doPostData = async (form: typeof initialState) => {
setIsSubmitting(true);
@ -75,6 +71,7 @@ const TransactionTopup = () => {
} finally {
setIsSubmitting(false);
setShowConfirmation(false);
fetchWallets();
ResetForm();
}
};
@ -103,6 +100,10 @@ const TransactionTopup = () => {
setAlert({ show: false, message: '' });
};
useEffect(() => {
fetchWallets();
}, []);
return (
<>
<Helmet>