feat(finance): refina fluxos de transacoes e pagadores

This commit is contained in:
Felipe Coutinho
2026-03-09 17:13:44 +00:00
parent 69da27276c
commit ada1377640
58 changed files with 1288 additions and 1559 deletions

View File

@@ -1,6 +1,14 @@
/**
* Formatting helpers for displaying lancamento data
*/
import {
currencyFormatter,
formatCurrency as formatCurrencyValue,
} from "@/lib/utils/currency";
import { formatDateOnly } from "@/lib/utils/date";
import { formatMonthYearLabel } from "@/lib/utils/period";
export { currencyFormatter };
/**
* Capitalizes the first letter of a string
@@ -11,14 +19,6 @@ function capitalize(value: string): string {
: value;
}
/**
* Currency formatter for pt-BR locale (BRL)
*/
export const currencyFormatter = new Intl.NumberFormat("pt-BR", {
style: "currency",
currency: "BRL",
});
/**
* Date formatter for pt-BR locale (dd/mm/yyyy)
*/
@@ -44,9 +44,13 @@ export const monthFormatter = new Intl.DateTimeFormat("pt-BR", {
*/
export function formatDate(value?: string | null): string {
if (!value) return "—";
const date = new Date(value);
if (Number.isNaN(date.getTime())) return "—";
return dateFormatter.format(date);
return (
formatDateOnly(value, {
day: "2-digit",
month: "2-digit",
year: "numeric",
}) ?? "—"
);
}
/**
@@ -57,10 +61,11 @@ export function formatDate(value?: string | null): string {
*/
export function formatPeriod(value?: string | null): string {
if (!value) return "—";
const [year, month] = value.split("-").map(Number);
if (!year || !month) return value;
const date = new Date(year, month - 1, 1);
return capitalize(monthFormatter.format(date));
try {
return formatMonthYearLabel(value);
} catch {
return value;
}
}
/**
@@ -97,5 +102,5 @@ export function getTransactionBadgeVariant(
* @example formatCurrency(1234.56) => "R$ 1.234,56"
*/
export function formatCurrency(value: number): string {
return currencyFormatter.format(value);
return formatCurrencyValue(value);
}

View File

@@ -19,6 +19,7 @@ import {
PAGADOR_ROLE_ADMIN,
PAGADOR_ROLE_TERCEIRO,
} from "@/lib/pagadores/constants";
import { toDateOnlyString } from "@/lib/utils/date";
type PagadorRow = typeof pagadores.$inferSelect;
type ContaRow = typeof contas.$inferSelect;
@@ -185,12 +186,10 @@ export const fetchLancamentoFilterSources = async (userId: string) => {
where: eq(pagadores.userId, userId),
}),
db.query.contas.findMany({
where: (contas, { eq, and }) =>
and(eq(contas.userId, userId), eq(contas.status, "Ativa")),
where: and(eq(contas.userId, userId), eq(contas.status, "Ativa")),
}),
db.query.cartoes.findMany({
where: (cartoes, { eq, and }) =>
and(eq(cartoes.userId, userId), eq(cartoes.status, "Ativo")),
where: and(eq(cartoes.userId, userId), eq(cartoes.status, "Ativo")),
}),
db.query.categorias.findMany({
where: eq(categorias.userId, userId),
@@ -405,7 +404,7 @@ export const mapLancamentosData = (rows: LancamentoRowWithRelations[]) =>
id: item.id,
userId: item.userId,
name: item.name,
purchaseDate: item.purchaseDate?.toISOString() ?? new Date().toISOString(),
purchaseDate: toDateOnlyString(item.purchaseDate) ?? "",
period: item.period ?? "",
transactionType: item.transactionType,
amount: Number(item.amount ?? 0),