2022-08-04 09:41:29 +00:00
|
|
|
import PortalAPI from 'dashboard/api/helpCenter/portals.js';
|
2022-07-27 06:54:43 +00:00
|
|
|
import { throwErrorMessage } from 'dashboard/store/utils/api';
|
|
|
|
import { types } from './mutations';
|
2022-08-04 09:41:29 +00:00
|
|
|
const portalAPIs = new PortalAPI();
|
2022-07-27 06:54:43 +00:00
|
|
|
export const actions = {
|
2022-08-31 14:29:05 +00:00
|
|
|
index: async ({ commit }) => {
|
2022-07-27 06:54:43 +00:00
|
|
|
try {
|
|
|
|
commit(types.SET_UI_FLAG, { isFetching: true });
|
2022-08-08 10:17:32 +00:00
|
|
|
const {
|
|
|
|
data: { payload, meta },
|
|
|
|
} = await portalAPIs.get();
|
|
|
|
commit(types.CLEAR_PORTALS);
|
2022-08-31 14:29:05 +00:00
|
|
|
const portalSlugs = payload.map(portal => portal.slug);
|
2022-08-08 10:17:32 +00:00
|
|
|
commit(types.ADD_MANY_PORTALS_ENTRY, payload);
|
2022-08-31 14:29:05 +00:00
|
|
|
commit(types.ADD_MANY_PORTALS_IDS, portalSlugs);
|
|
|
|
|
2022-08-08 10:17:32 +00:00
|
|
|
commit(types.SET_PORTALS_META, meta);
|
2022-07-27 06:54:43 +00:00
|
|
|
} catch (error) {
|
|
|
|
throwErrorMessage(error);
|
|
|
|
} finally {
|
|
|
|
commit(types.SET_UI_FLAG, { isFetching: false });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-08-31 14:29:05 +00:00
|
|
|
create: async ({ commit }, params) => {
|
2022-07-27 06:54:43 +00:00
|
|
|
commit(types.SET_UI_FLAG, { isCreating: true });
|
|
|
|
try {
|
2022-08-04 09:41:29 +00:00
|
|
|
const { data } = await portalAPIs.create(params);
|
2022-08-31 14:29:05 +00:00
|
|
|
const { slug: portalSlug } = data;
|
2022-07-27 06:54:43 +00:00
|
|
|
commit(types.ADD_PORTAL_ENTRY, data);
|
2022-08-31 14:29:05 +00:00
|
|
|
commit(types.ADD_PORTAL_ID, portalSlug);
|
2022-07-27 06:54:43 +00:00
|
|
|
} catch (error) {
|
|
|
|
throwErrorMessage(error);
|
|
|
|
} finally {
|
|
|
|
commit(types.SET_UI_FLAG, { isCreating: false });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-08-31 14:29:05 +00:00
|
|
|
update: async ({ commit }, { portalObj }) => {
|
|
|
|
const portalSlug = portalObj.slug;
|
2022-07-27 06:54:43 +00:00
|
|
|
commit(types.SET_HELP_PORTAL_UI_FLAG, {
|
|
|
|
uiFlags: { isUpdating: true },
|
2022-08-31 14:29:05 +00:00
|
|
|
portalSlug,
|
2022-07-27 06:54:43 +00:00
|
|
|
});
|
|
|
|
try {
|
2022-08-31 14:29:05 +00:00
|
|
|
const { data } = await portalAPIs.updatePortal({
|
|
|
|
portalSlug,
|
|
|
|
portalObj,
|
|
|
|
});
|
2022-07-27 06:54:43 +00:00
|
|
|
commit(types.UPDATE_PORTAL_ENTRY, data);
|
|
|
|
} catch (error) {
|
|
|
|
throwErrorMessage(error);
|
|
|
|
} finally {
|
|
|
|
commit(types.SET_HELP_PORTAL_UI_FLAG, {
|
|
|
|
uiFlags: { isUpdating: false },
|
2022-08-31 14:29:05 +00:00
|
|
|
portalSlug,
|
2022-07-27 06:54:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-08-31 14:29:05 +00:00
|
|
|
delete: async ({ commit }, { portalSlug }) => {
|
2022-07-27 06:54:43 +00:00
|
|
|
commit(types.SET_HELP_PORTAL_UI_FLAG, {
|
|
|
|
uiFlags: { isDeleting: true },
|
2022-08-31 14:29:05 +00:00
|
|
|
portalSlug,
|
2022-07-27 06:54:43 +00:00
|
|
|
});
|
|
|
|
try {
|
2022-08-31 14:29:05 +00:00
|
|
|
await portalAPIs.delete(portalSlug);
|
|
|
|
commit(types.REMOVE_PORTAL_ENTRY, portalSlug);
|
|
|
|
commit(types.REMOVE_PORTAL_ID, portalSlug);
|
2022-07-27 06:54:43 +00:00
|
|
|
} catch (error) {
|
|
|
|
throwErrorMessage(error);
|
|
|
|
} finally {
|
|
|
|
commit(types.SET_HELP_PORTAL_UI_FLAG, {
|
|
|
|
uiFlags: { isDeleting: false },
|
2022-08-31 14:29:05 +00:00
|
|
|
portalSlug,
|
2022-07-27 06:54:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2022-08-18 06:15:08 +00:00
|
|
|
updatePortal: async ({ commit }, portal) => {
|
|
|
|
commit(types.UPDATE_PORTAL_ENTRY, portal);
|
|
|
|
},
|
2022-07-27 06:54:43 +00:00
|
|
|
};
|