fix(vacay): reset selectedYear when the active year is deleted
When deleting the currently selected year, selectedYear was never cleared, leaving the deleted year shown as active in the UI. Now resets to the latest remaining year, or the current calendar year if all years have been removed. Fixes #369
This commit is contained in:
parent
98813a9b40
commit
f6faaa23b0
@ -222,7 +222,13 @@ export const useVacayStore = create<VacayState>((set, get) => ({
|
||||
|
||||
removeYear: async (year: number) => {
|
||||
const data = await api.removeYear(year)
|
||||
set({ years: data.years })
|
||||
const updates: Partial<VacayState> = { years: data.years }
|
||||
if (get().selectedYear === year) {
|
||||
updates.selectedYear = data.years.length > 0
|
||||
? data.years[data.years.length - 1]
|
||||
: new Date().getFullYear()
|
||||
}
|
||||
set(updates)
|
||||
},
|
||||
|
||||
loadEntries: async (year?: number) => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user