mirror of
https://github.com/Zproger/Aurum.git
synced 2026-10-14 19:46:40 +07:00
Aurum — a self-hosted personal finance operating system: cash flow, net worth tracking, budgets, goals, recurring payments, reports, proactive alerts, and a compound-interest returns calculator, all bilingual (RU/EN) and mobile-first. Ships as a three-container Docker Compose stack (Postgres + FastAPI + nginx-served React frontend). See README.md for setup and CONTRIBUTING.md for development.
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { addGoalContribution, createGoal, deleteGoal, fetchGoals, updateGoal } from "@/api/goals";
|
|
import type { GoalContributionInput, GoalInput } from "@/types";
|
|
|
|
function useInvalidateGoals() {
|
|
const queryClient = useQueryClient();
|
|
return () => queryClient.invalidateQueries({ queryKey: ["goals"] });
|
|
}
|
|
|
|
export function useGoals() {
|
|
return useQuery({ queryKey: ["goals"], queryFn: fetchGoals });
|
|
}
|
|
|
|
export function useCreateGoal() {
|
|
const invalidate = useInvalidateGoals();
|
|
return useMutation({
|
|
mutationFn: (input: GoalInput) => createGoal(input),
|
|
onSuccess: invalidate,
|
|
});
|
|
}
|
|
|
|
export function useUpdateGoal() {
|
|
const invalidate = useInvalidateGoals();
|
|
return useMutation({
|
|
mutationFn: ({ id, input }: { id: number; input: Partial<GoalInput> }) => updateGoal(id, input),
|
|
onSuccess: invalidate,
|
|
});
|
|
}
|
|
|
|
export function useDeleteGoal() {
|
|
const invalidate = useInvalidateGoals();
|
|
return useMutation({
|
|
mutationFn: (id: number) => deleteGoal(id),
|
|
onSuccess: invalidate,
|
|
});
|
|
}
|
|
|
|
export function useAddGoalContribution() {
|
|
const invalidate = useInvalidateGoals();
|
|
return useMutation({
|
|
mutationFn: ({ id, input }: { id: number; input: GoalContributionInput }) => addGoalContribution(id, input),
|
|
onSuccess: invalidate,
|
|
});
|
|
}
|