Files
SeConectai_Vendas/frontend/lib/format.ts
T
tiagoandClaude Sonnet 5 323912748f Frontend completo (Etapas 11-18) e extensões de backend (Etapas 13 e 18)
Adiciona o frontend Next.js em frontend/ (setup, design system,
autenticação/tema, layout/navegação, área master, área tenant completa:
clientes, produtos, vendas, recebimentos, whatsapp, e-mail, alertas,
equipe e perfil). Estende o backend de forma aditiva e autorizada:
cookie httpOnly para refresh token (Etapa 13) e CRUD de equipe +
edição de perfil do tenant (Etapa 18, módulo src/modules/equipe/ novo
e PUT /tenant/perfil). Detalhes completos em Etapas/V2/*.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-16 09:41:13 -03:00

32 lines
1.3 KiB
TypeScript

/** Formatação compartilhada (moeda/data pt-BR) — Etapa 15 em diante. */
const currencyFormatter = new Intl.NumberFormat('pt-BR', {
style: 'currency',
currency: 'BRL',
});
const dateFormatter = new Intl.DateTimeFormat('pt-BR', { dateStyle: 'short' });
const dateTimeFormatter = new Intl.DateTimeFormat('pt-BR', { dateStyle: 'short', timeStyle: 'short' });
/** Aceita `string`/`number` (a API devolve `Decimal` do Prisma como string). */
export function formatCurrency(value: string | number | null | undefined): string {
if (value === null || value === undefined) return '—';
const numeric = typeof value === 'string' ? Number(value) : value;
if (Number.isNaN(numeric)) return '—';
return currencyFormatter.format(numeric);
}
export function formatDate(value: string | Date | null | undefined): string {
if (!value) return '—';
const date = typeof value === 'string' ? new Date(value) : value;
if (Number.isNaN(date.getTime())) return '—';
return dateFormatter.format(date);
}
export function formatDateTime(value: string | Date | null | undefined): string {
if (!value) return '—';
const date = typeof value === 'string' ? new Date(value) : value;
if (Number.isNaN(date.getTime())) return '—';
return dateTimeFormatter.format(date);
}