feat: Add advanced contact filters (#3471)

Co-authored-by: Tejaswini <tejaswini@chatwoot.com>
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
Fayaz Ahmed
2021-12-03 08:42:44 +05:30
committed by GitHub
parent 1c29f5bbe4
commit d7cfe6858e
30 changed files with 716 additions and 43 deletions

View File

@@ -179,4 +179,27 @@ export const actions = {
commit(types.SET_CONTACT_UI_FLAG, { isUpdating: false });
}
},
filter: async ({ commit }, { page = 1, sortAttr, queryPayload } = {}) => {
commit(types.SET_CONTACT_UI_FLAG, { isFetching: true });
try {
const {
data: { payload, meta },
} = await ContactAPI.filter(page, sortAttr, queryPayload);
commit(types.CLEAR_CONTACTS);
commit(types.SET_CONTACTS, payload);
commit(types.SET_CONTACT_META, meta);
commit(types.SET_CONTACT_UI_FLAG, { isFetching: false });
} catch (error) {
commit(types.SET_CONTACT_UI_FLAG, { isFetching: false });
}
},
setContactFilters({ commit }, data) {
commit(types.SET_CONTACT_FILTERS, data);
},
clearContactFilters({ commit }) {
commit(types.CLEAR_CONTACT_FILTERS);
},
};

View File

@@ -12,4 +12,7 @@ export const getters = {
getMeta: $state => {
return $state.meta;
},
getAppliedContactFilters: _state => {
return _state.appliedFilters;
},
};

View File

@@ -17,6 +17,7 @@ const state = {
isDeleting: false,
},
sortOrder: [],
appliedFilters: [],
};
export default {

View File

@@ -66,4 +66,12 @@ export const mutations = {
}
});
},
[types.SET_CONTACT_FILTERS](_state, data) {
_state.appliedFilters = data;
},
[types.CLEAR_CONTACT_FILTERS](_state) {
_state.appliedFilters = [];
},
};