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)
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
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
|
|
),
|
|
})),
|
|
})
|