Refactor: Implement DashboardLayout, fix mobile nav, and resolve scroll issues
This commit is contained in:
33
lib/store/slices/incomesSlice.ts
Normal file
33
lib/store/slices/incomesSlice.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { StateCreator } from 'zustand'
|
||||
import { Income, AppState } from '@/lib/types'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
export interface IncomesSlice {
|
||||
incomes: Income[]
|
||||
addIncome: (income: Omit<Income, 'id'>) => void
|
||||
removeIncome: (id: string) => void
|
||||
updateIncome: (id: string, income: Partial<Income>) => void
|
||||
}
|
||||
|
||||
export const createIncomesSlice: StateCreator<
|
||||
AppState & IncomesSlice,
|
||||
[],
|
||||
[],
|
||||
IncomesSlice
|
||||
> = (set) => ({
|
||||
incomes: [],
|
||||
addIncome: (income) =>
|
||||
set((state) => ({
|
||||
incomes: [...(state.incomes || []), { ...income, id: uuidv4() }],
|
||||
})),
|
||||
removeIncome: (id) =>
|
||||
set((state) => ({
|
||||
incomes: state.incomes.filter((i) => i.id !== id),
|
||||
})),
|
||||
updateIncome: (id, updatedIncome) =>
|
||||
set((state) => ({
|
||||
incomes: state.incomes.map((i) =>
|
||||
i.id === id ? { ...i, ...updatedIncome } : i
|
||||
),
|
||||
})),
|
||||
})
|
||||
Reference in New Issue
Block a user