- Adicionar indexes compostos em lancamentos para queries frequentes - Eliminar ~20 JOINs com pagadores via helper cacheado getAdminPagadorId() - Consolidar queries: income-expense-balance (12→1), payment-status (2→1), categories (4→2) - Adicionar cache cross-request via unstable_cache com tag-based invalidation - Limitar scan de métricas a 24 meses - Deduplicar auth session por request via React.cache() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
"use client";
|
|
|
|
import { useMemo } from "react";
|
|
import type {
|
|
CategoryReportData,
|
|
CategoryReportItem,
|
|
} from "@/lib/relatorios/types";
|
|
import { CategoryTable } from "./category-table";
|
|
|
|
interface CategoryReportTableProps {
|
|
data: CategoryReportData;
|
|
}
|
|
|
|
export function CategoryReportTable({ data }: CategoryReportTableProps) {
|
|
const { categories, periods } = data;
|
|
|
|
// Separate categories by type
|
|
const { receitas, despesas } = useMemo(() => {
|
|
const receitas: CategoryReportItem[] = [];
|
|
const despesas: CategoryReportItem[] = [];
|
|
|
|
for (const category of categories) {
|
|
if (category.type === "receita") {
|
|
receitas.push(category);
|
|
} else {
|
|
despesas.push(category);
|
|
}
|
|
}
|
|
|
|
return { receitas, despesas };
|
|
}, [categories]);
|
|
|
|
return (
|
|
<div className="flex flex-col gap-6">
|
|
{/* Despesas Table */}
|
|
<CategoryTable
|
|
title="Despesas"
|
|
categories={despesas}
|
|
periods={periods}
|
|
colorIndexOffset={0}
|
|
/>
|
|
|
|
{/* Receitas Table */}
|
|
<CategoryTable
|
|
title="Receitas"
|
|
categories={receitas}
|
|
periods={periods}
|
|
colorIndexOffset={despesas.length}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|