import { useState } from "react"; import { useLedgerTransactions, type LedgerTransactionRow, } from "~/requestHandler/use-admin-hooks"; import { AdminTable, AdminPagination, AdminToolbar, AdminSearch, AdminSelect, StatusBadge, faToman, faDate, useDebouncedValue, type Column, } from "~/components/admin/DataTable"; const PAGE_SIZE = 25; const TYPE: Record = { deposit: { label: "واریز", tone: "green" }, purchase: { label: "خرید", tone: "blue" }, }; export default function LedgerTransactions() { const [page, setPage] = useState(1); const [search, setSearch] = useState(""); const [type, setType] = useState(""); const debouncedSearch = useDebouncedValue(search); const { data, isLoading } = useLedgerTransactions({ page, page_size: PAGE_SIZE, search: debouncedSearch, transaction_type: type, }); const reset = (fn: () => void) => { fn(); setPage(1); }; const columns: Column[] = [ { header: "نوع", render: (t) => { const ty = TYPE[t.transactionType] || { label: t.transactionType, tone: "blue" as const }; return ; }, }, { header: "مبلغ", render: (t) => {faToman(t.amount)}, }, { header: "کاربر", render: (t) => ( {t.userPhone || "—"} ), }, { header: "سفارش", render: (t) => ( {t.order ? t.order.slice(0, 8) : "—"} ), }, { header: "تاریخ", render: (t) => {faDate(t.createdAt)}, }, ]; return (
reset(() => setSearch(v))} placeholder="جستجوی تلفن کاربر…" /> reset(() => setType(v))} options={[ { value: "", label: "همه انواع" }, { value: "deposit", label: "واریز" }, { value: "purchase", label: "خرید" }, ]} /> t.id} />
); }