chore: Moves portal slug as ID to query resources in vue store (#5359)
This commit is contained in:
committed by
GitHub
parent
d14beeb654
commit
ebea5428bc
@@ -3,21 +3,17 @@ import { throwErrorMessage } from 'dashboard/store/utils/api';
|
||||
import { types } from './mutations';
|
||||
const portalAPIs = new PortalAPI();
|
||||
export const actions = {
|
||||
index: async ({ commit, state, dispatch }) => {
|
||||
index: async ({ commit }) => {
|
||||
try {
|
||||
commit(types.SET_UI_FLAG, { isFetching: true });
|
||||
const {
|
||||
data: { payload, meta },
|
||||
} = await portalAPIs.get();
|
||||
commit(types.CLEAR_PORTALS);
|
||||
const portalIds = payload.map(portal => portal.id);
|
||||
const portalSlugs = payload.map(portal => portal.slug);
|
||||
commit(types.ADD_MANY_PORTALS_ENTRY, payload);
|
||||
commit(types.ADD_MANY_PORTALS_IDS, portalIds);
|
||||
const { selectedPortalId } = state;
|
||||
// Check if selected portal is still in the portals list
|
||||
if (!portalIds.includes(selectedPortalId)) {
|
||||
dispatch('setPortalId', portalIds[0]);
|
||||
}
|
||||
commit(types.ADD_MANY_PORTALS_IDS, portalSlugs);
|
||||
|
||||
commit(types.SET_PORTALS_META, meta);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
@@ -26,20 +22,13 @@ export const actions = {
|
||||
}
|
||||
},
|
||||
|
||||
create: async ({ commit, state, dispatch }, params) => {
|
||||
create: async ({ commit }, params) => {
|
||||
commit(types.SET_UI_FLAG, { isCreating: true });
|
||||
try {
|
||||
const { data } = await portalAPIs.create(params);
|
||||
const { id: portalId } = data;
|
||||
const { slug: portalSlug } = data;
|
||||
commit(types.ADD_PORTAL_ENTRY, data);
|
||||
commit(types.ADD_PORTAL_ID, portalId);
|
||||
const {
|
||||
portals: { selectedPortalId },
|
||||
} = state;
|
||||
// Check if there are any selected portal
|
||||
if (!selectedPortalId) {
|
||||
dispatch('setPortalId', portalId);
|
||||
}
|
||||
commit(types.ADD_PORTAL_ID, portalSlug);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
@@ -47,47 +36,46 @@ export const actions = {
|
||||
}
|
||||
},
|
||||
|
||||
update: async ({ commit }, params) => {
|
||||
const portalId = params.id;
|
||||
const portalSlug = params.slug;
|
||||
update: async ({ commit }, { portalObj }) => {
|
||||
const portalSlug = portalObj.slug;
|
||||
commit(types.SET_HELP_PORTAL_UI_FLAG, {
|
||||
uiFlags: { isUpdating: true },
|
||||
portalId,
|
||||
portalSlug,
|
||||
});
|
||||
try {
|
||||
const { data } = await portalAPIs.updatePortal({ portalSlug, params });
|
||||
const { data } = await portalAPIs.updatePortal({
|
||||
portalSlug,
|
||||
portalObj,
|
||||
});
|
||||
commit(types.UPDATE_PORTAL_ENTRY, data);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
commit(types.SET_HELP_PORTAL_UI_FLAG, {
|
||||
uiFlags: { isUpdating: false },
|
||||
portalId,
|
||||
portalSlug,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
delete: async ({ commit }, portalId) => {
|
||||
delete: async ({ commit }, { portalSlug }) => {
|
||||
commit(types.SET_HELP_PORTAL_UI_FLAG, {
|
||||
uiFlags: { isDeleting: true },
|
||||
portalId,
|
||||
portalSlug,
|
||||
});
|
||||
try {
|
||||
await portalAPIs.delete(portalId);
|
||||
commit(types.REMOVE_PORTAL_ENTRY, portalId);
|
||||
commit(types.REMOVE_PORTAL_ID, portalId);
|
||||
await portalAPIs.delete(portalSlug);
|
||||
commit(types.REMOVE_PORTAL_ENTRY, portalSlug);
|
||||
commit(types.REMOVE_PORTAL_ID, portalSlug);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
commit(types.SET_HELP_PORTAL_UI_FLAG, {
|
||||
uiFlags: { isDeleting: false },
|
||||
portalId,
|
||||
portalSlug,
|
||||
});
|
||||
}
|
||||
},
|
||||
setPortalId: async ({ commit }, portalId) => {
|
||||
commit(types.SET_SELECTED_PORTAL_ID, portalId);
|
||||
},
|
||||
updatePortal: async ({ commit }, portal) => {
|
||||
commit(types.UPDATE_PORTAL_ENTRY, portal);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user