mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-05-10 03:11:46 +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:
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
getCurrentDateString,
|
||||
type InvoiceDialogState,
|
||||
@@ -20,27 +21,62 @@ type InvoicesWidgetController = Omit<
|
||||
> & {
|
||||
selectedInvoice: DashboardInvoice | null;
|
||||
modalState: InvoiceDialogState;
|
||||
paymentAccountId: string;
|
||||
setPaymentAccountId: (accountId: string) => void;
|
||||
paymentDate: Date;
|
||||
setPaymentDate: (date: Date) => void;
|
||||
};
|
||||
|
||||
export function useInvoicesWidgetController(
|
||||
invoices: DashboardInvoice[],
|
||||
): InvoicesWidgetController {
|
||||
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: invoices,
|
||||
getItemId: (invoice) => invoice.id,
|
||||
isItemConfirmed: (invoice) => isInvoicePaid(invoice.paymentStatus),
|
||||
executeConfirm: (invoice) =>
|
||||
updateInvoicePaymentStatusAction({
|
||||
executeConfirm: (invoice) => {
|
||||
const accountId = paymentAccountIdRef.current || undefined;
|
||||
const date = paymentDateRef.current;
|
||||
const isoDate = date.toISOString().split("T")[0];
|
||||
|
||||
return updateInvoicePaymentStatusAction({
|
||||
cardId: invoice.cardId,
|
||||
period: invoice.period,
|
||||
status: INVOICE_PAYMENT_STATUS.PAID,
|
||||
}),
|
||||
paymentAccountId: accountId,
|
||||
paymentDate: isoDate,
|
||||
});
|
||||
},
|
||||
applyConfirmedState: (invoice) =>
|
||||
markInvoiceAsPaid(invoice, getCurrentDateString()),
|
||||
});
|
||||
|
||||
const selectedInvoiceId = controller.selectedItem?.id ?? null;
|
||||
const selectedDefaultAccountId =
|
||||
controller.selectedItem?.defaultPaymentAccountId ?? "";
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedInvoiceId) {
|
||||
return;
|
||||
}
|
||||
setPaymentAccountId(selectedDefaultAccountId);
|
||||
setPaymentDate(new Date());
|
||||
}, [selectedInvoiceId, selectedDefaultAccountId]);
|
||||
|
||||
return {
|
||||
...controller,
|
||||
selectedInvoice: controller.selectedItem,
|
||||
paymentAccountId,
|
||||
setPaymentAccountId,
|
||||
paymentDate,
|
||||
setPaymentDate,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user