import type { MetaFunction } from "@remix-run/node"; import { useState } from "react"; import { Link } from "@remix-run/react"; import { Loader2, Eye, EyeOff } from "lucide-react"; import { useAdminProducts, useAdminProductUpdate, } from "~/requestHandler/use-admin-hooks"; import type { AdminProductRow } from "~/requestHandler/use-admin-hooks"; import { AdminTable, AdminPagination, AdminToolbar, AdminSearch, AdminSelect, AdminPageTitle, StatusBadge, faToman, faDate, useDebouncedValue, type Column, } from "~/components/admin/DataTable"; export const meta: MetaFunction = () => [ { title: "محصولات | پنل مدیریت" }, { name: "robots", content: "noindex, nofollow" }, ]; const PAGE_SIZE = 25; export default function AdminProducts() { const [page, setPage] = useState(1); const [search, setSearch] = useState(""); const [active, setActive] = useState(""); const debouncedSearch = useDebouncedValue(search); const update = useAdminProductUpdate(); const { data, isLoading } = useAdminProducts({ page, page_size: PAGE_SIZE, search: debouncedSearch, is_active: active, }); const reset = (fn: () => void) => { fn(); setPage(1); }; const pendingId = update.isPending ? update.variables?.id : null; const actBtn = "inline-flex items-center gap-1 px-2 py-1 rounded-lg text-[12px] font-semibold transition-colors disabled:opacity-40 cursor-pointer"; const columns: Column[] = [ { header: "محصول", render: (p) => (
{p.primaryImage && ( )}

{p.title}

), }, { header: "فروشگاه", render: (p) => {p.sellerName || p.sellerUsername || "—"}, }, { header: "دسته", render: (p) => {p.categoryName || "—"}, }, { header: "قیمت", render: (p) => {faToman(p.basePrice)}, }, { header: "وضعیت", render: (p) => p.isActive ? ( ) : ( ), }, { header: "تاریخ", render: (p) => {faDate(p.createdAt)}, }, { header: "عملیات", className: "text-left", render: (p) => { const busy = pendingId === p.id; if (busy) return ; return (
{p.isActive ? ( ) : ( )}
); }, }, ]; return (
محصولات reset(() => setSearch(v))} placeholder="جستجوی عنوان یا فروشگاه…" /> reset(() => setActive(v))} options={[ { value: "", label: "همه" }, { value: "true", label: "فعال" }, { value: "false", label: "غیرفعال" }, ]} /> p.id} />
); }