refactor: clean up imports and improve code consistency across various components; remove unused imports in page.tsx, add missing imports in categories page, and standardize formatting in hooks and chart components
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 1m30s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 1m30s
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
|||||||
import { useBankingMetadata, useCategoryStats } from "@/lib/hooks";
|
import { useBankingMetadata, useCategoryStats } from "@/lib/hooks";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Card } from "@/components/ui/card";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@@ -43,7 +44,7 @@ export default function CategoriesPage() {
|
|||||||
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
||||||
const [editingCategory, setEditingCategory] = useState<Category | null>(null);
|
const [editingCategory, setEditingCategory] = useState<Category | null>(null);
|
||||||
const [expandedParents, setExpandedParents] = useState<Set<string>>(
|
const [expandedParents, setExpandedParents] = useState<Set<string>>(
|
||||||
new Set(),
|
new Set()
|
||||||
);
|
);
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
name: "",
|
name: "",
|
||||||
@@ -54,7 +55,7 @@ export default function CategoriesPage() {
|
|||||||
});
|
});
|
||||||
const [searchQuery, setSearchQuery] = useState("");
|
const [searchQuery, setSearchQuery] = useState("");
|
||||||
const [recatResults, setRecatResults] = useState<RecategorizationResult[]>(
|
const [recatResults, setRecatResults] = useState<RecategorizationResult[]>(
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
const [isRecatDialogOpen, setIsRecatDialogOpen] = useState(false);
|
const [isRecatDialogOpen, setIsRecatDialogOpen] = useState(false);
|
||||||
const [isRecategorizing, setIsRecategorizing] = useState(false);
|
const [isRecategorizing, setIsRecategorizing] = useState(false);
|
||||||
@@ -76,7 +77,7 @@ export default function CategoriesPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const parents = metadata.categories.filter(
|
const parents = metadata.categories.filter(
|
||||||
(c: Category) => c.parentId === null,
|
(c: Category) => c.parentId === null
|
||||||
);
|
);
|
||||||
const children: Record<string, Category[]> = {};
|
const children: Record<string, Category[]> = {};
|
||||||
const orphans: Category[] = [];
|
const orphans: Category[] = [];
|
||||||
@@ -85,7 +86,7 @@ export default function CategoriesPage() {
|
|||||||
.filter((c: Category) => c.parentId !== null)
|
.filter((c: Category) => c.parentId !== null)
|
||||||
.forEach((child: Category) => {
|
.forEach((child: Category) => {
|
||||||
const parentExists = parents.some(
|
const parentExists = parents.some(
|
||||||
(p: Category) => p.id === child.parentId,
|
(p: Category) => p.id === child.parentId
|
||||||
);
|
);
|
||||||
if (parentExists) {
|
if (parentExists) {
|
||||||
if (!children[child.parentId!]) {
|
if (!children[child.parentId!]) {
|
||||||
@@ -108,7 +109,9 @@ export default function CategoriesPage() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (parentCategories.length > 0 && expandedParents.size === 0) {
|
if (parentCategories.length > 0 && expandedParents.size === 0) {
|
||||||
if (expandAllByDefault) {
|
if (expandAllByDefault) {
|
||||||
setExpandedParents(new Set(parentCategories.map((p: Category) => p.id)));
|
setExpandedParents(
|
||||||
|
new Set(parentCategories.map((p: Category) => p.id))
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
setExpandedParents(new Set());
|
setExpandedParents(new Set());
|
||||||
}
|
}
|
||||||
@@ -147,7 +150,7 @@ export default function CategoriesPage() {
|
|||||||
|
|
||||||
return { total, count };
|
return { total, count };
|
||||||
},
|
},
|
||||||
[categoryStats, childrenByParent],
|
[categoryStats, childrenByParent]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isLoadingMetadata || !metadata || isLoadingStats || !categoryStats) {
|
if (isLoadingMetadata || !metadata || isLoadingStats || !categoryStats) {
|
||||||
@@ -261,7 +264,7 @@ export default function CategoriesPage() {
|
|||||||
try {
|
try {
|
||||||
// Fetch uncategorized transactions
|
// Fetch uncategorized transactions
|
||||||
const uncategorizedResponse = await fetch(
|
const uncategorizedResponse = await fetch(
|
||||||
"/api/banking/transactions?limit=1000&offset=0&includeUncategorized=true",
|
"/api/banking/transactions?limit=1000&offset=0&includeUncategorized=true"
|
||||||
);
|
);
|
||||||
if (!uncategorizedResponse.ok) {
|
if (!uncategorizedResponse.ok) {
|
||||||
throw new Error("Failed to fetch uncategorized transactions");
|
throw new Error("Failed to fetch uncategorized transactions");
|
||||||
@@ -274,11 +277,11 @@ export default function CategoriesPage() {
|
|||||||
for (const transaction of uncategorized) {
|
for (const transaction of uncategorized) {
|
||||||
const categoryId = autoCategorize(
|
const categoryId = autoCategorize(
|
||||||
transaction.description + " " + (transaction.memo || ""),
|
transaction.description + " " + (transaction.memo || ""),
|
||||||
metadata.categories,
|
metadata.categories
|
||||||
);
|
);
|
||||||
if (categoryId) {
|
if (categoryId) {
|
||||||
const category = metadata.categories.find(
|
const category = metadata.categories.find(
|
||||||
(c: Category) => c.id === categoryId,
|
(c: Category) => c.id === categoryId
|
||||||
);
|
);
|
||||||
if (category) {
|
if (category) {
|
||||||
results.push({ transaction, category });
|
results.push({ transaction, category });
|
||||||
@@ -312,9 +315,9 @@ export default function CategoriesPage() {
|
|||||||
return children.some(
|
return children.some(
|
||||||
(c) =>
|
(c) =>
|
||||||
c.name.toLowerCase().includes(query) ||
|
c.name.toLowerCase().includes(query) ||
|
||||||
c.keywords.some((k) => k.toLowerCase().includes(query)),
|
c.keywords.some((k) => k.toLowerCase().includes(query))
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -359,9 +362,9 @@ export default function CategoriesPage() {
|
|||||||
(c) =>
|
(c) =>
|
||||||
c.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
c.name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||||
c.keywords.some((k) =>
|
c.keywords.some((k) =>
|
||||||
k.toLowerCase().includes(searchQuery.toLowerCase()),
|
k.toLowerCase().includes(searchQuery.toLowerCase())
|
||||||
) ||
|
) ||
|
||||||
parent.name.toLowerCase().includes(searchQuery.toLowerCase()),
|
parent.name.toLowerCase().includes(searchQuery.toLowerCase())
|
||||||
)
|
)
|
||||||
: allChildren;
|
: allChildren;
|
||||||
const stats = getCategoryStats(parent.id, true);
|
const stats = getCategoryStats(parent.id, true);
|
||||||
@@ -448,7 +451,7 @@ export default function CategoriesPage() {
|
|||||||
</p>
|
</p>
|
||||||
<p className="text-xs text-muted-foreground truncate">
|
<p className="text-xs text-muted-foreground truncate">
|
||||||
{new Date(result.transaction.date).toLocaleDateString(
|
{new Date(result.transaction.date).toLocaleDateString(
|
||||||
"fr-FR",
|
"fr-FR"
|
||||||
)}
|
)}
|
||||||
{" • "}
|
{" • "}
|
||||||
{new Intl.NumberFormat("fr-FR", {
|
{new Intl.NumberFormat("fr-FR", {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import { AccountsSummary } from "@/components/dashboard/accounts-summary";
|
|||||||
import { CategoryBreakdown } from "@/components/dashboard/category-breakdown";
|
import { CategoryBreakdown } from "@/components/dashboard/category-breakdown";
|
||||||
import { OFXImportDialog } from "@/components/import/ofx-import-dialog";
|
import { OFXImportDialog } from "@/components/import/ofx-import-dialog";
|
||||||
import { AccountFilterCombobox } from "@/components/ui/account-filter-combobox";
|
import { AccountFilterCombobox } from "@/components/ui/account-filter-combobox";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
|
||||||
import { useBankingData } from "@/lib/hooks";
|
import { useBankingData } from "@/lib/hooks";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Upload } from "lucide-react";
|
import { Upload } from "lucide-react";
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ export default function RulesPage() {
|
|||||||
const {
|
const {
|
||||||
data: transactionsData,
|
data: transactionsData,
|
||||||
isLoading: isLoadingTransactions,
|
isLoading: isLoadingTransactions,
|
||||||
invalidate: invalidateTransactions,
|
|
||||||
} = useTransactions(
|
} = useTransactions(
|
||||||
{
|
{
|
||||||
limit: 10000, // Large limit to get all uncategorized
|
limit: 10000, // Large limit to get all uncategorized
|
||||||
@@ -49,7 +48,7 @@ export default function RulesPage() {
|
|||||||
!!metadata,
|
!!metadata,
|
||||||
);
|
);
|
||||||
|
|
||||||
const refresh = useCallback(() => {
|
const _refresh = useCallback(() => {
|
||||||
invalidateAllTransactionQueries(queryClient);
|
invalidateAllTransactionQueries(queryClient);
|
||||||
invalidateAllCategoryQueries(queryClient);
|
invalidateAllCategoryQueries(queryClient);
|
||||||
}, [queryClient]);
|
}, [queryClient]);
|
||||||
|
|||||||
@@ -31,7 +31,15 @@ export function CategoryBarChart({
|
|||||||
const displayData = data.slice(0, maxItems).reverse(); // Reverse pour avoir le plus grand en haut
|
const displayData = data.slice(0, maxItems).reverse(); // Reverse pour avoir le plus grand en haut
|
||||||
|
|
||||||
// Custom tick component for clickable labels
|
// Custom tick component for clickable labels
|
||||||
const CustomYAxisTick = ({ x, y, payload }: any) => {
|
const CustomYAxisTick = ({
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
payload,
|
||||||
|
}: {
|
||||||
|
x: number;
|
||||||
|
y: number;
|
||||||
|
payload: { value: string };
|
||||||
|
}) => {
|
||||||
const categoryName = payload.value;
|
const categoryName = payload.value;
|
||||||
const item = displayData.find((d) => d.name === categoryName);
|
const item = displayData.find((d) => d.name === categoryName);
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ export function useTransactionsChartData({
|
|||||||
);
|
);
|
||||||
|
|
||||||
return monthlyChartData;
|
return monthlyChartData;
|
||||||
}, [transactionsData]);
|
}, [transactionsData, metadata]);
|
||||||
|
|
||||||
// Calculate category chart data (expenses only)
|
// Calculate category chart data (expenses only)
|
||||||
const categoryData = useMemo(() => {
|
const categoryData = useMemo(() => {
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ export function useTransactionsPage() {
|
|||||||
} else {
|
} else {
|
||||||
setIsCustomDatePickerOpen(true);
|
setIsCustomDatePickerOpen(true);
|
||||||
}
|
}
|
||||||
}, []);
|
}, [setPeriod]);
|
||||||
|
|
||||||
const handleCustomStartDateChange = useCallback((date: Date | undefined) => {
|
const handleCustomStartDateChange = useCallback((date: Date | undefined) => {
|
||||||
setCustomStartDate(date);
|
setCustomStartDate(date);
|
||||||
|
|||||||
Reference in New Issue
Block a user