feat(expenses): add monthly totals and pagination support for expenses
This commit is contained in:
@@ -7,6 +7,8 @@ import {
|
||||
generateMonthlyExpense as generateMonthlyExpenseApi,
|
||||
getExpenses, createNonPeriodicExpense as createNonPeriodicExpenseApi,
|
||||
payExpense as payExpenseApi,
|
||||
getMonthlyPayedTotal,
|
||||
getMonthlyTotals,
|
||||
type CreatePeriodicExpenseInput, type CreateNonPeriodicExpenseInput, type PayExpenseInput,
|
||||
} from "./api";
|
||||
|
||||
@@ -72,7 +74,10 @@ export function useDailyQuotes(type: string, startDate: string, endDate: string)
|
||||
export const expenseKeys = {
|
||||
periodic: ["periodic-expenses"] as const,
|
||||
all: ["expenses"] as const,
|
||||
byStatus: (status: string) => ["expenses", status] as const,
|
||||
byStatus: (status: string, page: number, pageSize: number) =>
|
||||
["expenses", status, page, pageSize] as const,
|
||||
monthlyTotal: (year: number, month: number) => ["expenses", "monthly-total", year, month] as const,
|
||||
monthlyTotals: (year: number, month: number) => ["expenses", "totals", year, month] as const,
|
||||
};
|
||||
|
||||
export function usePeriodicExpenses() {
|
||||
@@ -123,10 +128,24 @@ export function useGenerateMonthlyExpense() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useExpenses(status: string) {
|
||||
export function useExpenses(status: string, page: number = 1, pageSize: number = 10) {
|
||||
return useQuery({
|
||||
queryKey: expenseKeys.byStatus(status),
|
||||
queryFn: () => getExpenses(status === "all" ? undefined : status),
|
||||
queryKey: expenseKeys.byStatus(status, page, pageSize),
|
||||
queryFn: () => getExpenses(status === "all" ? undefined : status, page, pageSize),
|
||||
});
|
||||
}
|
||||
|
||||
export function useMonthlyTotals(year: number, month: number) {
|
||||
return useQuery({
|
||||
queryKey: expenseKeys.monthlyTotals(year, month),
|
||||
queryFn: () => getMonthlyTotals(year, month),
|
||||
});
|
||||
}
|
||||
|
||||
export function useMonthlyPayedTotal(year: number, month: number) {
|
||||
return useQuery({
|
||||
queryKey: expenseKeys.monthlyTotal(year, month),
|
||||
queryFn: () => getMonthlyPayedTotal(year, month),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user