diff --git a/src/hooks/incident/useCurrentIncident.ts b/src/hooks/incident/useCurrentIncident.ts index af6a2e6dd..deeffbb36 100644 --- a/src/hooks/incident/useCurrentIncident.ts +++ b/src/hooks/incident/useCurrentIncident.ts @@ -127,12 +127,17 @@ export const useCurrentIncident = () => { : updateUserIncident(newIncidentId)); }; + const loadRecentIncident = async () => { + await recentIncidentState.execute().catch(getErrorMessage); + }; + return { currentIncidentId: readonly(currentIncidentId), currentIncident, hasCurrentIncident, isCurrentIncidentLoading, updateCurrentIncidentId, + loadRecentIncident, fetchIncidentDetails: async () => { debug('Fetching incident details...'); await fetchInstance().catch(getErrorMessage); diff --git a/src/hooks/incident/useUserIncident.ts b/src/hooks/incident/useUserIncident.ts index c7e586ac4..19143fc5d 100644 --- a/src/hooks/incident/useUserIncident.ts +++ b/src/hooks/incident/useUserIncident.ts @@ -56,7 +56,10 @@ export const useUserIncident = ( incidentStates: incidentFromStates.value, incidentId: incidentId.value, }); - await updateUserIncident(newValue).catch(getErrorMessage); + // update user states if new incident id is defined and does not match incident id from states. + if (newValue) { + await updateUserIncident(newValue).catch(getErrorMessage); + } }, { immediate: true }, ); diff --git a/src/layouts/Authenticated.vue b/src/layouts/Authenticated.vue index 112c14b5d..3dbcf20b5 100644 --- a/src/layouts/Authenticated.vue +++ b/src/layouts/Authenticated.vue @@ -208,6 +208,7 @@ export default defineComponent({ currentIncident, currentIncidentId, fetchIncidentDetails, + loadRecentIncident, updateCurrentIncidentId, } = useCurrentIncident(); const authStore = useAuthStore(); @@ -509,6 +510,9 @@ export default defineComponent({ // Load other page data (/incidents, /organizations, /languages, etc.) // It's because loading /incidents before loading current user incident is slow // Note: The sequence of operations here is crucial for achieving the desired performance. + if (!currentIncidentId.value) { + loadRecentIncident().catch(getErrorMessage); + } fetchIncidentDetails().catch(getErrorMessage); // Load all other page data after loading user incident loadState.execute().catch(getErrorMessage);