# Pull Request Template ## Description This PR incudes new Agent assignment policy index page with CRUD actions. Fixes https://linear.app/chatwoot/issue/CW-5570/feat-assignment-policy-index-page-with-actions ## Type of change - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? ### Loom https://www.loom.com/share/17ab5ceca4854f179628a3b53f347e5a?sid=cb64e881-57fd-4ae1-921b-7648653cca33 ### Screenshots **Light mode** <img width="1428" height="888" alt="image" src="https://github.com/user-attachments/assets/fdbb83e9-1f4f-4432-9e8a-4a8f1b810d31" /> **Dark mode** <img width="1428" height="888" alt="image" src="https://github.com/user-attachments/assets/f1fb38b9-1150-482c-ba62-3fe63ee1c7d4" /> <img width="726" height="495" alt="image" src="https://github.com/user-attachments/assets/90a6ad55-9ab6-4adb-93a7-2327f5f09c79" /> ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
157 lines
4.5 KiB
JavaScript
157 lines
4.5 KiB
JavaScript
import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
|
|
import types from '../mutation-types';
|
|
import AssignmentPoliciesAPI from '../../api/assignmentPolicies';
|
|
import { throwErrorMessage } from '../utils/api';
|
|
import camelcaseKeys from 'camelcase-keys';
|
|
|
|
export const state = {
|
|
records: [],
|
|
uiFlags: {
|
|
isFetching: false,
|
|
isFetchingItem: false,
|
|
isCreating: false,
|
|
isUpdating: false,
|
|
isDeleting: false,
|
|
},
|
|
inboxUiFlags: {
|
|
isFetching: false,
|
|
},
|
|
};
|
|
|
|
export const getters = {
|
|
getAssignmentPolicies(_state) {
|
|
return _state.records;
|
|
},
|
|
getUIFlags(_state) {
|
|
return _state.uiFlags;
|
|
},
|
|
getInboxUiFlags(_state) {
|
|
return _state.inboxUiFlags;
|
|
},
|
|
getAssignmentPolicyById: _state => id => {
|
|
return _state.records.find(record => record.id === Number(id)) || {};
|
|
},
|
|
};
|
|
|
|
export const actions = {
|
|
get: async function get({ commit }) {
|
|
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetching: true });
|
|
try {
|
|
const response = await AssignmentPoliciesAPI.get();
|
|
commit(types.SET_ASSIGNMENT_POLICIES, camelcaseKeys(response.data));
|
|
} catch (error) {
|
|
throwErrorMessage(error);
|
|
} finally {
|
|
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetching: false });
|
|
}
|
|
},
|
|
|
|
show: async function show({ commit }, policyId) {
|
|
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetchingItem: true });
|
|
try {
|
|
const response = await AssignmentPoliciesAPI.show(policyId);
|
|
const policy = camelcaseKeys(response.data);
|
|
commit(types.EDIT_ASSIGNMENT_POLICY, policy);
|
|
} catch (error) {
|
|
throwErrorMessage(error);
|
|
} finally {
|
|
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isFetchingItem: false });
|
|
}
|
|
},
|
|
|
|
create: async function create({ commit }, policyObj) {
|
|
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isCreating: true });
|
|
try {
|
|
const response = await AssignmentPoliciesAPI.create(policyObj);
|
|
commit(types.ADD_ASSIGNMENT_POLICY, camelcaseKeys(response.data));
|
|
return response.data;
|
|
} catch (error) {
|
|
throwErrorMessage(error);
|
|
throw error;
|
|
} finally {
|
|
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isCreating: false });
|
|
}
|
|
},
|
|
|
|
update: async function update({ commit }, { id, ...policyParams }) {
|
|
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isUpdating: true });
|
|
try {
|
|
const response = await AssignmentPoliciesAPI.update(id, policyParams);
|
|
commit(types.EDIT_ASSIGNMENT_POLICY, camelcaseKeys(response.data));
|
|
return response.data;
|
|
} catch (error) {
|
|
throwErrorMessage(error);
|
|
throw error;
|
|
} finally {
|
|
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isUpdating: false });
|
|
}
|
|
},
|
|
|
|
delete: async function deletePolicy({ commit }, policyId) {
|
|
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isDeleting: true });
|
|
try {
|
|
await AssignmentPoliciesAPI.delete(policyId);
|
|
commit(types.DELETE_ASSIGNMENT_POLICY, policyId);
|
|
} catch (error) {
|
|
throwErrorMessage(error);
|
|
throw error;
|
|
} finally {
|
|
commit(types.SET_ASSIGNMENT_POLICIES_UI_FLAG, { isDeleting: false });
|
|
}
|
|
},
|
|
|
|
getInboxes: async function getInboxes({ commit }, policyId) {
|
|
commit(types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, { isFetching: true });
|
|
try {
|
|
const response = await AssignmentPoliciesAPI.getInboxes(policyId);
|
|
commit(types.SET_ASSIGNMENT_POLICIES_INBOXES, {
|
|
policyId,
|
|
inboxes: camelcaseKeys(response.data.inboxes),
|
|
});
|
|
} catch (error) {
|
|
throwErrorMessage(error);
|
|
throw error;
|
|
} finally {
|
|
commit(types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG, {
|
|
isFetching: false,
|
|
});
|
|
}
|
|
},
|
|
};
|
|
|
|
export const mutations = {
|
|
[types.SET_ASSIGNMENT_POLICIES_UI_FLAG](_state, data) {
|
|
_state.uiFlags = {
|
|
..._state.uiFlags,
|
|
...data,
|
|
};
|
|
},
|
|
|
|
[types.SET_ASSIGNMENT_POLICIES]: MutationHelpers.set,
|
|
[types.ADD_ASSIGNMENT_POLICY]: MutationHelpers.create,
|
|
[types.EDIT_ASSIGNMENT_POLICY]: MutationHelpers.update,
|
|
[types.DELETE_ASSIGNMENT_POLICY]: MutationHelpers.destroy,
|
|
|
|
[types.SET_ASSIGNMENT_POLICIES_INBOXES_UI_FLAG](_state, data) {
|
|
_state.inboxUiFlags = {
|
|
..._state.inboxUiFlags,
|
|
...data,
|
|
};
|
|
},
|
|
|
|
[types.SET_ASSIGNMENT_POLICIES_INBOXES](_state, { policyId, inboxes }) {
|
|
const policy = _state.records.find(p => p.id === policyId);
|
|
if (policy) {
|
|
policy.inboxes = inboxes;
|
|
}
|
|
},
|
|
};
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state,
|
|
getters,
|
|
actions,
|
|
mutations,
|
|
};
|