make sure that 404 current time entry requests do not override local

state while preparing new time entry
This commit is contained in:
Gregor Vostrak
2026-02-10 17:21:18 +01:00
parent dc98151d42
commit bfc33b48c1

View File

@@ -1,5 +1,5 @@
import { defineStore } from 'pinia';
import { computed, reactive, ref } from 'vue';
import { computed, ref } from 'vue';
import { api } from '@/packages/api/src';
import type { TimeEntry } from '@/packages/api/src';
import dayjs, { Dayjs } from 'dayjs';
@@ -30,7 +30,7 @@ const emptyTimeEntry = {
} as TimeEntry;
export const useCurrentTimeEntryStore = defineStore('currentTimeEntry', () => {
const currentTimeEntry = ref<TimeEntry>(reactive(emptyTimeEntry));
const currentTimeEntry = ref<TimeEntry>({ ...emptyTimeEntry });
const { handleApiRequestNotifications } = useNotificationsStore();
const queryClient = useQueryClient();
@@ -74,11 +74,23 @@ export const useCurrentTimeEntryStore = defineStore('currentTimeEntry', () => {
startLiveTimer();
}
} else {
currentTimeEntry.value = { ...emptyTimeEntry };
// No active time entry on server
// Only reset if we had a previously started timer (has an ID)
// Don't reset if user is preparing a new time entry (no ID yet)
if (currentTimeEntry.value.id !== '') {
currentTimeEntry.value = { ...emptyTimeEntry };
stopLiveTimer();
}
}
}
} catch {
currentTimeEntry.value = { ...emptyTimeEntry };
// API error (e.g., 404 when no active time entry)
// Only reset if we had a previously started timer (has an ID)
// Don't reset if user is preparing a new time entry (no ID yet)
if (currentTimeEntry.value.id !== '') {
currentTimeEntry.value = { ...emptyTimeEntry };
stopLiveTimer();
}
}
} else {
throw new Error(