Initial commit - cleaned for CV

This commit is contained in:
Renato97
2026-03-31 01:23:33 -03:00
commit 9c11f23af0
142 changed files with 13690 additions and 0 deletions

View 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
),
})),
})