import { useState } from 'react'; import { Table, Input, Select, Space, Typography, Tag } from 'antd'; import type { TableColumnsType } from 'antd'; import type { ProdutoSummary } from '@sar/api-interface'; import { useCatalog, usePautas } from '../../lib/queries/catalog'; const { Title } = Typography; const { Search } = Input; function fmtPrice(v: string | null | undefined): string { const n = Number(v ?? 0); return n > 0 ? n.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }) : '—'; } const columns: TableColumnsType = [ { title: 'Código', dataIndex: 'codigo', width: 110, render: (v: string) => {v.trim()}, }, { title: 'Descrição', dataIndex: 'descricao', render: (v: string, row: ProdutoSummary) => (
{v.trim()}
{row.grupo &&
{row.grupo.trim()}
}
), }, { title: 'Und', dataIndex: 'unidade', width: 60, align: 'center', render: (v: string | null) => v ?? '—', }, { title: 'Marca', dataIndex: 'marca', width: 130, render: (v: string | null) => (v ? {v.trim()} : null), }, { title: 'Preço', dataIndex: 'vlPreco1', width: 120, align: 'right', render: (v: string) => ( 0 ? '#389e0d' : '#999' }}> {fmtPrice(v)} ), }, { title: 'Estoque', dataIndex: 'qtdEstoque', width: 90, align: 'right', render: (v: string | null) => { if (v == null) return '—'; const n = Number(v); return ( 0 ? 'inherit' : '#f5222d' }}>{n.toLocaleString('pt-BR')} ); }, }, ]; export function CatalogPage() { const [q, setQ] = useState(''); const [idPauta, setIdPauta] = useState(); const [page, setPage] = useState(1); const limit = 50; const { data: pautas, isLoading: pautasLoading } = usePautas(); const { data, isLoading } = useCatalog({ q: q || undefined, idPauta, page, limit }); return (
Catálogo de Produtos { setQ(v); setPage(1); }} onChange={(e) => { if (!e.target.value) { setQ(''); setPage(1); } }} />