mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-05-10 03:11:46 +00:00
chore: ajustes de componentes, estilos, dependências e métricas do dashboard
- dashboard: melhorias em métricas, filtros de transações e overview de período - transactions: colunas, tabela e página com novos campos e ajustes de exibição - ui: card, table, navigation-menu, navbar, month-picker, logo-picker, theme-toggler - calculator: ajustes de display, keypad e estado - calendar: melhorias de grid e day-cell - insights: atualização de constantes - settings: pequenos ajustes - pnpm-lock: atualização de dependências - pdf.worker: atualização do worker Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
135
src/features/accounts/components/adjust-balance-dialog.tsx
Normal file
135
src/features/accounts/components/adjust-balance-dialog.tsx
Normal file
@@ -0,0 +1,135 @@
|
||||
"use client";
|
||||
|
||||
import { RiEqualizerLine } from "@remixicon/react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState, useTransition } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { adjustAccountBalanceAction } from "@/features/accounts/actions";
|
||||
import { Button } from "@/shared/components/ui/button";
|
||||
import { CurrencyInput } from "@/shared/components/ui/currency-input";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/shared/components/ui/dialog";
|
||||
import { Label } from "@/shared/components/ui/label";
|
||||
import { formatCurrency } from "@/shared/utils/currency";
|
||||
|
||||
type AdjustBalanceDialogProps = {
|
||||
accountId: string;
|
||||
period: string;
|
||||
currentBalance: number;
|
||||
};
|
||||
|
||||
export function AdjustBalanceDialog({
|
||||
accountId,
|
||||
period,
|
||||
currentBalance,
|
||||
}: AdjustBalanceDialogProps) {
|
||||
const router = useRouter();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [isPending, startTransition] = useTransition();
|
||||
const [amount, setAmount] = useState<string>(currentBalance.toFixed(2));
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
setAmount(currentBalance.toFixed(2));
|
||||
}
|
||||
}, [open, currentBalance]);
|
||||
|
||||
const targetBalance = Number(amount);
|
||||
const diff = Number.isFinite(targetBalance)
|
||||
? Math.round((targetBalance - currentBalance) * 100) / 100
|
||||
: 0;
|
||||
const diffLabel =
|
||||
diff > 0
|
||||
? `Será criado um lançamento de receita de ${formatCurrency(diff)}.`
|
||||
: diff < 0
|
||||
? `Será criado um lançamento de despesa de ${formatCurrency(Math.abs(diff))}.`
|
||||
: "Nenhum ajuste será criado — o saldo já está correto.";
|
||||
|
||||
const handleSave = () => {
|
||||
if (!Number.isFinite(targetBalance)) {
|
||||
toast.error("Informe um valor válido.");
|
||||
return;
|
||||
}
|
||||
|
||||
startTransition(async () => {
|
||||
const result = await adjustAccountBalanceAction({
|
||||
accountId,
|
||||
period,
|
||||
currentBalance,
|
||||
targetBalance,
|
||||
});
|
||||
|
||||
if (result.success) {
|
||||
toast.success(result.message);
|
||||
setOpen(false);
|
||||
router.refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
toast.error(result.error);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
aria-label="Ajustar saldo"
|
||||
>
|
||||
<RiEqualizerLine className="size-4" />
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="sm:max-w-md">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Ajustar saldo</DialogTitle>
|
||||
<DialogDescription>
|
||||
Informe o saldo correto da conta ao final do período. A diferença em
|
||||
relação ao saldo atual será lançada como um ajuste.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4">
|
||||
<div className="rounded-md border bg-muted/30 px-3 py-2 text-sm">
|
||||
<p className="text-muted-foreground">Saldo atual no sistema</p>
|
||||
<p className="font-medium text-foreground">
|
||||
{formatCurrency(currentBalance)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="adjust-balance-target">Saldo correto</Label>
|
||||
<CurrencyInput
|
||||
id="adjust-balance-target"
|
||||
value={amount}
|
||||
onValueChange={setAmount}
|
||||
autoFocus
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">{diffLabel}</p>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => setOpen(false)}
|
||||
disabled={isPending}
|
||||
>
|
||||
Cancelar
|
||||
</Button>
|
||||
<Button type="button" onClick={handleSave} disabled={isPending}>
|
||||
{isPending ? "Salvando..." : "Salvar"}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user