diff --git a/app/folders/page.tsx b/app/folders/page.tsx
index 6ac18e3..c0fe57a 100644
--- a/app/folders/page.tsx
+++ b/app/folders/page.tsx
@@ -22,7 +22,7 @@ import {
Building2,
RefreshCw,
} from "lucide-react"
-import { generateId, addFolder, updateFolder, deleteFolder } from "@/lib/store-db"
+import { addFolder, updateFolder, deleteFolder, updateAccount } from "@/lib/store-db"
import type { Folder as FolderType, Account } from "@/lib/types"
import { cn } from "@/lib/utils"
@@ -42,6 +42,7 @@ interface FolderTreeItemProps {
level: number
onEdit: (folder: FolderType) => void
onDelete: (folderId: string) => void
+ onEditAccount: (account: Account) => void
formatCurrency: (amount: number) => string
}
@@ -52,13 +53,14 @@ function FolderTreeItem({
level,
onEdit,
onDelete,
+ onEditAccount,
formatCurrency,
}: FolderTreeItemProps) {
const [isExpanded, setIsExpanded] = useState(true)
- // Pour le dossier racine, inclure aussi les comptes sans dossier (folderId: null)
+ // Pour le dossier "Mes Comptes" (folder-root), inclure aussi les comptes sans dossier
const folderAccounts = accounts.filter((a) =>
- a.folderId === folder.id || (folder.parentId === null && a.folderId === null)
+ a.folderId === folder.id || (folder.id === "folder-root" && a.folderId === null)
)
const childFolders = allFolders.filter((f) => f.parentId === folder.id)
const hasChildren = childFolders.length > 0 || folderAccounts.length > 0
@@ -129,12 +131,20 @@ function FolderTreeItem({
{isExpanded && (
{folderAccounts.map((account) => (
-
+
{account.name}
= 0 ? "text-emerald-600" : "text-red-600")}>
{formatCurrency(account.balance)}
+
))}
@@ -147,6 +157,7 @@ function FolderTreeItem({
level={level + 1}
onEdit={onEdit}
onDelete={onDelete}
+ onEditAccount={onEditAccount}
formatCurrency={formatCurrency}
/>
))}
@@ -156,6 +167,13 @@ function FolderTreeItem({
)
}
+const accountTypeLabels = {
+ CHECKING: "Compte courant",
+ SAVINGS: "Épargne",
+ CREDIT_CARD: "Carte de crédit",
+ OTHER: "Autre",
+}
+
export default function FoldersPage() {
const { data, isLoading, refresh } = useBankingData()
const [isDialogOpen, setIsDialogOpen] = useState(false)
@@ -165,6 +183,15 @@ export default function FoldersPage() {
parentId: "folder-root" as string | null,
color: "#6366f1",
})
+
+ // Account editing state
+ const [isAccountDialogOpen, setIsAccountDialogOpen] = useState(false)
+ const [editingAccount, setEditingAccount] = useState
(null)
+ const [accountFormData, setAccountFormData] = useState({
+ name: "",
+ type: "CHECKING" as Account["type"],
+ folderId: "folder-root",
+ })
if (isLoading || !data) {
return (
@@ -241,6 +268,35 @@ export default function FoldersPage() {
}
}
+ const handleEditAccount = (account: Account) => {
+ setEditingAccount(account)
+ setAccountFormData({
+ name: account.name,
+ type: account.type,
+ folderId: account.folderId || "folder-root",
+ })
+ setIsAccountDialogOpen(true)
+ }
+
+ const handleSaveAccount = async () => {
+ if (!editingAccount) return
+
+ try {
+ await updateAccount({
+ ...editingAccount,
+ name: accountFormData.name,
+ type: accountFormData.type,
+ folderId: accountFormData.folderId === "folder-root" ? null : accountFormData.folderId,
+ })
+ refresh()
+ setIsAccountDialogOpen(false)
+ setEditingAccount(null)
+ } catch (error) {
+ console.error("Error updating account:", error)
+ alert("Erreur lors de la mise à jour du compte")
+ }
+ }
+
return (
@@ -272,6 +328,7 @@ export default function FoldersPage() {
level={0}
onEdit={handleEdit}
onDelete={handleDelete}
+ onEditAccount={handleEditAccount}
formatCurrency={formatCurrency}
/>
))}
@@ -343,6 +400,65 @@ export default function FoldersPage() {
+
+
)
}