feat(merchants): scatter plot, merchant profiles, and per-merchant transaction history
- /merchants page with spend-vs-frequency scatter chart (click to open profile) - Merchant profile drawer: stats, monthly trend line, full transaction history - /api/analytics/merchants: split-adjusted merchant aggregates + monthly trends - /api/analytics/merchants/[merchant]: per-merchant transaction list - Add Merchants nav item to sidebar
This commit is contained in:
@@ -557,3 +557,49 @@ export function useFees() {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export interface MerchantRow {
|
||||
merchant: string;
|
||||
category: string;
|
||||
transaction_count: number;
|
||||
total_spend: number;
|
||||
avg_transaction: number;
|
||||
first_seen: string;
|
||||
last_seen: string;
|
||||
months_active: number;
|
||||
monthly_trend: Record<string, number>;
|
||||
}
|
||||
|
||||
export function useMerchants(months = 12) {
|
||||
return useQuery<{ merchants: MerchantRow[]; months: number }>({
|
||||
queryKey: ["analytics", "merchants", months],
|
||||
queryFn: async () => {
|
||||
const res = await fetch(`/api/analytics/merchants?months=${months}`);
|
||||
return res.json();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export interface MerchantTxnRow {
|
||||
id: number;
|
||||
transaction_date: string;
|
||||
description: string;
|
||||
amount: number;
|
||||
amount_aud: number | null;
|
||||
my_amount: number;
|
||||
transaction_type: string;
|
||||
category: string;
|
||||
bank_name: string;
|
||||
statement_id: number;
|
||||
}
|
||||
|
||||
export function useMerchantTransactions(merchant: string | null) {
|
||||
return useQuery<{ transactions: MerchantTxnRow[] }>({
|
||||
queryKey: ["analytics", "merchant-txns", merchant],
|
||||
queryFn: async () => {
|
||||
const res = await fetch(`/api/analytics/merchants/${encodeURIComponent(merchant!)}`);
|
||||
return res.json();
|
||||
},
|
||||
enabled: !!merchant,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user