2022-09-02 04:52:15 +00:00
|
|
|
import PortalAPI from 'dashboard/api/helpCenter/portals';
|
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 {
|
2022-10-21 20:43:15 +00:00
|
|
|
data: { payload },
|
2022-08-08 10:17:32 +00:00
|
|
|
} = 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-07-27 06:54:43 +00:00
|
|
|
} catch (error) {
|
|
|
|
throwErrorMessage(error);
|
|
|
|
} finally {
|
|
|
|
commit(types.SET_UI_FLAG, { isFetching: false });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-10-21 20:43:15 +00:00
|
|
|
show: async ({ commit }, { portalSlug, locale }) => {
|
|
|
|
commit(types.SET_UI_FLAG, { isFetchingItem: true });
|
|
|
|
try {
|
|
|
|
const response = await portalAPIs.getPortal({ portalSlug, locale });
|
|
|
|
const {
|
|
|
|
data: { meta },
|
|
|
|
} = response;
|
|
|
|
commit(types.SET_PORTALS_META, meta);
|
|
|
|
} catch (error) {
|
|
|
|
// Ignore error
|
|
|
|
} finally {
|
|
|
|
commit(types.SET_UI_FLAG, { isFetchingItem: 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-09-02 07:02:07 +00:00
|
|
|
update: async ({ commit }, { portalSlug, ...portalObj }) => {
|
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,
|
2022-09-02 07:02:07 +00:00
|
|
|
portalObj,
|
2022-08-31 14:29:05 +00:00
|
|
|
});
|
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-09-01 07:57:08 +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
|
|
|
};
|