mirror of
https://github.com/Zproger/Aurum.git
synced 2026-10-14 19:46:40 +07:00
Initial public release
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.
This commit is contained in:
44
frontend/src/hooks/useGoals.ts
Normal file
44
frontend/src/hooks/useGoals.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user