feat: Portals store integration (#5185)

This commit is contained in:
Muhsin Keloth
2022-08-08 15:47:32 +05:30
committed by GitHub
parent 052422ed03
commit 20f3568583
30 changed files with 982 additions and 413 deletions

View File

@@ -3,13 +3,22 @@ import { throwErrorMessage } from 'dashboard/store/utils/api';
import { types } from './mutations';
const portalAPIs = new PortalAPI();
export const actions = {
index: async ({ commit }) => {
index: async ({ commit, state, dispatch }) => {
try {
commit(types.SET_UI_FLAG, { isFetching: true });
const { data } = await portalAPIs.get();
const portalIds = data.map(portal => portal.id);
commit(types.ADD_MANY_PORTALS_ENTRY, data);
const {
data: { payload, meta },
} = await portalAPIs.get();
commit(types.CLEAR_PORTALS);
const portalIds = payload.map(portal => portal.id);
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.SET_PORTALS_META, meta);
} catch (error) {
throwErrorMessage(error);
} finally {
@@ -68,4 +77,8 @@ export const actions = {
});
}
},
setPortalId: async ({ commit }, portalId) => {
commit(types.SET_SELECTED_PORTAL_ID, portalId);
},
};