feat(web): clientes e catálogo funcionando com dados do ERP

- clients.ts, catalog.ts: corrige bug res.ok/res.json() — apiFetch retorna JSON direto
- catalog.service.ts: corrige nomes de coluna da vw_produtos (descr_det, lista_pauta,
  remove preco_com_ipi inexistente)
- CatalogPage.tsx: nova tela — código, descrição, grupo, marca, preço, estoque
- router.tsx: adiciona rota /catalogo

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-29 14:46:25 +00:00
parent 24408ecd83
commit 1f8a9d872a
5 changed files with 148 additions and 20 deletions

View File

@@ -1,8 +1,10 @@
import { useQuery } from '@tanstack/react-query';
import {
ProdutoListResponseSchema,
ProdutoDetailSchema,
type ProdutoListQuery,
type ProdutoListResponse,
type ProdutoDetail,
} from '@sar/api-interface';
import { apiFetch } from '../api-client';
@@ -18,9 +20,19 @@ export function useCatalog(params: Partial<ProdutoListQuery> = {}) {
queryKey: ['catalog', params],
queryFn: async () => {
const res = await apiFetch(`/catalog${qs ? `?${qs}` : ''}`);
if (!res.ok) throw new Error(`catalog error ${res.status}`);
return ProdutoListResponseSchema.parse(await res.json());
return ProdutoListResponseSchema.parse(res);
},
staleTime: 4 * 60 * 60 * 1000,
});
}
export function useProdutoDetail(id: number | undefined) {
return useQuery<ProdutoDetail>({
queryKey: ['catalog', id],
enabled: id != null,
queryFn: async () => {
const res = await apiFetch(`/catalog/${id}`);
return ProdutoDetailSchema.parse(res);
},
staleTime: 4 * 60 * 60 * 1000, // TTL 4h — FR-4.4
});
}