mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-06-10 07:16:01 +00:00
Refatoração estrutural sem mudanças funcionais. Saldo líquido: −428 linhas. Removido: - 14 funções/constantes mortas verificadas via grep no repo todo: validateCategoriaOwnership, getInstallmentAnticipationsAction, getAnticipationDetailsAction, formatDecimalForDb, currencyFormatterNoCents, optionalDecimalSchema, formatMonthLabel, getGoalProgressStatusColorClass, MONTH_PERIOD_PARAM, calculateRemainingInstallments, e 5 funções fetch* não usadas em inbox/queries.ts. - 1 tipo morto (ImportRow) + 2 órfãos consequentes (InstallmentAnticipationWithRelations, GoalProgressStatus convertido em interno). - ~30 export keywords desnecessários (símbolos usados apenas no próprio arquivo). - Re-exports mortos em barrels: EstablishmentLogoPicker, CategoryReportSkeleton, WidgetSkeleton, toNameKey. - Arquivo features/reports/types.ts (barrel inteiro era órfão). Padronizado (PT-BR→EN em identificadores expostos): - 4 constantes globais (LANCAMENTOS_* → TRANSACTIONS_*). - 12 tipos/interfaces (Lancamento*/Pagador*/Estabelecimento* → equivalentes EN). - 13 funções/components exportados (fetchPagador*, EstabelecimentoInput, PagadorInfoCard, etc.). - 5 props cross-file (preLancamentosCount → inboxPendingCount, pagadorAvatarUrl → payerAvatarUrl, etc.). - Mantidas em PT-BR conforme exceção do CLAUDE.md: variáveis locais (pagador, categoria, lancamento), accessor key pagadorName (persistida em preferências), strings de UI. Reorganizado: - transactions/: 14 helpers soltos na raiz movidos para lib/; barrel actions.ts reduzido de 76 linhas de wrappers para 14 linhas de re-exports puros; anticipation-actions.ts movido para actions/anticipation.ts. - dashboard/: 8 helpers soltos consolidados em dashboard/lib/. - reports/: 5 query files na raiz consolidados em reports/lib/. - payers/: detail-actions.ts (21KB) e detail-queries.ts movidos para payers/lib/. - shared/components/: 9 dos 16 componentes soltos agrupados em brand/, widgets/, feedback/. - shared/lib/fetch-json.ts movido para shared/utils/fetch-json.ts. Validação: pnpm exec tsc --noEmit (0 erros), biome check (0 issues), knip (sem unused). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
125 lines
3.0 KiB
TypeScript
125 lines
3.0 KiB
TypeScript
import type { CSSProperties } from "react";
|
|
import MoneyValues from "@/shared/components/money-values";
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
CardHeader,
|
|
CardTitle,
|
|
} from "@/shared/components/ui/card";
|
|
import type { PayerMonthlyBreakdown } from "@/shared/lib/payers/details";
|
|
import { cn } from "@/shared/utils/ui";
|
|
|
|
const segmentConfig = {
|
|
card: {
|
|
label: "Cartões",
|
|
color: "bg-violet-500",
|
|
},
|
|
boleto: {
|
|
label: "Boletos",
|
|
color: "bg-amber-500",
|
|
},
|
|
instant: {
|
|
label: "Pix/Débito/Dinheiro",
|
|
color: "bg-emerald-500",
|
|
},
|
|
} as const;
|
|
|
|
type PayerMonthlySummaryCardProps = {
|
|
periodLabel: string;
|
|
breakdown: PayerMonthlyBreakdown;
|
|
};
|
|
|
|
export function PayerMonthlySummaryCard({
|
|
periodLabel,
|
|
breakdown,
|
|
}: PayerMonthlySummaryCardProps) {
|
|
const splittableEntries = (
|
|
Object.keys(segmentConfig) as Array<keyof typeof segmentConfig>
|
|
).map((key) => ({
|
|
key,
|
|
...segmentConfig[key],
|
|
value: breakdown.paymentSplits[key],
|
|
}));
|
|
|
|
const totalBase = splittableEntries.reduce(
|
|
(sum, entry) => sum + entry.value,
|
|
0,
|
|
);
|
|
|
|
let offset = 0;
|
|
|
|
return (
|
|
<Card>
|
|
<CardHeader className="flex flex-col gap-1.5">
|
|
<CardTitle className="text-lg font-semibold">Totais do mês</CardTitle>
|
|
<p className="text-xs text-muted-foreground">
|
|
{periodLabel} - Despesas por forma de pagamento
|
|
</p>
|
|
</CardHeader>
|
|
|
|
<CardContent className="space-y-4 pt-0">
|
|
<div className="space-y-2">
|
|
<div>
|
|
<span className="text-xs tracking-wide text-muted-foreground">
|
|
Total
|
|
</span>
|
|
<MoneyValues
|
|
amount={breakdown.totalExpenses}
|
|
className="block text-2xl font-semibold text-foreground"
|
|
/>
|
|
</div>
|
|
|
|
<div className="relative h-1.5 w-full overflow-hidden rounded-full bg-muted">
|
|
{splittableEntries.map((entry) => {
|
|
const percent =
|
|
totalBase > 0
|
|
? Math.max((entry.value / totalBase) * 100, 0)
|
|
: 0;
|
|
const style: CSSProperties = {
|
|
width: `${percent}%`,
|
|
left: `${offset}%`,
|
|
};
|
|
offset += percent;
|
|
return (
|
|
<span
|
|
key={entry.key}
|
|
className={cn(
|
|
"absolute inset-y-0 rounded-full transition-all",
|
|
entry.color,
|
|
)}
|
|
style={style}
|
|
/>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="grid gap-3 sm:grid-cols-3">
|
|
{splittableEntries.map((entry) => {
|
|
const percent =
|
|
totalBase > 0 ? Math.round((entry.value / totalBase) * 100) : 0;
|
|
return (
|
|
<div key={entry.key} className="space-y-1 rounded-lg border p-3">
|
|
<span className="flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground/70">
|
|
<span
|
|
className={cn("size-2 rounded-full", entry.color)}
|
|
aria-hidden
|
|
/>
|
|
{entry.label}
|
|
</span>
|
|
<MoneyValues
|
|
amount={entry.value}
|
|
className="block text-lg font-semibold text-foreground"
|
|
/>
|
|
<span className="text-xs text-muted-foreground">
|
|
{percent}% das despesas
|
|
</span>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
}
|