From 6603627165f7fc7a0be8c848ac74598cd18c0d52 Mon Sep 17 00:00:00 2001 From: Narul Hidayah Date: Fri, 18 Apr 2025 15:42:01 +0700 Subject: [PATCH] wallet in topup and disbursment transaction --- .../TransactionDisbursement.tsx | 37 +++++++++++++++++- .../transaction/topup/TransactionTopup.tsx | 38 ++++++++++++++++++- 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/pages/transaction/disbursement-saldo/TransactionDisbursement.tsx b/src/pages/transaction/disbursement-saldo/TransactionDisbursement.tsx index e608cd6..72c660d 100644 --- a/src/pages/transaction/disbursement-saldo/TransactionDisbursement.tsx +++ b/src/pages/transaction/disbursement-saldo/TransactionDisbursement.tsx @@ -4,10 +4,11 @@ import { Breadcrumbs, Link } from '@mui/material'; import { Helmet } from 'react-helmet'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; -import { useState } from 'react'; +import { useState ,useEffect } from 'react'; import { useCallApi } from '@/hooks'; import { apiConfig } from '@/config/api.config'; import { toast } from 'sonner'; +import { getAuth } from '@/auth'; const TransactionDisbursement = () => { const [form, setForm] = useState({ @@ -15,8 +16,28 @@ const TransactionDisbursement = () => { amount: '', pin: '' }); + const [wallets, setWallets] = useState([]); const { GetData, PostData } = useCallApi(); + const parsedUser = getAuth()?.user; 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'); + } + }; + + fetchWallets(); + }, []); const handleSubmit = async (e: any) => { e.preventDefault(); @@ -61,6 +82,20 @@ const TransactionDisbursement = () => { Disbursement Saldo + {/* Wallet Section */} +
+

Your Wallets

+
+ {wallets.map((wallet: any) => ( +
+

{wallet.wallet}

+

+ {new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(wallet.amount)} +

+
+ ))} +
+
diff --git a/src/pages/transaction/topup/TransactionTopup.tsx b/src/pages/transaction/topup/TransactionTopup.tsx index 744abb0..a05fb95 100644 --- a/src/pages/transaction/topup/TransactionTopup.tsx +++ b/src/pages/transaction/topup/TransactionTopup.tsx @@ -4,18 +4,40 @@ import { Breadcrumbs, Link } from '@mui/material'; import { Helmet } from 'react-helmet'; import { Input } from '@/components/ui/input'; import { Button } from '@/components/ui/button'; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { useCallApi } from '@/hooks'; import { apiConfig } from '@/config/api.config'; import { toast } from 'sonner'; +import { getAuth } from '@/auth'; const TransactionTopup = () => { const [form, setForm] = useState({ topupAmount: '', pin: '' }); + + const [wallets, setWallets] = useState([]); const { GetData, PostData } = useCallApi(); + const parsedUser = getAuth()?.user; 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'); + } + }; + + fetchWallets(); + }, []); const handleSubmit = async (e: any) => { e.preventDefault(); @@ -60,6 +82,20 @@ const TransactionTopup = () => { Topup + {/* Wallet Section */} +
+

Your Wallets

+
+ {wallets.map((wallet: any) => ( +
+

{wallet.wallet}

+

+ {new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(wallet.amount)} +

+
+ ))} +
+