refactor: deduplicate cache revalidation actions

This commit is contained in:
Shivam Mishra
2026-06-08 18:39:40 +05:30
parent 0deb026f9d
commit 625302ac3c
8 changed files with 129 additions and 71 deletions
@@ -7,6 +7,7 @@ import {
DELETE_TEAM,
} from './types';
import TeamsAPI from '../../../api/teams';
import { createCacheRevalidateAction } from '../../utils/cacheRevalidate';
export const actions = {
create: async ({ commit }, teamInfo) => {
@@ -22,18 +23,11 @@ export const actions = {
commit(SET_TEAM_UI_FLAG, { isCreating: false });
}
},
revalidate: async ({ commit }, { newKey }) => {
try {
const isExistingKeyValid = await TeamsAPI.validateCacheKey(newKey);
if (!isExistingKeyValid) {
const response = await TeamsAPI.refetchAndCommit(newKey);
commit(CLEAR_TEAMS);
commit(SET_TEAMS, response.data);
}
} catch (error) {
// Ignore error
}
},
revalidate: createCacheRevalidateAction({
api: TeamsAPI,
mutation: SET_TEAMS,
clearMutation: CLEAR_TEAMS,
}),
get: async ({ commit }) => {
commit(SET_TEAM_UI_FLAG, { isFetching: true });
try {