mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-05-09 11:01:45 +00:00
feat(dashboard): confirmação de pagamento com conta e data para faturas e boletos
- widget de faturas abre modal com seleção de conta de origem e data antes de pagar - widget de boletos ganha a mesma paridade: modal com conta de pagamento e data - toggleTransactionSettlementAction aceita paymentAccountId e paymentDate opcionais - DashboardBill expõe accountId para inicializar o modal com a conta já vinculada Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,13 @@ export type DashboardBill = {
|
||||
dueDate: string | null;
|
||||
boletoPaymentDate: string | null;
|
||||
isSettled: boolean;
|
||||
accountId: string | null;
|
||||
};
|
||||
|
||||
export type BillPaymentAccountOption = {
|
||||
value: string;
|
||||
label: string;
|
||||
logo: string | null;
|
||||
};
|
||||
|
||||
export type DashboardBillsSnapshot = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
type BillDialogState,
|
||||
getCurrentBillDateString,
|
||||
@@ -20,12 +21,26 @@ type BillWidgetController = Omit<
|
||||
> & {
|
||||
selectedBill: DashboardBill | null;
|
||||
modalState: BillDialogState;
|
||||
paymentAccountId: string;
|
||||
setPaymentAccountId: (accountId: string) => void;
|
||||
paymentDate: Date;
|
||||
setPaymentDate: (date: Date) => void;
|
||||
};
|
||||
|
||||
const toIsoDate = (date: Date) => date.toISOString().split("T")[0] ?? "";
|
||||
|
||||
export function useBillWidgetController(
|
||||
bills?: DashboardBill[],
|
||||
): BillWidgetController {
|
||||
const safeBills = bills ?? EMPTY_BILLS;
|
||||
const [paymentAccountId, setPaymentAccountId] = useState<string>("");
|
||||
const [paymentDate, setPaymentDate] = useState<Date>(() => new Date());
|
||||
|
||||
const paymentAccountIdRef = useRef(paymentAccountId);
|
||||
const paymentDateRef = useRef(paymentDate);
|
||||
paymentAccountIdRef.current = paymentAccountId;
|
||||
paymentDateRef.current = paymentDate;
|
||||
|
||||
const controller = usePaymentDialogController({
|
||||
items: safeBills,
|
||||
getItemId: (bill) => bill.id,
|
||||
@@ -34,13 +49,36 @@ export function useBillWidgetController(
|
||||
toggleTransactionSettlementAction({
|
||||
id: bill.id,
|
||||
value: true,
|
||||
paymentAccountId: paymentAccountIdRef.current || null,
|
||||
paymentDate: toIsoDate(paymentDateRef.current),
|
||||
}),
|
||||
applyConfirmedState: (bill) =>
|
||||
markBillAsSettled(bill, getCurrentBillDateString()),
|
||||
markBillAsSettled(
|
||||
{
|
||||
...bill,
|
||||
accountId: paymentAccountIdRef.current || bill.accountId,
|
||||
},
|
||||
toIsoDate(paymentDateRef.current) || getCurrentBillDateString(),
|
||||
),
|
||||
});
|
||||
|
||||
const selectedBillId = controller.selectedItem?.id ?? null;
|
||||
const selectedBillAccountId = controller.selectedItem?.accountId ?? "";
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedBillId) {
|
||||
return;
|
||||
}
|
||||
setPaymentAccountId(selectedBillAccountId ?? "");
|
||||
setPaymentDate(new Date());
|
||||
}, [selectedBillId, selectedBillAccountId]);
|
||||
|
||||
return {
|
||||
...controller,
|
||||
selectedBill: controller.selectedItem,
|
||||
paymentAccountId,
|
||||
setPaymentAccountId,
|
||||
paymentDate,
|
||||
setPaymentDate,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user