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 { Input } from '@/components/ui/input'; import { DialogContent, MenuItem, Radio, RadioGroup, FormControlLabel, FormControl, Dialog, DialogTitle, Typography, Button, Box, Breadcrumbs, Link } from '@mui/material'; import { useState, useEffect, useRef } from 'react'; import CloseIcon from '@mui/icons-material/Close'; import Divider from '@mui/material/Divider'; import ConfirmDialog from '@/components/confirm'; import { toast } from 'sonner'; import { Container, DataGridLoader, DataGridProvider, LoaderTransparant } from '@/components'; import { ListToolBar } from './ListToolbar'; import { RefreshCw } from 'lucide-react'; import { setgroups } from 'process'; 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 [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(); }, []); async function fetchAgentBalance(): Promise { setIsReloading(true); try { let balances = await axios.get(`${BASE_URL}/customer/agent-balance`, { params: { limit: 20, page: 1, with_deleted: false, order_field: 'created_at', order_direction: 'DESC' } }); let temp = 1; let resBalance = balances.data.data.list.map((el: any) => { el.no = temp++; if (!el.agent_name) el.agent_name = '' return el; }); 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 = () => { setIsReloading(true); 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 && ( )} } layout={{ card: true }} serverSide={false} 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 content to render */}

{agent_name}

{barcode && ( Barcode )}