refactor: standardize quotation marks in pnpm-lock.yaml and improve code formatting across various components; enhance readability and maintain consistency in code style
This commit is contained in:
@@ -7,7 +7,7 @@ import { useState } from "react";
|
||||
*/
|
||||
export function useLocalStorage<T>(
|
||||
key: string,
|
||||
initialValue: T
|
||||
initialValue: T,
|
||||
): [T, (value: T | ((val: T) => T)) => void] {
|
||||
// État pour stocker la valeur
|
||||
const [storedValue, setStoredValue] = useState<T>(() => {
|
||||
@@ -29,9 +29,9 @@ export function useLocalStorage<T>(
|
||||
// Permet d'utiliser une fonction comme setState
|
||||
const valueToStore =
|
||||
value instanceof Function ? value(storedValue) : value;
|
||||
|
||||
|
||||
setStoredValue(valueToStore);
|
||||
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
window.localStorage.setItem(key, JSON.stringify(valueToStore));
|
||||
}
|
||||
@@ -42,4 +42,3 @@ export function useLocalStorage<T>(
|
||||
|
||||
return [storedValue, setValue];
|
||||
}
|
||||
|
||||
|
||||
@@ -146,13 +146,13 @@ export function useTransactionsBalanceChart({
|
||||
// Fetch transactions before startDate for initial balance calculation
|
||||
const { data: beforeStartDateData } = useTransactions(
|
||||
beforeStartDateParams,
|
||||
!!metadata && period !== "all" && !!startDate
|
||||
!!metadata && period !== "all" && !!startDate,
|
||||
);
|
||||
|
||||
// Fetch all filtered transactions for chart
|
||||
const { data: transactionsData, isLoading } = useTransactions(
|
||||
chartParams,
|
||||
!!metadata
|
||||
!!metadata,
|
||||
);
|
||||
|
||||
// Calculate balance chart data
|
||||
@@ -169,7 +169,7 @@ export function useTransactionsBalanceChart({
|
||||
|
||||
// Sort transactions by date
|
||||
const sortedTransactions = [...transactions].sort(
|
||||
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()
|
||||
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime(),
|
||||
);
|
||||
|
||||
// Calculate starting balance: initialBalance + transactions before startDate
|
||||
@@ -181,7 +181,7 @@ export function useTransactionsBalanceChart({
|
||||
// Start with initial balances
|
||||
runningBalance = accountsToUse.reduce(
|
||||
(sum: number, acc: Account) => sum + (acc.initialBalance || 0),
|
||||
0
|
||||
0,
|
||||
);
|
||||
|
||||
// Add transactions before startDate if we have them
|
||||
@@ -190,7 +190,7 @@ export function useTransactionsBalanceChart({
|
||||
(t) => {
|
||||
const transactionDate = new Date(t.date);
|
||||
return transactionDate < startDate;
|
||||
}
|
||||
},
|
||||
);
|
||||
beforeStartTransactions.forEach((t) => {
|
||||
runningBalance += t.amount;
|
||||
@@ -206,7 +206,7 @@ export function useTransactionsBalanceChart({
|
||||
});
|
||||
|
||||
const aggregatedBalanceData: BalanceChartDataPoint[] = Array.from(
|
||||
aggregatedBalanceByDate.entries()
|
||||
aggregatedBalanceByDate.entries(),
|
||||
).map(([date, balance]) => ({
|
||||
date: new Date(date).toLocaleDateString("fr-FR", {
|
||||
day: "2-digit",
|
||||
@@ -234,7 +234,7 @@ export function useTransactionsBalanceChart({
|
||||
(t) => {
|
||||
const transactionDate = new Date(t.date);
|
||||
return transactionDate < startDate;
|
||||
}
|
||||
},
|
||||
);
|
||||
beforeStartTransactions.forEach((t) => {
|
||||
const currentBalance = accountRunningBalances.get(t.accountId) || 0;
|
||||
@@ -246,7 +246,7 @@ export function useTransactionsBalanceChart({
|
||||
const transactionsForAccounts = selectedAccounts.includes("all")
|
||||
? sortedTransactions
|
||||
: sortedTransactions.filter((t) =>
|
||||
selectedAccounts.includes(t.accountId)
|
||||
selectedAccounts.includes(t.accountId),
|
||||
);
|
||||
|
||||
transactionsForAccounts.forEach((t) => {
|
||||
@@ -276,7 +276,7 @@ export function useTransactionsBalanceChart({
|
||||
(t) => {
|
||||
const transactionDate = new Date(t.date);
|
||||
return transactionDate < startDate && t.accountId === account.id;
|
||||
}
|
||||
},
|
||||
);
|
||||
beforeStartTransactions.forEach((t) => {
|
||||
accountStartingBalance += t.amount;
|
||||
@@ -304,7 +304,7 @@ export function useTransactionsBalanceChart({
|
||||
});
|
||||
|
||||
return point;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -115,7 +115,7 @@ export function useTransactionsChartData({
|
||||
// Fetch all filtered transactions for chart
|
||||
const { data: transactionsData, isLoading } = useTransactions(
|
||||
chartParams,
|
||||
!!metadata
|
||||
!!metadata,
|
||||
);
|
||||
|
||||
// Calculate monthly chart data
|
||||
@@ -141,13 +141,13 @@ export function useTransactionsChartData({
|
||||
|
||||
// Format months with year: use short format for better readability
|
||||
const sortedMonths = Array.from(monthlyMap.entries()).sort((a, b) =>
|
||||
a[0].localeCompare(b[0])
|
||||
a[0].localeCompare(b[0]),
|
||||
);
|
||||
|
||||
const monthlyChartData: MonthlyChartData[] = sortedMonths.map(
|
||||
([monthKey, values]) => {
|
||||
const date = new Date(monthKey + "-01");
|
||||
|
||||
|
||||
// Format: "janv. 24" instead of "janv. 2024" for compactness
|
||||
const monthLabel = date.toLocaleDateString("fr-FR", {
|
||||
month: "short",
|
||||
@@ -160,7 +160,7 @@ export function useTransactionsChartData({
|
||||
depenses: values.expenses,
|
||||
solde: values.income - values.expenses,
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return monthlyChartData;
|
||||
@@ -184,10 +184,12 @@ export function useTransactionsChartData({
|
||||
});
|
||||
|
||||
const categoryChartData: CategoryChartData[] = Array.from(
|
||||
categoryTotals.entries()
|
||||
categoryTotals.entries(),
|
||||
)
|
||||
.map(([categoryId, total]) => {
|
||||
const category = metadata.categories.find((c: Category) => c.id === categoryId);
|
||||
const category = metadata.categories.find(
|
||||
(c: Category) => c.id === categoryId,
|
||||
);
|
||||
return {
|
||||
name: category?.name || "Non catégorisé",
|
||||
value: Math.round(total),
|
||||
@@ -204,10 +206,7 @@ export function useTransactionsChartData({
|
||||
// Calculate total amount and count from all filtered transactions
|
||||
const totalAmount = useMemo(() => {
|
||||
if (!transactionsData) return 0;
|
||||
return transactionsData.transactions.reduce(
|
||||
(sum, t) => sum + t.amount,
|
||||
0
|
||||
);
|
||||
return transactionsData.transactions.reduce((sum, t) => sum + t.amount, 0);
|
||||
}, [transactionsData]);
|
||||
|
||||
const totalCount = useMemo(() => {
|
||||
@@ -223,4 +222,3 @@ export function useTransactionsChartData({
|
||||
transactions: transactionsData?.transactions || [],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ export function useTransactionsForAccountFilter({
|
||||
// Fetch all filtered transactions (without account filter)
|
||||
const { data: transactionsData, isLoading } = useTransactions(
|
||||
filterParams,
|
||||
!!metadata
|
||||
!!metadata,
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -106,4 +106,3 @@ export function useTransactionsForAccountFilter({
|
||||
isLoading,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ export function useTransactionsForCategoryFilter({
|
||||
// Fetch all filtered transactions (without category filter)
|
||||
const { data: transactionsData, isLoading } = useTransactions(
|
||||
filterParams,
|
||||
!!metadata
|
||||
!!metadata,
|
||||
);
|
||||
|
||||
return {
|
||||
@@ -102,4 +102,3 @@ export function useTransactionsForCategoryFilter({
|
||||
isLoading,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,10 @@ export function useTransactionsPage() {
|
||||
"all",
|
||||
]);
|
||||
const [showReconciled, setShowReconciled] = useState<string>("all");
|
||||
const [period, setPeriod] = useLocalStorage<Period>("transactions-period", "3months");
|
||||
const [period, setPeriod] = useLocalStorage<Period>(
|
||||
"transactions-period",
|
||||
"3months",
|
||||
);
|
||||
const [customStartDate, setCustomStartDate] = useState<Date | undefined>(
|
||||
undefined,
|
||||
);
|
||||
@@ -75,29 +78,29 @@ export function useTransactionsPage() {
|
||||
useEffect(() => {
|
||||
const categoryIdsParam = searchParams.get("categoryIds");
|
||||
const includeUncategorizedParam = searchParams.get("includeUncategorized");
|
||||
|
||||
|
||||
if (categoryIdsParam && metadata) {
|
||||
const categoryIds = categoryIdsParam.split(",");
|
||||
|
||||
|
||||
// Expand parent categories to include their children
|
||||
const expandedCategoryIds = new Set<string>(categoryIds);
|
||||
|
||||
|
||||
categoryIds.forEach((categoryId) => {
|
||||
// Check if this is a parent category
|
||||
const category = metadata.categories.find(
|
||||
(c: Category) => c.id === categoryId
|
||||
(c: Category) => c.id === categoryId,
|
||||
);
|
||||
if (category && category.parentId === null) {
|
||||
// Find all children of this parent
|
||||
const children = metadata.categories.filter(
|
||||
(c: Category) => c.parentId === categoryId
|
||||
(c: Category) => c.parentId === categoryId,
|
||||
);
|
||||
children.forEach((child: Category) => {
|
||||
expandedCategoryIds.add(child.id);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
setSelectedCategories(Array.from(expandedCategoryIds));
|
||||
setPage(0);
|
||||
} else if (includeUncategorizedParam === "true") {
|
||||
@@ -205,15 +208,18 @@ export function useTransactionsPage() {
|
||||
setPage(0);
|
||||
}, []);
|
||||
|
||||
const handlePeriodChange = useCallback((p: Period) => {
|
||||
setPeriod(p);
|
||||
setPage(0);
|
||||
if (p !== "custom") {
|
||||
setIsCustomDatePickerOpen(false);
|
||||
} else {
|
||||
setIsCustomDatePickerOpen(true);
|
||||
}
|
||||
}, [setPeriod]);
|
||||
const handlePeriodChange = useCallback(
|
||||
(p: Period) => {
|
||||
setPeriod(p);
|
||||
setPage(0);
|
||||
if (p !== "custom") {
|
||||
setIsCustomDatePickerOpen(false);
|
||||
} else {
|
||||
setIsCustomDatePickerOpen(true);
|
||||
}
|
||||
},
|
||||
[setPeriod],
|
||||
);
|
||||
|
||||
const handleCustomStartDateChange = useCallback((date: Date | undefined) => {
|
||||
setCustomStartDate(date);
|
||||
|
||||
Reference in New Issue
Block a user