mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-05-09 11:01:45 +00:00
refactor(dashboard): reorganizar módulos em subdiretórios e nova arquitetura de widgets
Arquivos de queries, helpers e controllers dispersos na raiz de dashboard/ foram movidos para subdiretórios temáticos (bills/, invoices/, notes/, notifications/, overview/, payments/, goals-progress/, categories/). ~25 widgets monolíticos obsoletos removidos em favor de nova arquitetura baseada em widget-registry com components/widgets/. Novos componentes: category-breakdown-chart/list, goals-progress-item, percentage-change-indicator. Imports atualizados em fetch-dashboard-data e transaction-filters limpos. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
62
src/features/dashboard/bills/bills-helpers.ts
Normal file
62
src/features/dashboard/bills/bills-helpers.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import type { DashboardBill } from "@/features/dashboard/bills/bills-queries";
|
||||
import type { PaymentDialogState } from "@/features/dashboard/payments/use-payment-dialog-controller";
|
||||
import { getBusinessDateString, isDateOnlyPast } from "@/shared/utils/date";
|
||||
import {
|
||||
buildFinancialStatusLabel,
|
||||
buildRelativeFinancialStatusLabel,
|
||||
formatFinancialDateLabel,
|
||||
} from "@/shared/utils/financial-dates";
|
||||
|
||||
export type BillDialogState = PaymentDialogState;
|
||||
export type BillStatusDateItem = Pick<
|
||||
DashboardBill,
|
||||
"dueDate" | "boletoPaymentDate" | "isSettled"
|
||||
>;
|
||||
|
||||
export const formatBillDateLabel = (value: string | null, prefix?: string) => {
|
||||
return formatFinancialDateLabel(value, prefix);
|
||||
};
|
||||
|
||||
export const buildBillStatusLabel = (bill: BillStatusDateItem) => {
|
||||
return buildFinancialStatusLabel({
|
||||
isSettled: bill.isSettled,
|
||||
dueDate: bill.dueDate,
|
||||
paidAt: bill.boletoPaymentDate,
|
||||
});
|
||||
};
|
||||
|
||||
export const buildBillWidgetStatusLabel = (bill: BillStatusDateItem) => {
|
||||
return buildRelativeFinancialStatusLabel({
|
||||
isSettled: bill.isSettled,
|
||||
dueDate: bill.dueDate,
|
||||
paidAt: bill.boletoPaymentDate,
|
||||
});
|
||||
};
|
||||
|
||||
export const getCurrentBillDateString = () => getBusinessDateString();
|
||||
|
||||
export const isBillOverdue = (bill: DashboardBill) => {
|
||||
if (bill.isSettled || !bill.dueDate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return isDateOnlyPast(bill.dueDate);
|
||||
};
|
||||
|
||||
export const getBillStatusBadgeVariant = (
|
||||
statusLabel: string,
|
||||
): "success" | "info" => {
|
||||
if (statusLabel.toLowerCase() === "pendente") {
|
||||
return "info";
|
||||
}
|
||||
return "success";
|
||||
};
|
||||
|
||||
export const markBillAsSettled = (
|
||||
bill: DashboardBill,
|
||||
boletoPaymentDate: string,
|
||||
): DashboardBill => ({
|
||||
...bill,
|
||||
isSettled: true,
|
||||
boletoPaymentDate,
|
||||
});
|
||||
14
src/features/dashboard/bills/bills-queries.ts
Normal file
14
src/features/dashboard/bills/bills-queries.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export type DashboardBill = {
|
||||
id: string;
|
||||
name: string;
|
||||
amount: number;
|
||||
dueDate: string | null;
|
||||
boletoPaymentDate: string | null;
|
||||
isSettled: boolean;
|
||||
};
|
||||
|
||||
export type DashboardBillsSnapshot = {
|
||||
bills: DashboardBill[];
|
||||
totalPendingAmount: number;
|
||||
pendingCount: number;
|
||||
};
|
||||
46
src/features/dashboard/bills/use-bill-widget-controller.ts
Normal file
46
src/features/dashboard/bills/use-bill-widget-controller.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
type BillDialogState,
|
||||
getCurrentBillDateString,
|
||||
markBillAsSettled,
|
||||
} from "@/features/dashboard/bills/bills-helpers";
|
||||
import type { DashboardBill } from "@/features/dashboard/bills/bills-queries";
|
||||
import {
|
||||
type PaymentDialogController,
|
||||
usePaymentDialogController,
|
||||
} from "@/features/dashboard/payments/use-payment-dialog-controller";
|
||||
import { toggleTransactionSettlementAction } from "@/features/transactions/actions";
|
||||
|
||||
const EMPTY_BILLS: DashboardBill[] = [];
|
||||
|
||||
type BillWidgetController = Omit<
|
||||
PaymentDialogController<DashboardBill>,
|
||||
"selectedItem"
|
||||
> & {
|
||||
selectedBill: DashboardBill | null;
|
||||
modalState: BillDialogState;
|
||||
};
|
||||
|
||||
export function useBillWidgetController(
|
||||
bills?: DashboardBill[],
|
||||
): BillWidgetController {
|
||||
const safeBills = bills ?? EMPTY_BILLS;
|
||||
const controller = usePaymentDialogController({
|
||||
items: safeBills,
|
||||
getItemId: (bill) => bill.id,
|
||||
isItemConfirmed: (bill) => bill.isSettled,
|
||||
executeConfirm: (bill) =>
|
||||
toggleTransactionSettlementAction({
|
||||
id: bill.id,
|
||||
value: true,
|
||||
}),
|
||||
applyConfirmedState: (bill) =>
|
||||
markBillAsSettled(bill, getCurrentBillDateString()),
|
||||
});
|
||||
|
||||
return {
|
||||
...controller,
|
||||
selectedBill: controller.selectedItem,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user