'use client'; import { useState, useEffect } from 'react'; import { ArrowLeftRight, Check, X, RefreshCw, Search } from 'lucide-react'; import { apiFetch } from '@/services/api/client'; import { toast } from 'sonner'; import { TablePagination, useClientPagination } from '@/components/ui/TablePagination'; import { formatCurrency } from '@/lib/utils'; import { format } from 'date-fns'; export default function RefundsPage() { const [refunds, setRefunds] = useState([]); const [loading, setLoading] = useState(true); const [searchQuery, setSearchQuery] = useState(''); const loadRefunds = async () => { setLoading(true); try { const data = await apiFetch('/api/v1/refunds'); setRefunds(data); } catch (err: any) { toast.error(err.message || 'Failed to load refunds'); } finally { setLoading(false); } }; useEffect(() => { loadRefunds(); }, []); const handleAction = async (refundId: string, action: 'APPROVE' | 'REJECT') => { try { const payload = action === 'APPROVE' ? { admin_notes: "Approved from UI" } : { rejection_reason: "Rejected from UI" }; await apiFetch(`/api/v1/refunds/${refundId}/${action.toLowerCase()}`, { method: 'POST', body: JSON.stringify(payload) }); toast.success(`Refund ${action === 'APPROVE' ? 'Approved' : 'Rejected'}!`); loadRefunds(); } catch (err: any) { toast.error(err.message || `Failed to ${action.toLowerCase()} refund`); } }; const filteredRefunds = refunds.filter((r) => JSON.stringify(r).toLowerCase().includes(searchQuery.toLowerCase()) ); const pager = useClientPagination(filteredRefunds, 10); return (

Refunds & Returns Management

Manage return requests, verify part numbers, and process refunds

setSearchQuery(e.target.value)} className="w-full pl-9 pr-4 h-9 crm-radius-control border border-border bg-card text-[13px] focus:outline-none focus:border-primary" />
{loading ? (
) : ( {pager.items.length === 0 ? ( ) : ( pager.items.map((r) => ( )) )}
Request ID Entity Part No. Verif. Amount Reason Status Action
No refund requests found.
{r.refund_id.slice(-8).toUpperCase()} {r.entity_type === 'ECOM_ORDER' ? 'Order' : 'Service'}
{r.entity_id}
{r.part_number_verification || '—'} {formatCurrency(r.amount)} {r.reason} {r.status} {r.status === 'PENDING' && (
)}
)}
); }