feat: initial commit - finanzas app
Complete personal finance management application with: - Dashboard with financial metrics and alerts - Credit card management and payments - Fixed and variable debt tracking - Monthly budget planning - Intelligent alert system - Responsive design with Tailwind CSS Tech stack: Next.js 14, TypeScript, Zustand, Recharts 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This commit is contained in:
39
lib/store/slices/budgetSlice.ts
Normal file
39
lib/store/slices/budgetSlice.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { StateCreator } from 'zustand'
|
||||
import { MonthlyBudget } from '@/lib/types'
|
||||
|
||||
const now = new Date()
|
||||
|
||||
export interface BudgetSlice {
|
||||
monthlyBudgets: MonthlyBudget[]
|
||||
currentMonth: number
|
||||
currentYear: number
|
||||
|
||||
setMonthlyBudget: (budget: MonthlyBudget) => void
|
||||
updateMonthlyBudget: (month: number, year: number, updates: Partial<MonthlyBudget>) => void
|
||||
}
|
||||
|
||||
export const createBudgetSlice: StateCreator<BudgetSlice> = (set) => ({
|
||||
monthlyBudgets: [],
|
||||
currentMonth: now.getMonth() + 1,
|
||||
currentYear: now.getFullYear(),
|
||||
|
||||
setMonthlyBudget: (budget) =>
|
||||
set((state) => {
|
||||
const existingIndex = state.monthlyBudgets.findIndex(
|
||||
(b) => b.month === budget.month && b.year === budget.year
|
||||
)
|
||||
if (existingIndex >= 0) {
|
||||
const newBudgets = [...state.monthlyBudgets]
|
||||
newBudgets[existingIndex] = budget
|
||||
return { monthlyBudgets: newBudgets }
|
||||
}
|
||||
return { monthlyBudgets: [...state.monthlyBudgets, budget] }
|
||||
}),
|
||||
|
||||
updateMonthlyBudget: (month, year, updates) =>
|
||||
set((state) => ({
|
||||
monthlyBudgets: state.monthlyBudgets.map((b) =>
|
||||
b.month === month && b.year === year ? { ...b, ...updates } : b
|
||||
),
|
||||
})),
|
||||
})
|
||||
Reference in New Issue
Block a user