import { DataTable } from '@/components/ui/DataTable'; import { getColumns } from './Column'; import { apiConfig } from '@/config/api.config'; import axios, { AxiosResponse } from 'axios'; import html2canvas from 'html2canvas'; import { Helmet } from 'react-helmet'; import { DialogContent, MenuItem, Radio, RadioGroup, FormControlLabel, FormControl, Dialog, DialogTitle, Typography, Button, Box, Breadcrumbs, Link } from '@mui/material'; import { useState, useEffect, useRef } from 'react'; import { toast } from 'sonner'; import { Container, DataGridLoader, DataGridProvider, LoaderTransparant } from '@/components'; import { ListToolBar } from './ListToolbar'; import { toAbsoluteUrl } from '@/utils'; const BASE_URL = apiConfig.service_customer; let initBalance = { id: '', msisdn: '', fullname: '', username: '', agent_name: '', balance_emoney: '', balance_merchant: '', balance_point: '', balance_deposit: '' }; const AgentBalance = () => { const [isDialogOpen, setIsDialogOpen] = useState(false); const [loading, setLoading] = useState(false); const [dataBalance, setDataBalance] = useState([]); const [formData, setFormData] = useState(initBalance); const [pageIndex, setPageIndex] = useState(1); const [currentPage, setCurrentPage] = useState(0); const [pageSize, setPageSize] = useState(10); const [dialogType, setDialogType] = useState(''); const [dialogOpen, setDialogOpen] = useState(false); const [isReloading, setIsReloading] = useState(false); const [barcode, setBarcode] = useState(''); // const [selectedMember, setSelectedMember] = useState(initBalance); useEffect(() => { // fetchAgentBalance(); }, []); const fetchAgentBalance = async ( page: number, limit: number, sorting: any, filter: any ) => { filter = filter.length ? filter : {}; let balances = await axios.get(`${BASE_URL}/customer/agent-balance`, { params: { limit: limit, page: page + 1, // +1 because your API uses 1-based pages with_deleted: false, order_field: 'created_at', order_direction: 'DESC', filter: JSON.stringify(filter), } }); let temp = 1; let resBalance = balances.data.data.list.map((el: any) => { el.no = temp++; if (!el.agent_name) el.agent_name = '' return el; }); return { data: resBalance, totalCount: balances?.data.data.total_count } // setIsReloading(true); // try { // // setDataBalance(resBalance); // } catch (error: any) { // alert(error.message); // console.log(error); // } finally { // setIsReloading(false); // } } const openDialog = () => setIsDialogOpen(true); const closeDialog = () => { setIsDialogOpen(false); setFormData(initBalance); }; function createGroup() { setDialogType('create'); openDialog(); } const handleUpdate = async (data: any) => { await getQrCode(data.id); setFormData(data); setDialogType('update'); setIsDialogOpen(true); }; const handleReload = async () => { setIsReloading(true); await fetchAgentBalance(currentPage, pageSize, '',''); setIsReloading(false); // fetchAgentBalance(); }; async function getQrCode(customerId: any): Promise { try { setBarcode(``); let getToken = await axios.get(`${BASE_URL}/token/get`, { params: { id: customerId } }); console.log(getToken.data.data); setBarcode(getToken.data.data.qrCode); } catch (error: any) { toast.warning(error.message); console.log(error); } finally { // setBarcode(`https://miro.medium.com/v2/resize:fit:250/1*DcceOyLkzU--EzP4PYKd_g.png`) } } if (loading) return ; return ( <> TPAY | Agent Balance {/* setDialogOpen(false)} title="Confirm Action" content={''} onYes={handleYes} onNo={() => setDialogOpen(false)} /> */}

Agent Balances

Dashboard Members Agent Balances
{isReloading && ( )} {!isReloading && ( fetchAgentBalance(pageIndex, pageSize, sorting, columnFilters) } toolbar={ } onRowSelectionChange={(selected, table: any) => { const selectedRow = table.getSelectedRowModel().rows[0]; if (selectedRow) handleUpdate(selectedRow.original); }} /> )}
{/* */}
); }; // ==================== const PaymentCard = ({ barcode, agent_name, customerId }: any) => { const [token_legacy, setToken_legacy] = useState(''); const cardRef: any = useRef(null); const waitForImageLoad = (img: HTMLImageElement): Promise => { return new Promise((resolve) => { if (img.complete && img.naturalHeight !== 0) { resolve(); } else { toast.warning(`No QR Code`); img.onload = () => resolve(); } }); }; const handleDownload = async () => { if (!cardRef.current) return; const img = cardRef.current.querySelector('img'); if (img) { await waitForImageLoad(img); } else { return toast.warning(`No QR Code`); } const canvas = await html2canvas(cardRef.current, { useCORS: true, allowTaint: false, backgroundColor: 'white', scale: 2 }); const dataUrl = canvas.toDataURL('image/png'); const link = document.createElement('a'); link.href = dataUrl; link.download = `${agent_name}_barcode_card.png`; link.click(); }; const updateTokenLegacy = async () => { try { if (!token_legacy) toast.warning(`Token Legacy can not be empty`); await axios.post(`${BASE_URL}/token/insert-token-legacy`, { customerid: customerId, token_legacy }); toast.success(`Success Update Token Legacy`); } catch (error: any) { toast.error(error.message); } }; return (
Card Frame

{agent_name}

{barcode && (
Barcode
)}

Imprime husi : Telin Digital Solution

Imprime : 01–06–2025