diff --git a/src/pages/members/feedback-member/blocks/EditDialog.tsx b/src/pages/members/feedback-member/blocks/EditDialog.tsx index b12a0c0..c99d396 100644 --- a/src/pages/members/feedback-member/blocks/EditDialog.tsx +++ b/src/pages/members/feedback-member/blocks/EditDialog.tsx @@ -1,5 +1,5 @@ import { useState, useEffect } from 'react'; -import { Dialog, DialogContent } from '@/components/ui/dialog'; +import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Select, SelectContent, @@ -59,16 +59,12 @@ const EditDialog = () => { if (response?.status) { toast.success('Feedback reviewed successfully'); - // Close the edit dialog handleEditDialog(false, null); - // First close the detail dialog to reset its state handleDetailDialog(false, null); - // Refresh the main data grid first refreshData(); - // Wait a tiny bit then reopen the detail with refreshed data setTimeout(() => { handleDetailDialog(true, selectedFeedback); }, 300); @@ -97,7 +93,6 @@ const EditDialog = () => { } const data = response.data; - // console.log('Fetched data:', data); setReviewNotes(data.review_notes || ''); @@ -112,7 +107,11 @@ const EditDialog = () => { return ( handleEditDialog(open, null)}> - + + + + +
diff --git a/src/pages/transaction/approval-transaction/blocks/DetailApprovalTransaction.tsx b/src/pages/transaction/approval-transaction/blocks/DetailApprovalTransaction.tsx index 4b5d549..35756d2 100644 --- a/src/pages/transaction/approval-transaction/blocks/DetailApprovalTransaction.tsx +++ b/src/pages/transaction/approval-transaction/blocks/DetailApprovalTransaction.tsx @@ -10,8 +10,10 @@ import { DialogHeader, DialogTitle } from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; const API_URL = apiConfig.transaction; +const API_URL_CURRENT_BALANCE = apiConfig.service_wallet; const DetailApprovalTransaction = () => { const { GetData } = useCallApi(); @@ -51,6 +53,60 @@ const DetailApprovalTransaction = () => { } }, [showDetailDialog]); + const [currentBalance, setCurrentBalance] = useState(null); + const [currentBalanceTransfer, setCurrentBalanceTransfer] = useState(null); + useEffect(() => { + setCurrentBalance(null); + }, [transactionDetails]); + + useEffect(() => { + setCurrentBalanceTransfer(null); + }, [transactionDetails]); + + const getCurrentBallanceWallet = async (customerId: string) => { + try { + const responsecurrentbalance = await GetData( + `${API_URL_CURRENT_BALANCE}/dashboard/balance/account/${customerId}`, + {} + ); + + const match = responsecurrentbalance?.data?.find( + (item: any) => item.id_wallet === transactionDetails?.origin_wallet?.id + ); + + if (match) { + // console.log('Matched Wallet:', match); // Optional debug + return match.amount; + } + } catch (error) { + console.error('Error fetching current balance', error); + } + + return null; + }; + + const getCurrentBallanceWalletTransfer = async (customerIdtransfer: string) => { + try { + const response = await GetData( + `${API_URL_CURRENT_BALANCE}/dashboard/balance/account/${customerIdtransfer}`, + {} + ); + + const match = response?.data?.find( + (item: any) => item.id_wallet === transactionDetails?.transfer?.destination_wallet?.id + ); + + if (match) { + // console.log('Matched Wallet:', match); + return match.amount; + } + } catch (error) { + console.error('Error fetching current balance', error); + } + + return null; + }; + return ( @@ -471,7 +527,27 @@ const DetailApprovalTransaction = () => {

Description

{transactionDetails?.origin_wallet.description}

+
+

Current Balance

+

+ {currentBalance !== null && currentBalance !== undefined + ? new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(currentBalance) + : '-'} +

+
+
)} @@ -482,16 +558,42 @@ const DetailApprovalTransaction = () => { {!transactionDetails?.transfer ? (
No Data available
) : ( -
-
-

Name

-

{transactionDetails.transfer.destination_wallet.name}

+ <> +
+
+

Name

+

{transactionDetails.transfer.destination_wallet.name}

+
+
+

Description

+

{transactionDetails.transfer.destination_wallet.description}

+
+
+

Current Balance

+

+ {currentBalanceTransfer !== null + ? new Intl.NumberFormat('en-US', { + style: 'currency', + currency: 'USD', + }).format(currentBalanceTransfer) + : '-'} +

+
-
-

Description

-

{transactionDetails.transfer.destination_wallet.description}

-
-
+ + )}
)} @@ -540,8 +642,8 @@ const DetailApprovalTransaction = () => { }) : ''} {log.request_body} - {log.response_body} - {log.request_endpoint} + {log.response_body} + {log.request_endpoint} )) ) : ( diff --git a/src/pages/transaction/history-transaction/blocks/DetailTransaction.tsx b/src/pages/transaction/history-transaction/blocks/DetailTransaction.tsx index de6a873..decf631 100644 --- a/src/pages/transaction/history-transaction/blocks/DetailTransaction.tsx +++ b/src/pages/transaction/history-transaction/blocks/DetailTransaction.tsx @@ -13,11 +13,15 @@ import { DialogTitle } from '@/components/ui/dialog'; import { useDataGrid } from '@/components'; +import { Button } from '@/components/ui/button'; const API_URL = apiConfig.transaction; +const API_URL_CURRENT_BALANCE = apiConfig.service_wallet; + const DetailTransaction = () => { const { GetData } = useCallApi(); + // const { reload } = useDataGrid(); const { showDetailDialog, @@ -45,7 +49,7 @@ const DetailTransaction = () => { id: selectedTransactionId }); setTransactionDetails(response?.data); - // console.log(response?.data); + // console.log(response?.data.origin_customer.id); // console.log(selectedTransactionId); } catch (error) { console.error('Error fetching transaction', error); @@ -67,6 +71,61 @@ const DetailTransaction = () => { } }, [showDetailDialog]); + const [currentBalance, setCurrentBalance] = useState(null); + const [currentBalanceTransfer, setCurrentBalanceTransfer] = useState(null); + + useEffect(() => { + setCurrentBalance(null); + }, [transactionDetails]); + + useEffect(() => { + setCurrentBalanceTransfer(null); + }, [transactionDetails]); + + const getCurrentBallanceWallet = async (customerId: string) => { + try { + const responsecurrentbalance = await GetData( + `${API_URL_CURRENT_BALANCE}/dashboard/balance/account/${customerId}`, + {} + ); + + const match = responsecurrentbalance?.data?.find( + (item: any) => item.id_wallet === transactionDetails?.origin_wallet?.id + ); + + if (match) { + // console.log('Matched Wallet:', match); // Optional debug + return match.amount; + } + } catch (error) { + console.error('Error fetching current balance', error); + } + + return null; + }; + + + const getCurrentBallanceWalletTransfer = async (customerIdtransfer: string) => { + try { + const response = await GetData( + `${API_URL_CURRENT_BALANCE}/dashboard/balance/account/${customerIdtransfer}`, + {} + ); + + const match = response?.data?.find( + (item: any) => item.id_wallet === transactionDetails?.transfer?.destination_wallet?.id + ); + + if (match) { + // console.log('Matched Wallet:', match); + return match.amount; + } + } catch (error) { + console.error('Error fetching current balance', error); + } + + return null; + }; return ( @@ -231,16 +290,6 @@ const DetailTransaction = () => { -

- Origin Wallet - - Wallet - -

-
- -
-

Purchase @@ -482,7 +531,27 @@ const DetailTransaction = () => {

Description

{transactionDetails?.origin_wallet.description}

+
+

Current Balance

+

+ {currentBalance !== null && currentBalance !== undefined + ? new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(currentBalance) + : '-'} +

+
+ )} @@ -493,16 +562,43 @@ const DetailTransaction = () => { {!transactionDetails?.transfer ? (
No Data available
) : ( -
-
-

Name

-

{transactionDetails.transfer.destination_wallet.name}

+ <> +
+
+

Name

+

{transactionDetails.transfer.destination_wallet.name}

+
+
+

Description

+

{transactionDetails.transfer.destination_wallet.description}

+
+
+

Current Balance

+

+ {currentBalanceTransfer !== null + ? new Intl.NumberFormat('en-US', { + style: 'currency', + currency: 'USD', + }).format(currentBalanceTransfer) + : '-'} +

+
-
-

Description

-

{transactionDetails.transfer.destination_wallet.description}

-
-
+ + + )}
)} diff --git a/src/pages/transfer/transfertype/blocks/ListToolBar.tsx b/src/pages/transfer/transfertype/blocks/ListToolBar.tsx index c1c116c..308c074 100644 --- a/src/pages/transfer/transfertype/blocks/ListToolBar.tsx +++ b/src/pages/transfer/transfertype/blocks/ListToolBar.tsx @@ -23,6 +23,29 @@ interface TransferType { const API_URL = apiConfig.service_transaction; +const typeLabelMap: Record = { + D: 'Disbursement', + O: 'Other', + CA: 'Change Group Emoney Customer to Agent', + AC: 'Change Group Emoney Agent to Customer', + PC: 'Change Group Point Agent to Customer', + PA: 'Change Group Point Customer to Agent', + CE: 'Return Customer Emoney', + AD: 'Return Agent Deposit', + AM: 'Return Agent Merchant', + AE: 'Return Agent Emoney', + R: 'Reward Point', + TE: 'Top Up Escrow', + TM: 'Top Up Master Agent', + TA: 'Top Up Agent', + PL: 'Purchase Loja', + DE: 'Disbursment Escrow', + DM: 'Disbursment Master Agent', + DA: 'Disbursment Agent', + WI: 'Withdraw Merchant', + IC: 'Income Merchant' +}; + const ListToolbar = () => { const { table, reload } = useDataGrid(); const { handleAddDialog } = useManageTransferTypeContext(); @@ -31,40 +54,10 @@ const ListToolbar = () => { const [searchValue, setSearchValue] = useState(''); const [statusTypes, setStatusTypes] = useState(''); - const [walletOrigins, setWalletOrigin] = useState(''); - const [walletDestinations, setWalletDestination] = useState(''); const [approval, setApproval] = useState(''); const unique = (arr: string[]) => Array.from(new Set(arr)); const types = unique(transferTypes.map((t) => t.type)); - const origins = unique(transferTypes.map((t) => t.wallet_origin.name)); - const destinations = unique(transferTypes.map((t) => t.wallet_destination.name)); - const typeLabelMap: Record = { - D: 'Disbursement', - O: 'Other', - CA: 'Change Group Emoney Customer to Agent', - AC: 'Change Group Emoney Agent to Customer', - PC: 'Change Group Point Agent to Customer', - PA: 'Change Group Point Customer to Agent', - CE: 'Return Customer Emoney', - AD: 'Return Agent Deposit', - AM: 'Return Agent Merchant', - AE: 'Return Agent Emoney', - R: 'Reward Point', - TE: 'Top Up Escrow', - TM: 'Top Up Master Agent', - TA: 'Top Up Agent', - PL: 'Purchase Loja', - DE: 'Disbursment Escrow', - DM: 'Disbursment Master Agent', - DA: 'Disbursment Agent', - WI: 'Withdraw Merchant', - IC: 'Income Merchant' - }; - const approvalLabelMap: Record = { - Y: 'Yes', - N: 'No' - }; useEffect(() => { const timer = setTimeout(() => { @@ -78,18 +71,6 @@ const ListToolbar = () => { table.getColumn('type')?.setFilterValue(statusTypes); }, [statusTypes]); - useEffect(() => { - table - .getColumn('wallet_origin') - ?.setFilterValue(walletOrigins === '__all__' ? '' : walletOrigins); - }, [walletOrigins]); - - useEffect(() => { - table - .getColumn('wallet_destination') - ?.setFilterValue(walletDestinations === '__all__' ? '' : walletDestinations); - }, [walletDestinations]); - useEffect(() => { table.getColumn('status_approval')?.setFilterValue(approval); }, [approval]); @@ -115,62 +96,86 @@ const ListToolbar = () => { const handleClearFilter = () => { setSearchValue(''); - setStatusTypes('__all__'); - setWalletOrigin('__all__'); - setWalletDestination('__all__'); - setApproval('__all__'); + setStatusTypes(''); + setApproval(''); + table.getColumn('name')?.setFilterValue(''); table.getColumn('type')?.setFilterValue(''); - table.getColumn('wallet_origin')?.setFilterValue(''); - table.getColumn('wallet_destination')?.setFilterValue(''); table.getColumn('status_approval')?.setFilterValue(''); - table.setPageIndex(0); + + setTimeout(() => { + table.setPageIndex(0); + reload(); + }, 0); }; - const renderSelect = ( - placeholder: string, - value: string, - onChange: (val: string) => void, - options: string[], - labelMap?: Record - ) => ( -
- -
- ); - - return ( -
-
+
+
-
- +
+
+ +
+ +
+ +
+ +
+ +
+ + +
-
- {/* Filter bar */} -
- {renderSelect( - 'Select Status Transaction Type', - statusTypes, - setStatusTypes, - types, - typeLabelMap - )} - {renderSelect( - 'Select Status Approval', - approval, - setApproval, - ['Y', 'N'], - approvalLabelMap - )} - {/* {renderSelect('Select Origin Wallet', walletOrigins, setWalletOrigin, origins)} - {renderSelect( - 'Select Destination Wallet', - walletDestinations, - setWalletDestination, - destinations - )} */} - - {/* {renderSelect('Origin', walletOrigins, setWalletOrigin, origins)} - {renderSelect('Destination', walletDestinations, setWalletDestination, destinations)} */} -
); diff --git a/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx b/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx index 683e9ae..e173f59 100644 --- a/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx +++ b/src/pages/wallet/wallet-history/blocks/ListToolbar.tsx @@ -19,6 +19,13 @@ interface WalletProps { name: string; } +const getOneMonthsAgo = () => { + const today = new Date(); + return new Date(today.getFullYear(), today.getMonth() - 1, today.getDate()); +}; + +const formatDate = (date: Date): string => date.toISOString().split('T')[0]; + const ListToolbar = () => { const { table, reload } = useDataGrid(); const { GetData } = useCallApi(); @@ -32,12 +39,10 @@ const ListToolbar = () => { ); const [wallets, setWallets] = useState([]); - const formatDate = (date: Date): string => date.toISOString().split('T')[0]; - useEffect(() => { const today = new Date(); - const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1); - setDateRange({ from: formatDate(firstDayOfMonth), to: formatDate(today) }); + const threeMonthsAgo = getOneMonthsAgo(); + setDateRange({ from: formatDate(threeMonthsAgo), to: formatDate(today) }); }, []); useEffect(() => { @@ -45,7 +50,6 @@ const ListToolbar = () => { table.getColumn('msisdn')?.setFilterValue(searchValue); table.setPageIndex(0); }, 200); - return () => clearTimeout(timer); }, [searchValue, table]); @@ -89,35 +93,50 @@ const ListToolbar = () => { }, []); const handleClearAllFilters = () => { + const today = new Date(); + const oneMonthAgo = getOneMonthsAgo(); + const resetDateRange = { + from: formatDate(oneMonthAgo), + to: formatDate(today) + }; + setSearchValue(''); setWalletId(''); + setDateRange(resetDateRange); + + table.getColumn('msisdn')?.setFilterValue(''); + table.getColumn('id_wallet')?.setFilterValue(''); + table.getColumn('CreatedAt')?.setFilterValue(resetDateRange); + + setTimeout(() => { + table.setPageIndex(0); + reload(); + }, 0); + }; + + const handleRefresh = () => { const today = new Date(); - const firstDayOfMonth = new Date(today.getFullYear(), today.getMonth(), 1); - setDateRange({ - from: formatDate(firstDayOfMonth), + const threeMonthsAgo = getOneMonthsAgo(); + const resetDateRange = { + from: formatDate(threeMonthsAgo), to: formatDate(today) - }); + }; - table.getAllColumns().forEach((column) => { - if (column.id !== 'CreatedAt') { - column.setFilterValue(undefined); - } - }); + setSearchValue(''); + setWalletId(''); + setDateRange(resetDateRange); + table.setColumnFilters([{ id: 'CreatedAt', value: resetDateRange }]); table.setPageIndex(0); - - table.getColumn('CreatedAt')?.setFilterValue({ - from: formatDate(firstDayOfMonth), - to: formatDate(today) - }); + reload(); }; return (
-
+
-
-