/* global React, Icon, Eyebrow, Badge, Button, api */ const { useState: useStatePP, useEffect: useEffectPP } = React; function PayoutsPanel({ profile, onChanged }){ const [balance, setBalance] = useStatePP(null); const [payouts, setPayouts] = useStatePP([]); const [busy, setBusy] = useStatePP(false); const [errMsg, setErrMsg] = useStatePP(""); const [loading, setLoading] = useStatePP(true); const reload = async () => { const [b, p] = await Promise.all([api.getMyBalance(), api.listMyPayouts()]); setBalance(b.error ? null : b.data); setPayouts(p.error ? [] : p.data); setLoading(false); }; useEffectPP(() => { let mounted = true; (async () => { await reload(); if (!mounted) return; })(); return () => { mounted = false; }; }, []); const available = balance ? Number(balance.available_balance) : 0; const lifetimePaid = payouts.filter(p => p.status === "paid").reduce((s,p) => s + Number(p.amount||0), 0); const method = (profile && profile.payout_method) || null; const destination = method === "paypal" ? (profile && profile.paypal_email) : (profile && profile.bank_details && (profile.bank_details.summary || "Bank account on file")); const canRequest = available >= 20 && method && destination; const requestPayout = async () => { setErrMsg(""); if (!method || !destination) { setErrMsg("Set your payout method in Settings first."); return; } if (available < 20) { setErrMsg("Minimum cashout is $20."); return; } setBusy(true); const r = await api.requestPayout({ amount: Number(available.toFixed(2)), method, destination: typeof destination === "string" ? destination : JSON.stringify(destination) }); setBusy(false); if (r.error) { setErrMsg(r.error.message || "Request failed."); return; } await reload(); onChanged && onChanged(); }; if (loading) return
| {h} | ))}||||
|---|---|---|---|---|
| {new Date(date).toLocaleDateString(undefined, {month:"short",day:"numeric",year:"numeric"})} | ${Number(p.amount).toFixed(2)} | {p.method === "paypal" ? "PayPal" : "Bank"} | {p.txn_ref || "—"} |