feat(expenses): add import functionality for expenses and total pending calculation
This commit is contained in:
@@ -9,6 +9,9 @@ import {
|
||||
payExpense as payExpenseApi,
|
||||
getMonthlyPayedTotal,
|
||||
getMonthlyTotals,
|
||||
getTotalPending,
|
||||
importPeriodicExpenses,
|
||||
importExpenses,
|
||||
type CreatePeriodicExpenseInput, type CreateNonPeriodicExpenseInput, type PayExpenseInput,
|
||||
} from "./api";
|
||||
|
||||
@@ -78,6 +81,7 @@ export const expenseKeys = {
|
||||
["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,
|
||||
totalPending: ["expenses", "pending-total"] as const,
|
||||
};
|
||||
|
||||
export function usePeriodicExpenses() {
|
||||
@@ -142,6 +146,13 @@ export function useMonthlyTotals(year: number, month: number) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useTotalPending() {
|
||||
return useQuery({
|
||||
queryKey: expenseKeys.totalPending,
|
||||
queryFn: getTotalPending,
|
||||
});
|
||||
}
|
||||
|
||||
export function useMonthlyPayedTotal(year: number, month: number) {
|
||||
return useQuery({
|
||||
queryKey: expenseKeys.monthlyTotal(year, month),
|
||||
@@ -159,6 +170,26 @@ export function useCreateNonPeriodicExpense() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useImportExpenses() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (file: File) => importExpenses(file),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: expenseKeys.all });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useImportPeriodicExpenses() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (file: File) => importPeriodicExpenses(file),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: expenseKeys.periodic });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function usePayExpense() {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation({
|
||||
|
||||
Reference in New Issue
Block a user