feat: add initial balance support to accounts, enhancing account management and balance calculations across components

This commit is contained in:
Julien Froidefond
2025-11-30 12:13:02 +01:00
parent c26ba9ddc6
commit 184a073bb1
13 changed files with 117 additions and 30 deletions

View File

@@ -7,6 +7,7 @@ import { Building2, GripVertical, Pencil } from "lucide-react";
import { cn } from "@/lib/utils";
import Link from "next/link";
import type { Account } from "@/lib/types";
import { getAccountBalance } from "@/lib/account-utils";
interface DraggableAccountItemProps {
account: Account;
@@ -19,6 +20,7 @@ export function DraggableAccountItem({
onEditAccount,
formatCurrency,
}: DraggableAccountItemProps) {
const realBalance = getAccountBalance(account);
const {
attributes,
listeners,
@@ -71,10 +73,10 @@ export function DraggableAccountItem({
<span
className={cn(
"text-sm tabular-nums",
account.balance >= 0 ? "text-emerald-600" : "text-red-600"
realBalance >= 0 ? "text-emerald-600" : "text-red-600"
)}
>
{formatCurrency(account.balance)}
{formatCurrency(realBalance)}
</span>
<Button
variant="ghost"

View File

@@ -4,6 +4,7 @@ import { useState } from "react";
import { DraggableFolderItem } from "./draggable-folder-item";
import { DraggableAccountItem } from "./draggable-account-item";
import type { Folder as FolderType, Account } from "@/lib/types";
import { getAccountBalance } from "@/lib/account-utils";
interface FolderTreeItemProps {
folder: FolderType;
@@ -35,7 +36,10 @@ export function FolderTreeItem({
(folder.id === "folder-root" && a.folderId === null)
);
const childFolders = allFolders.filter((f) => f.parentId === folder.id);
const folderTotal = folderAccounts.reduce((sum, a) => sum + a.balance, 0);
const folderTotal = folderAccounts.reduce(
(sum, a) => sum + getAccountBalance(a),
0,
);
return (
<div>