feat: add duplicate transaction detection and display in transactions page, enhancing user experience with visual indicators for duplicates
This commit is contained in:
21
lib/hooks.ts
21
lib/hooks.ts
@@ -83,7 +83,7 @@ export function useLocalStorage<T>(key: string, initialValue: T) {
|
||||
|
||||
// Helper function to serialize transaction params into a query key
|
||||
export function getTransactionsQueryKey(
|
||||
params: TransactionsPaginatedParams = {},
|
||||
params: TransactionsPaginatedParams = {}
|
||||
): (string | number)[] {
|
||||
const key: (string | number)[] = ["transactions"];
|
||||
if (params.limit) key.push(`limit:${params.limit}`);
|
||||
@@ -106,7 +106,7 @@ export function getTransactionsQueryKey(
|
||||
|
||||
export function useTransactions(
|
||||
params: TransactionsPaginatedParams = {},
|
||||
enabled = true,
|
||||
enabled = true
|
||||
) {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -134,7 +134,7 @@ export function useTransactions(
|
||||
if (params.isReconciled !== undefined && params.isReconciled !== "all") {
|
||||
searchParams.set(
|
||||
"isReconciled",
|
||||
params.isReconciled === true ? "true" : "false",
|
||||
params.isReconciled === true ? "true" : "false"
|
||||
);
|
||||
}
|
||||
if (params.sortField) searchParams.set("sortField", params.sortField);
|
||||
@@ -205,3 +205,18 @@ export function useAccountsWithStats() {
|
||||
staleTime: 60 * 1000, // 1 minute
|
||||
});
|
||||
}
|
||||
|
||||
export function useDuplicateIds() {
|
||||
return useQuery({
|
||||
queryKey: ["duplicate-ids"],
|
||||
queryFn: async (): Promise<Set<string>> => {
|
||||
const response = await fetch("/api/banking/duplicates/ids");
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch duplicate IDs");
|
||||
}
|
||||
const data = await response.json();
|
||||
return new Set(data.duplicateIds || []);
|
||||
},
|
||||
staleTime: 30 * 1000, // 30 seconds
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user