From 2cafdb3960afa3f82092b7dac9e27e4b81872943 Mon Sep 17 00:00:00 2001 From: Andrey Aratov Date: Mon, 2 Sep 2024 10:13:05 +0300 Subject: [PATCH] fix: monthly budget update --- CHANGELOG.md | 4 ++-- package.json | 2 +- .../BaseExpensesList/BaseExpensesList.spec.ts | 2 -- src/stores/settings/settings.spec.ts | 10 ++-------- src/stores/settings/settings.ts | 13 +++++++------ src/types.ts | 2 +- 6 files changed, 13 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d108e85..f9d59d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog -## 0.9.2 +## 0.9.3 ### Bug Fixes @@ -45,7 +45,7 @@ ### Bug Fixes - input z-index - + ## 0.7.1 ### Bug Fixes diff --git a/package.json b/package.json index 58f5269..692e822 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "budget.it", - "version": "0.9.2", + "version": "0.9.3", "description": "Another budget app, but this one is handy", "repository": "https://github.com/begprod/budget.it", "homepage": "https://begprod.github.io/budget.it/", diff --git a/src/components/BaseExpensesList/BaseExpensesList.spec.ts b/src/components/BaseExpensesList/BaseExpensesList.spec.ts index 3a70083..e860cfc 100644 --- a/src/components/BaseExpensesList/BaseExpensesList.spec.ts +++ b/src/components/BaseExpensesList/BaseExpensesList.spec.ts @@ -100,11 +100,9 @@ describe('BaseExpensesList', () => { monthlyDailyBudget.value = { '032024': { dailyBudget: dailyBudget.value, - isCurrent: false, }, '042024': { dailyBudget: 900, - isCurrent: true, }, }; diff --git a/src/stores/settings/settings.spec.ts b/src/stores/settings/settings.spec.ts index 5728ff5..9f1b696 100644 --- a/src/stores/settings/settings.spec.ts +++ b/src/stores/settings/settings.spec.ts @@ -31,18 +31,12 @@ describe('Settings store', () => { }); it('should set daily budget', () => { - const currentMonth = Object.keys(getMonthlyDailyBudget.value).find( - (key: string) => getMonthlyDailyBudget.value[key].isCurrent, - ); + const currentMonth = new Date().toLocaleDateString().substring(3, 10).replace('.', ''); setDailyBudget(1000); - const currentMonthDailyBudget = currentMonth - ? getMonthlyDailyBudget.value[currentMonth].dailyBudget - : NaN; - expect(dailyBudget.value).toEqual(1000); - expect(currentMonthDailyBudget).toEqual(1000); + expect(getMonthlyDailyBudget.value[currentMonth].dailyBudget).toEqual(1000); }); it('should add new currency', () => { diff --git a/src/stores/settings/settings.ts b/src/stores/settings/settings.ts index aca1ba9..909fce0 100644 --- a/src/stores/settings/settings.ts +++ b/src/stores/settings/settings.ts @@ -38,7 +38,7 @@ export const useSettingsStore = defineStore('settings', { }), getters: { - getMonthlyDailyBudget(state): Record { + getMonthlyDailyBudget(state): Record { return state.monthlyDailyBudget; }, getActiveCurrency(state): ICurrency { @@ -48,6 +48,10 @@ export const useSettingsStore = defineStore('settings', { actions: { initMonthlyDailyBudgetObject() { + if (Object.keys(this.monthlyDailyBudget).length !== 0) { + return; + } + const monthsList = generateMonths(5); const nextMonth = generateMonths(0, 1); const allMonths = [...nextMonth, ...monthsList]; @@ -55,7 +59,6 @@ export const useSettingsStore = defineStore('settings', { allMonths.forEach((month: IMonth) => { this.monthlyDailyBudget[month.id] = { dailyBudget: this.dailyBudget, - isCurrent: month.isCurrent, }; }); }, @@ -67,11 +70,9 @@ export const useSettingsStore = defineStore('settings', { }); }, setDailyBudget(value: number) { - const currentMonth = Object.keys(this.monthlyDailyBudget).find( - (key: string) => this.monthlyDailyBudget[key].isCurrent, - ); + const currentMonth = new Date().toLocaleDateString().substring(3, 10).replace('.', ''); - if (!currentMonth) { + if (!this.monthlyDailyBudget[currentMonth]) { throw new Error('Current month not found'); } diff --git a/src/types.ts b/src/types.ts index bec2c79..6df3eba 100644 --- a/src/types.ts +++ b/src/types.ts @@ -46,7 +46,7 @@ export interface IExpense { export interface ISettingsStore { currencies: RemovableRef>; dailyBudget: RemovableRef; - monthlyDailyBudget: RemovableRef>; + monthlyDailyBudget: RemovableRef>; } export interface ICurrency {