From cb8628ce3950c3dc8808336b2beded9799095b41 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Mon, 8 Dec 2025 09:28:09 +0100 Subject: [PATCH] refactor: standardize code formatting and improve readability across multiple components, including transaction handling and sidebar layout adjustments --- app/api/banking/transactions/route.ts | 5 +- app/rules/page.tsx | 28 +++++----- app/transactions/page.tsx | 54 +++++++++---------- components/dashboard/sidebar.tsx | 27 +++++----- components/layout/page-header.tsx | 4 +- components/transactions/transaction-table.tsx | 22 ++++---- components/ui/account-filter-combobox.tsx | 8 +-- components/ui/category-filter-combobox.tsx | 10 ++-- hooks/use-mobile.ts | 2 +- lib/hooks.ts | 6 +-- 10 files changed, 80 insertions(+), 86 deletions(-) diff --git a/app/api/banking/transactions/route.ts b/app/api/banking/transactions/route.ts index 4152ad1..f02ec4b 100644 --- a/app/api/banking/transactions/route.ts +++ b/app/api/banking/transactions/route.ts @@ -125,9 +125,6 @@ export async function DELETE(request: Request) { console.error("Error deleting transaction:", error); const errorMessage = error instanceof Error ? error.message : "Failed to delete transaction"; - return NextResponse.json( - { error: errorMessage }, - { status: 500 }, - ); + return NextResponse.json({ error: errorMessage }, { status: 500 }); } } diff --git a/app/rules/page.tsx b/app/rules/page.tsx index 2efd410..cf77a89 100644 --- a/app/rules/page.tsx +++ b/app/rules/page.tsx @@ -42,7 +42,7 @@ export default function RulesPage() { offset: 0, includeUncategorized: true, }, - !!metadata + !!metadata, ); const refresh = useCallback(() => { @@ -56,7 +56,7 @@ export default function RulesPage() { const [filterMinCount, setFilterMinCount] = useState(2); const [expandedGroups, setExpandedGroups] = useState>(new Set()); const [selectedGroup, setSelectedGroup] = useState( - null + null, ); const [isDialogOpen, setIsDialogOpen] = useState(false); const [isAutoCategorizing, setIsAutoCategorizing] = useState(false); @@ -87,7 +87,7 @@ export default function RulesPage() { totalAmount: transactions.reduce((sum, t) => sum + t.amount, 0), suggestedKeyword: suggestKeyword(descriptions), }; - } + }, ); // Filter by search query @@ -98,7 +98,7 @@ export default function RulesPage() { (g) => g.displayName.toLowerCase().includes(query) || g.key.includes(query) || - g.suggestedKeyword.toLowerCase().includes(query) + g.suggestedKeyword.toLowerCase().includes(query), ); } @@ -167,7 +167,7 @@ export default function RulesPage() { // 1. Add keyword to category const category = metadata.categories.find( - (c: { id: string }) => c.id === ruleData.categoryId + (c: { id: string }) => c.id === ruleData.categoryId, ); if (!category) { throw new Error("Category not found"); @@ -175,7 +175,7 @@ export default function RulesPage() { // Check if keyword already exists const keywordExists = category.keywords.some( - (k: string) => k.toLowerCase() === ruleData.keyword.toLowerCase() + (k: string) => k.toLowerCase() === ruleData.keyword.toLowerCase(), ); if (!keywordExists) { @@ -193,14 +193,14 @@ export default function RulesPage() { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id, categoryId: ruleData.categoryId }), - }) - ) + }), + ), ); } refresh(); }, - [metadata, refresh] + [metadata, refresh], ); const handleAutoCategorize = useCallback(async () => { @@ -214,7 +214,7 @@ export default function RulesPage() { for (const transaction of uncategorized) { const categoryId = autoCategorize( transaction.description + " " + (transaction.memo || ""), - metadata.categories + metadata.categories, ); if (categoryId) { await fetch("/api/banking/transactions", { @@ -228,7 +228,7 @@ export default function RulesPage() { refresh(); alert( - `${categorizedCount} transaction(s) catégorisée(s) automatiquement` + `${categorizedCount} transaction(s) catégorisée(s) automatiquement`, ); } catch (error) { console.error("Error auto-categorizing:", error); @@ -247,8 +247,8 @@ export default function RulesPage() { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ...t, categoryId }), - }) - ) + }), + ), ); refresh(); } catch (error) { @@ -256,7 +256,7 @@ export default function RulesPage() { alert("Erreur lors de la catégorisation"); } }, - [refresh] + [refresh], ); if ( diff --git a/app/transactions/page.tsx b/app/transactions/page.tsx index abb0364..bcbbe9e 100644 --- a/app/transactions/page.tsx +++ b/app/transactions/page.tsx @@ -65,20 +65,20 @@ export default function TransactionsPage() { const [showReconciled, setShowReconciled] = useState("all"); const [period, setPeriod] = useState("all"); const [customStartDate, setCustomStartDate] = useState( - undefined + undefined, ); const [customEndDate, setCustomEndDate] = useState( - undefined + undefined, ); const [isCustomDatePickerOpen, setIsCustomDatePickerOpen] = useState(false); const [sortField, setSortField] = useState("date"); const [sortOrder, setSortOrder] = useState("desc"); const [selectedTransactions, setSelectedTransactions] = useState>( - new Set() + new Set(), ); const [ruleDialogOpen, setRuleDialogOpen] = useState(false); const [ruleTransaction, setRuleTransaction] = useState( - null + null, ); const [updatingTransactionIds, setUpdatingTransactionIds] = useState< Set @@ -182,7 +182,7 @@ export default function TransactionsPage() { // Use transactions from current page to find similar ones const normalizedDesc = normalizeDescription(ruleTransaction.description); const similarTransactions = transactionsData.transactions.filter( - (t) => normalizeDescription(t.description) === normalizedDesc + (t) => normalizeDescription(t.description) === normalizedDesc, ); if (similarTransactions.length === 0) return null; @@ -193,7 +193,7 @@ export default function TransactionsPage() { transactions: similarTransactions, totalAmount: similarTransactions.reduce((sum, t) => sum + t.amount, 0), suggestedKeyword: suggestKeyword( - similarTransactions.map((t) => t.description) + similarTransactions.map((t) => t.description), ), }; }, [ruleTransaction, transactionsData]); @@ -209,7 +209,7 @@ export default function TransactionsPage() { // 1. Add keyword to category const category = metadata.categories.find( - (c: { id: string }) => c.id === ruleData.categoryId + (c: { id: string }) => c.id === ruleData.categoryId, ); if (!category) { throw new Error("Category not found"); @@ -217,7 +217,7 @@ export default function TransactionsPage() { // Check if keyword already exists const keywordExists = category.keywords.some( - (k: string) => k.toLowerCase() === ruleData.keyword.toLowerCase() + (k: string) => k.toLowerCase() === ruleData.keyword.toLowerCase(), ); if (!keywordExists) { @@ -235,8 +235,8 @@ export default function TransactionsPage() { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id, categoryId: ruleData.categoryId }), - }) - ) + }), + ), ); } @@ -245,7 +245,7 @@ export default function TransactionsPage() { queryClient.invalidateQueries({ queryKey: ["banking-metadata"] }); setRuleDialogOpen(false); }, - [metadata, queryClient] + [metadata, queryClient], ); const invalidateAll = useCallback(() => { @@ -272,7 +272,7 @@ export default function TransactionsPage() { if (!transactionsData) return; const transaction = transactionsData.transactions.find( - (t) => t.id === transactionId + (t) => t.id === transactionId, ); if (!transaction) return; @@ -297,7 +297,7 @@ export default function TransactionsPage() { if (!transactionsData) return; const transaction = transactionsData.transactions.find( - (t) => t.id === transactionId + (t) => t.id === transactionId, ); if (!transaction || transaction.isReconciled) return; @@ -320,12 +320,12 @@ export default function TransactionsPage() { const setCategory = async ( transactionId: string, - categoryId: string | null + categoryId: string | null, ) => { if (!transactionsData) return; const transaction = transactionsData.transactions.find( - (t) => t.id === transactionId + (t) => t.id === transactionId, ); if (!transaction) return; @@ -350,7 +350,7 @@ export default function TransactionsPage() { return { ...oldData, transactions: oldData.transactions.map((t) => - t.id === transactionId ? { ...t, categoryId } : t + t.id === transactionId ? { ...t, categoryId } : t, ), }; }); @@ -370,7 +370,7 @@ export default function TransactionsPage() { if (!transactionsData) return; const transactionsToUpdate = transactionsData.transactions.filter((t) => - selectedTransactions.has(t.id) + selectedTransactions.has(t.id), ); setSelectedTransactions(new Set()); @@ -382,8 +382,8 @@ export default function TransactionsPage() { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ...t, isReconciled: reconciled }), - }) - ) + }), + ), ); invalidateTransactions(); } catch (error) { @@ -395,7 +395,7 @@ export default function TransactionsPage() { if (!transactionsData) return; const transactionsToUpdate = transactionsData.transactions.filter((t) => - selectedTransactions.has(t.id) + selectedTransactions.has(t.id), ); const transactionIds = transactionsToUpdate.map((t) => t.id); @@ -413,8 +413,8 @@ export default function TransactionsPage() { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ ...t, categoryId }), - }) - ) + }), + ), ); // Mise à jour directe du cache après succès @@ -424,7 +424,7 @@ export default function TransactionsPage() { return { ...oldData, transactions: oldData.transactions.map((t) => - transactionIds.includes(t.id) ? { ...t, categoryId } : t + transactionIds.includes(t.id) ? { ...t, categoryId } : t, ), }; }); @@ -446,7 +446,7 @@ export default function TransactionsPage() { setSelectedTransactions(new Set()); } else { setSelectedTransactions( - new Set(transactionsData.transactions.map((t) => t.id)) + new Set(transactionsData.transactions.map((t) => t.id)), ); } }; @@ -488,7 +488,7 @@ export default function TransactionsPage() { return { ...oldData, transactions: oldData.transactions.filter( - (t) => t.id !== transactionId + (t) => t.id !== transactionId, ), total: oldData.total - 1, }; @@ -499,13 +499,13 @@ export default function TransactionsPage() { `/api/banking/transactions?id=${transactionId}`, { method: "DELETE", - } + }, ); if (!response.ok) { const errorData = await response.json().catch(() => ({})); throw new Error( - errorData.error || `Failed to delete transaction: ${response.status}` + errorData.error || `Failed to delete transaction: ${response.status}`, ); } diff --git a/components/dashboard/sidebar.tsx b/components/dashboard/sidebar.tsx index 2dd932f..58a0e8e 100644 --- a/components/dashboard/sidebar.tsx +++ b/components/dashboard/sidebar.tsx @@ -77,10 +77,7 @@ function SidebarContent({ )} -