diff --git a/src/pages/transaction/disbursement-saldo/TransactionDisbursement.tsx b/src/pages/transaction/disbursement-saldo/TransactionDisbursement.tsx index 9bfbb92..6df4d68 100644 --- a/src/pages/transaction/disbursement-saldo/TransactionDisbursement.tsx +++ b/src/pages/transaction/disbursement-saldo/TransactionDisbursement.tsx @@ -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); diff --git a/src/pages/transaction/topup/TransactionTopup.tsx b/src/pages/transaction/topup/TransactionTopup.tsx index 4fa7af4..64a881e 100644 --- a/src/pages/transaction/topup/TransactionTopup.tsx +++ b/src/pages/transaction/topup/TransactionTopup.tsx @@ -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 ( <>