chore: clean up code by removing trailing whitespace and ensuring consistent formatting across various files = prettier

This commit is contained in:
Julien Froidefond
2025-12-01 08:37:30 +01:00
parent 757b1b84ab
commit e715779de7
98 changed files with 5453 additions and 3126 deletions

View File

@@ -37,19 +37,27 @@ export default function TransactionsPage() {
}
}, [searchParams]);
const [selectedCategories, setSelectedCategories] = useState<string[]>(["all"]);
const [selectedCategories, setSelectedCategories] = useState<string[]>([
"all",
]);
const [showReconciled, setShowReconciled] = useState<string>("all");
const [period, setPeriod] = useState<Period>("all");
const [customStartDate, setCustomStartDate] = useState<Date | undefined>(undefined);
const [customEndDate, setCustomEndDate] = useState<Date | undefined>(undefined);
const [customStartDate, setCustomStartDate] = useState<Date | undefined>(
undefined,
);
const [customEndDate, setCustomEndDate] = useState<Date | undefined>(
undefined,
);
const [isCustomDatePickerOpen, setIsCustomDatePickerOpen] = useState(false);
const [sortField, setSortField] = useState<SortField>("date");
const [sortOrder, setSortOrder] = useState<SortOrder>("desc");
const [selectedTransactions, setSelectedTransactions] = useState<Set<string>>(
new Set()
new Set(),
);
const [ruleDialogOpen, setRuleDialogOpen] = useState(false);
const [ruleTransaction, setRuleTransaction] = useState<Transaction | null>(null);
const [ruleTransaction, setRuleTransaction] = useState<Transaction | null>(
null,
);
// Get start date based on period
const startDate = useMemo(() => {
@@ -104,7 +112,7 @@ export default function TransactionsPage() {
transactions = transactions.filter(
(t) =>
t.description.toLowerCase().includes(query) ||
t.memo?.toLowerCase().includes(query)
t.memo?.toLowerCase().includes(query),
);
}
@@ -113,7 +121,7 @@ export default function TransactionsPage() {
transactions = transactions.filter((t) => !t.categoryId);
} else {
transactions = transactions.filter(
(t) => t.categoryId && selectedCategories.includes(t.categoryId)
(t) => t.categoryId && selectedCategories.includes(t.categoryId),
);
}
}
@@ -121,12 +129,20 @@ export default function TransactionsPage() {
if (showReconciled !== "all") {
const isReconciled = showReconciled === "reconciled";
transactions = transactions.filter(
(t) => t.isReconciled === isReconciled
(t) => t.isReconciled === isReconciled,
);
}
return transactions;
}, [data, searchQuery, selectedCategories, showReconciled, period, startDate, endDate]);
}, [
data,
searchQuery,
selectedCategories,
showReconciled,
period,
startDate,
endDate,
]);
// Transactions filtered for category filter (by accounts, search, reconciled, period - not categories)
const transactionsForCategoryFilter = useMemo(() => {
@@ -154,25 +170,33 @@ export default function TransactionsPage() {
transactions = transactions.filter(
(t) =>
t.description.toLowerCase().includes(query) ||
t.memo?.toLowerCase().includes(query)
t.memo?.toLowerCase().includes(query),
);
}
if (!selectedAccounts.includes("all")) {
transactions = transactions.filter(
(t) => selectedAccounts.includes(t.accountId)
transactions = transactions.filter((t) =>
selectedAccounts.includes(t.accountId),
);
}
if (showReconciled !== "all") {
const isReconciled = showReconciled === "reconciled";
transactions = transactions.filter(
(t) => t.isReconciled === isReconciled
(t) => t.isReconciled === isReconciled,
);
}
return transactions;
}, [data, searchQuery, selectedAccounts, showReconciled, period, startDate, endDate]);
}, [
data,
searchQuery,
selectedAccounts,
showReconciled,
period,
startDate,
endDate,
]);
const filteredTransactions = useMemo(() => {
if (!data) return [];
@@ -199,13 +223,13 @@ export default function TransactionsPage() {
transactions = transactions.filter(
(t) =>
t.description.toLowerCase().includes(query) ||
t.memo?.toLowerCase().includes(query)
t.memo?.toLowerCase().includes(query),
);
}
if (!selectedAccounts.includes("all")) {
transactions = transactions.filter(
(t) => selectedAccounts.includes(t.accountId)
transactions = transactions.filter((t) =>
selectedAccounts.includes(t.accountId),
);
}
@@ -214,7 +238,7 @@ export default function TransactionsPage() {
transactions = transactions.filter((t) => !t.categoryId);
} else {
transactions = transactions.filter(
(t) => t.categoryId && selectedCategories.includes(t.categoryId)
(t) => t.categoryId && selectedCategories.includes(t.categoryId),
);
}
}
@@ -222,7 +246,7 @@ export default function TransactionsPage() {
if (showReconciled !== "all") {
const isReconciled = showReconciled === "reconciled";
transactions = transactions.filter(
(t) => t.isReconciled === isReconciled
(t) => t.isReconciled === isReconciled,
);
}
@@ -268,7 +292,7 @@ export default function TransactionsPage() {
// Find similar transactions (same normalized description)
const normalizedDesc = normalizeDescription(ruleTransaction.description);
const similarTransactions = data.transactions.filter(
(t) => normalizeDescription(t.description) === normalizedDesc
(t) => normalizeDescription(t.description) === normalizedDesc,
);
return {
@@ -276,7 +300,9 @@ export default function TransactionsPage() {
displayName: ruleTransaction.description,
transactions: similarTransactions,
totalAmount: similarTransactions.reduce((sum, t) => sum + t.amount, 0),
suggestedKeyword: suggestKeyword(similarTransactions.map((t) => t.description)),
suggestedKeyword: suggestKeyword(
similarTransactions.map((t) => t.description),
),
};
}, [ruleTransaction, data]);
@@ -290,14 +316,16 @@ export default function TransactionsPage() {
if (!data) return;
// 1. Add keyword to category
const category = data.categories.find((c) => c.id === ruleData.categoryId);
const category = data.categories.find(
(c) => c.id === ruleData.categoryId,
);
if (!category) {
throw new Error("Category not found");
}
// Check if keyword already exists
const keywordExists = category.keywords.some(
(k) => k.toLowerCase() === ruleData.keyword.toLowerCase()
(k) => k.toLowerCase() === ruleData.keyword.toLowerCase(),
);
if (!keywordExists) {
@@ -310,20 +338,20 @@ export default function TransactionsPage() {
// 2. Apply to existing transactions if requested
if (ruleData.applyToExisting) {
const transactions = data.transactions.filter((t) =>
ruleData.transactionIds.includes(t.id)
ruleData.transactionIds.includes(t.id),
);
await Promise.all(
transactions.map((t) =>
updateTransaction({ ...t, categoryId: ruleData.categoryId })
)
updateTransaction({ ...t, categoryId: ruleData.categoryId }),
),
);
}
refresh();
setRuleDialogOpen(false);
},
[data, refresh]
[data, refresh],
);
if (isLoading || !data) {
@@ -355,7 +383,7 @@ export default function TransactionsPage() {
};
const updatedTransactions = data.transactions.map((t) =>
t.id === transactionId ? updatedTransaction : t
t.id === transactionId ? updatedTransaction : t,
);
update({ ...data, transactions: updatedTransactions });
@@ -381,7 +409,7 @@ export default function TransactionsPage() {
};
const updatedTransactions = data.transactions.map((t) =>
t.id === transactionId ? updatedTransaction : t
t.id === transactionId ? updatedTransaction : t,
);
update({ ...data, transactions: updatedTransactions });
@@ -399,7 +427,7 @@ export default function TransactionsPage() {
const setCategory = async (
transactionId: string,
categoryId: string | null
categoryId: string | null,
) => {
const transaction = data.transactions.find((t) => t.id === transactionId);
if (!transaction) return;
@@ -407,7 +435,7 @@ export default function TransactionsPage() {
const updatedTransaction = { ...transaction, categoryId };
const updatedTransactions = data.transactions.map((t) =>
t.id === transactionId ? updatedTransaction : t
t.id === transactionId ? updatedTransaction : t,
);
update({ ...data, transactions: updatedTransactions });
@@ -425,11 +453,11 @@ export default function TransactionsPage() {
const bulkReconcile = async (reconciled: boolean) => {
const transactionsToUpdate = data.transactions.filter((t) =>
selectedTransactions.has(t.id)
selectedTransactions.has(t.id),
);
const updatedTransactions = data.transactions.map((t) =>
selectedTransactions.has(t.id) ? { ...t, isReconciled: reconciled } : t
selectedTransactions.has(t.id) ? { ...t, isReconciled: reconciled } : t,
);
update({ ...data, transactions: updatedTransactions });
setSelectedTransactions(new Set());
@@ -441,8 +469,8 @@ export default function TransactionsPage() {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ...t, isReconciled: reconciled }),
})
)
}),
),
);
} catch (error) {
console.error("Failed to update transactions:", error);
@@ -452,11 +480,11 @@ export default function TransactionsPage() {
const bulkSetCategory = async (categoryId: string | null) => {
const transactionsToUpdate = data.transactions.filter((t) =>
selectedTransactions.has(t.id)
selectedTransactions.has(t.id),
);
const updatedTransactions = data.transactions.map((t) =>
selectedTransactions.has(t.id) ? { ...t, categoryId } : t
selectedTransactions.has(t.id) ? { ...t, categoryId } : t,
);
update({ ...data, transactions: updatedTransactions });
setSelectedTransactions(new Set());
@@ -468,8 +496,8 @@ export default function TransactionsPage() {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ ...t, categoryId }),
})
)
}),
),
);
} catch (error) {
console.error("Failed to update transactions:", error);
@@ -507,10 +535,10 @@ export default function TransactionsPage() {
const deleteTransaction = async (transactionId: string) => {
// Optimistic update
const updatedTransactions = data.transactions.filter(
(t) => t.id !== transactionId
(t) => t.id !== transactionId,
);
update({ ...data, transactions: updatedTransactions });
// Remove from selected if selected
const newSelected = new Set(selectedTransactions);
newSelected.delete(transactionId);
@@ -521,7 +549,7 @@ export default function TransactionsPage() {
`/api/banking/transactions?id=${transactionId}`,
{
method: "DELETE",
}
},
);
if (!response.ok) throw new Error("Failed to delete transaction");
} catch (error) {