Add budget module and push notifications for transactions
All checks were successful
Deploy to VPS / deploy (push) Successful in 34s

Budget: recurring items CRUD, yearly/monthly projections with no-double-count
logic, and full UI (overview, monthly detail, recurring items manager).

Push notifications: Web Push via VAPID keys, triggered on transaction creation
from n8n. Includes service worker handlers, frontend subscription flow, and
a test button on the Dashboard (temporary).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Carlos Escalante
2026-03-26 22:28:14 -06:00
parent 2cd0d3b2e1
commit 8d76059ae8
25 changed files with 2225 additions and 13 deletions

View File

@@ -0,0 +1,89 @@
import { useState, useEffect, useCallback } from 'react';
import {
type YearlyProjection,
type MonthlyDetail,
type RecurringItem,
type RecurringItemCreate,
type RecurringItemUpdate,
getYearlyProjection,
getMonthlyDetail,
getRecurringItems,
createRecurringItem,
updateRecurringItem as apiUpdateItem,
deleteRecurringItem as apiDeleteItem,
} from '@/api';
export function useBudget(initialYear: number) {
const [year, setYear] = useState(initialYear);
const [selectedMonth, setSelectedMonth] = useState<number>(new Date().getMonth() + 1);
const [projection, setProjection] = useState<YearlyProjection | null>(null);
const [monthDetail, setMonthDetail] = useState<MonthlyDetail | null>(null);
const [recurringItems, setRecurringItems] = useState<RecurringItem[]>([]);
const [loading, setLoading] = useState(true);
const [monthLoading, setMonthLoading] = useState(false);
const fetchProjection = useCallback(async () => {
setLoading(true);
try {
const { data } = await getYearlyProjection(year);
setProjection(data);
} finally {
setLoading(false);
}
}, [year]);
const fetchMonthDetail = useCallback(async () => {
setMonthLoading(true);
try {
const { data } = await getMonthlyDetail(year, selectedMonth);
setMonthDetail(data);
} finally {
setMonthLoading(false);
}
}, [year, selectedMonth]);
const fetchRecurringItems = useCallback(async () => {
const { data } = await getRecurringItems();
setRecurringItems(data);
}, []);
useEffect(() => {
fetchProjection();
fetchRecurringItems();
}, [fetchProjection, fetchRecurringItems]);
useEffect(() => {
fetchMonthDetail();
}, [fetchMonthDetail]);
const addItem = async (data: RecurringItemCreate) => {
await createRecurringItem(data);
await Promise.all([fetchProjection(), fetchMonthDetail(), fetchRecurringItems()]);
};
const updateItem = async (id: number, data: RecurringItemUpdate) => {
await apiUpdateItem(id, data);
await Promise.all([fetchProjection(), fetchMonthDetail(), fetchRecurringItems()]);
};
const deleteItem = async (id: number) => {
await apiDeleteItem(id);
await Promise.all([fetchProjection(), fetchMonthDetail(), fetchRecurringItems()]);
};
return {
year,
setYear,
selectedMonth,
setSelectedMonth,
projection,
monthDetail,
recurringItems,
loading,
monthLoading,
addItem,
updateItem,
deleteItem,
refresh: () => Promise.all([fetchProjection(), fetchMonthDetail(), fetchRecurringItems()]),
};
}