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,4 @@
|
||||
import {
|
||||
RiBankCardLine,
|
||||
RiCalendarLine,
|
||||
RiLoader4Line,
|
||||
RiMoneyDollarCircleLine,
|
||||
@@ -10,11 +9,17 @@ import {
|
||||
type InvoiceDialogState,
|
||||
parseInvoiceDueDate,
|
||||
} from "@/features/dashboard/invoices/invoices-helpers";
|
||||
import type { DashboardInvoice } from "@/features/dashboard/invoices/invoices-queries";
|
||||
import type {
|
||||
DashboardInvoice,
|
||||
InvoicePaymentAccountOption,
|
||||
} from "@/features/dashboard/invoices/invoices-queries";
|
||||
import { AccountCardSelectContent } from "@/features/transactions/components/select-items";
|
||||
import MoneyValues from "@/shared/components/money-values";
|
||||
import { PaymentSuccess } from "@/shared/components/payment-success";
|
||||
import { Badge } from "@/shared/components/ui/badge";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import { Card } from "@/shared/components/ui/card";
|
||||
import { DatePicker } from "@/shared/components/ui/date-picker";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -23,6 +28,15 @@ import {
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/shared/components/ui/dialog";
|
||||
import { Label } from "@/shared/components/ui/label";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/shared/components/ui/select";
|
||||
import { Separator } from "@/shared/components/ui/separator";
|
||||
import {
|
||||
INVOICE_PAYMENT_STATUS,
|
||||
INVOICE_STATUS_LABEL,
|
||||
@@ -34,6 +48,11 @@ type InvoicePaymentDialogProps = {
|
||||
open: boolean;
|
||||
modalState: InvoiceDialogState;
|
||||
isPending: boolean;
|
||||
paymentAccountId: string;
|
||||
onPaymentAccountChange: (accountId: string) => void;
|
||||
paymentDate: Date;
|
||||
onPaymentDateChange: (date: Date) => void;
|
||||
paymentAccountOptions: InvoicePaymentAccountOption[];
|
||||
onClose: () => void;
|
||||
onConfirm: () => void;
|
||||
};
|
||||
@@ -43,6 +62,11 @@ export function InvoicePaymentDialog({
|
||||
open,
|
||||
modalState,
|
||||
isPending,
|
||||
paymentAccountId,
|
||||
onPaymentAccountChange,
|
||||
paymentDate,
|
||||
onPaymentDateChange,
|
||||
paymentAccountOptions,
|
||||
onClose,
|
||||
onConfirm,
|
||||
}: InvoicePaymentDialogProps) {
|
||||
@@ -51,6 +75,12 @@ export function InvoicePaymentDialog({
|
||||
const dueInfo = invoice
|
||||
? parseInvoiceDueDate(invoice.period, invoice.dueDay)
|
||||
: null;
|
||||
const isInvoicePending =
|
||||
invoice?.paymentStatus === INVOICE_PAYMENT_STATUS.PENDING;
|
||||
const paymentDateValue = paymentDate.toISOString().split("T")[0] ?? "";
|
||||
const selectedAccount = paymentAccountOptions.find(
|
||||
(option) => option.value === paymentAccountId,
|
||||
);
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
@@ -85,13 +115,12 @@ export function InvoicePaymentDialog({
|
||||
<>
|
||||
<DialogHeader>
|
||||
<div className="mb-1 flex items-center gap-3">
|
||||
<div className="flex size-10 items-center justify-center rounded-full bg-primary/10">
|
||||
<RiBankCardLine className="size-5 text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<DialogTitle>Confirmar pagamento</DialogTitle>
|
||||
<DialogDescription className="mt-0.5 text-xs">
|
||||
Fatura do cartão
|
||||
<DialogDescription className="mt-1 text-xs">
|
||||
{isInvoicePending
|
||||
? "Escolha a conta de origem e a data em que a fatura foi paga."
|
||||
: "Fatura do cartão"}
|
||||
</DialogDescription>
|
||||
</div>
|
||||
</div>
|
||||
@@ -99,8 +128,7 @@ export function InvoicePaymentDialog({
|
||||
|
||||
{invoice ? (
|
||||
<div className="space-y-3">
|
||||
{/* Card principal */}
|
||||
<div className="flex items-center gap-3 rounded-xl border p-4">
|
||||
<Card className="flex flex-row items-start gap-2 p-4">
|
||||
<InvoiceLogo
|
||||
cardName={invoice.cardName}
|
||||
logo={invoice.logo}
|
||||
@@ -110,66 +138,119 @@ export function InvoicePaymentDialog({
|
||||
fallbackClassName="text-xs"
|
||||
/>
|
||||
<div className="min-w-0">
|
||||
<p className="text-xs font-medium text-muted-foreground uppercase tracking-wide">
|
||||
<p className="text-xs font-medium text-muted-foreground uppercase">
|
||||
Cartão
|
||||
</p>
|
||||
<p className="truncate text-base font-semibold text-foreground">
|
||||
{invoice.cardName}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* Métricas */}
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="rounded-xl border p-3">
|
||||
<div className="mb-1.5 flex items-center gap-1.5 text-muted-foreground">
|
||||
<Card className="p-3">
|
||||
<div className="flex items-center gap-1.5 text-muted-foreground">
|
||||
<RiMoneyDollarCircleLine className="size-3.5" />
|
||||
<span className="text-xs font-medium uppercase tracking-wide">
|
||||
<span className="text-xs font-medium uppercase">
|
||||
Total da fatura
|
||||
</span>
|
||||
</div>
|
||||
<MoneyValues
|
||||
amount={Math.abs(invoice.totalAmount)}
|
||||
className="text-lg font-semibold"
|
||||
className="text-xl font-semibold"
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<div className="rounded-xl border p-3">
|
||||
<div className="mb-1.5 flex items-center gap-1.5 text-muted-foreground">
|
||||
<Card className="p-3">
|
||||
<div className="flex items-center gap-1.5 text-muted-foreground">
|
||||
<RiCalendarLine className="size-3.5" />
|
||||
<span className="text-xs font-medium uppercase tracking-wide">
|
||||
<span className="text-xs font-medium uppercase">
|
||||
{invoice.paymentStatus === INVOICE_PAYMENT_STATUS.PAID
|
||||
? "Pago em"
|
||||
: "Vencimento"}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
<div className="font-semibold">
|
||||
{invoice.paymentStatus === INVOICE_PAYMENT_STATUS.PAID
|
||||
? (paymentInfo?.label ?? "—")
|
||||
: (dueInfo?.label ?? "—")}
|
||||
</p>
|
||||
? (paymentInfo?.label?.replace(/^Pago em\s*/u, "") ??
|
||||
"—")
|
||||
: (dueInfo?.label?.replace(/^Vence (em|dia)\s*/u, "") ??
|
||||
"—")}
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<Separator />
|
||||
|
||||
{isInvoicePending ? (
|
||||
<div className="space-y-3">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="invoice-widget-payment-account">
|
||||
Conta de pagamento
|
||||
</Label>
|
||||
<Select
|
||||
value={paymentAccountId}
|
||||
onValueChange={onPaymentAccountChange}
|
||||
disabled={
|
||||
isProcessing || paymentAccountOptions.length === 0
|
||||
}
|
||||
>
|
||||
<SelectTrigger
|
||||
id="invoice-widget-payment-account"
|
||||
className="w-full"
|
||||
>
|
||||
<SelectValue placeholder="Selecione uma conta">
|
||||
{selectedAccount ? (
|
||||
<AccountCardSelectContent
|
||||
label={selectedAccount.label}
|
||||
logo={selectedAccount.logo}
|
||||
/>
|
||||
) : null}
|
||||
</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{paymentAccountOptions.map((option) => (
|
||||
<SelectItem key={option.value} value={option.value}>
|
||||
<AccountCardSelectContent
|
||||
label={option.label}
|
||||
logo={option.logo}
|
||||
/>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="invoice-widget-payment-date">
|
||||
Data do pagamento
|
||||
</Label>
|
||||
<DatePicker
|
||||
id="invoice-widget-payment-date"
|
||||
value={paymentDateValue}
|
||||
onChange={(value) => {
|
||||
if (value) {
|
||||
onPaymentDateChange(new Date(`${value}T00:00:00`));
|
||||
}
|
||||
}}
|
||||
disabled={isProcessing}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Status */}
|
||||
<div className="flex items-center justify-between rounded-xl border p-3">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Status atual
|
||||
</span>
|
||||
<Badge
|
||||
variant={getInvoiceStatusBadgeVariant(
|
||||
INVOICE_STATUS_LABEL[invoice.paymentStatus],
|
||||
)}
|
||||
>
|
||||
{INVOICE_STATUS_LABEL[invoice.paymentStatus]}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
{/* Aviso */}
|
||||
<p className="px-1 text-xs text-muted-foreground">
|
||||
Vamos registrar a fatura como paga. Você poderá editar depois
|
||||
se necessário.
|
||||
</p>
|
||||
) : (
|
||||
<div className="flex items-center justify-between rounded-xl border p-3">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Status atual
|
||||
</span>
|
||||
<Badge
|
||||
variant={getInvoiceStatusBadgeVariant(
|
||||
INVOICE_STATUS_LABEL[invoice.paymentStatus],
|
||||
)}
|
||||
>
|
||||
{INVOICE_STATUS_LABEL[invoice.paymentStatus]}
|
||||
</Badge>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -185,7 +266,12 @@ export function InvoicePaymentDialog({
|
||||
<Button
|
||||
type="button"
|
||||
onClick={onConfirm}
|
||||
disabled={isProcessing || !invoice}
|
||||
disabled={
|
||||
isProcessing ||
|
||||
!invoice ||
|
||||
(isInvoicePending &&
|
||||
(!paymentAccountId || paymentAccountOptions.length === 0))
|
||||
}
|
||||
>
|
||||
{isProcessing ? (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user