feat: Create store to manage Portals (#5020)
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
committed by
GitHub
parent
1594d49a70
commit
bfca4852c8
@@ -0,0 +1,71 @@
|
||||
import PortalsAPI from 'dashboard/api/helpCenter/portals.js';
|
||||
import { throwErrorMessage } from 'dashboard/store/utils/api';
|
||||
import { types } from './mutations';
|
||||
|
||||
export const actions = {
|
||||
index: async ({ commit }) => {
|
||||
try {
|
||||
commit(types.SET_UI_FLAG, { isFetching: true });
|
||||
const { data } = await PortalsAPI.get();
|
||||
const portalIds = data.map(portal => portal.id);
|
||||
commit(types.ADD_MANY_PORTALS_ENTRY, data);
|
||||
commit(types.ADD_MANY_PORTALS_IDS, portalIds);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
commit(types.SET_UI_FLAG, { isFetching: false });
|
||||
}
|
||||
},
|
||||
|
||||
create: async ({ commit }, params) => {
|
||||
commit(types.SET_UI_FLAG, { isCreating: true });
|
||||
try {
|
||||
const { data } = await PortalsAPI.create(params);
|
||||
const { id: portalId } = data;
|
||||
commit(types.ADD_PORTAL_ENTRY, data);
|
||||
commit(types.ADD_PORTAL_ID, portalId);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
commit(types.SET_UI_FLAG, { isCreating: false });
|
||||
}
|
||||
},
|
||||
|
||||
update: async ({ commit }, params) => {
|
||||
const portalId = params.id;
|
||||
commit(types.SET_HELP_PORTAL_UI_FLAG, {
|
||||
uiFlags: { isUpdating: true },
|
||||
portalId,
|
||||
});
|
||||
try {
|
||||
const { data } = await PortalsAPI.update(params);
|
||||
commit(types.UPDATE_PORTAL_ENTRY, data);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
commit(types.SET_HELP_PORTAL_UI_FLAG, {
|
||||
uiFlags: { isUpdating: false },
|
||||
portalId,
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
delete: async ({ commit }, portalId) => {
|
||||
commit(types.SET_HELP_PORTAL_UI_FLAG, {
|
||||
uiFlags: { isDeleting: true },
|
||||
portalId,
|
||||
});
|
||||
try {
|
||||
await PortalsAPI.delete(portalId);
|
||||
commit(types.REMOVE_PORTAL_ENTRY, portalId);
|
||||
commit(types.REMOVE_PORTAL_ID, portalId);
|
||||
} catch (error) {
|
||||
throwErrorMessage(error);
|
||||
} finally {
|
||||
commit(types.SET_HELP_PORTAL_UI_FLAG, {
|
||||
uiFlags: { isDeleting: false },
|
||||
portalId,
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user