mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-29 18:22:53 +00:00
Fixes https://github.com/chatwoot/chatwoot/issues/8436 Fixes https://github.com/chatwoot/chatwoot/issues/9767 Fixes https://github.com/chatwoot/chatwoot/issues/10156 Fixes https://github.com/chatwoot/chatwoot/issues/6031 Fixes https://github.com/chatwoot/chatwoot/issues/5696 Fixes https://github.com/chatwoot/chatwoot/issues/9250 Fixes https://github.com/chatwoot/chatwoot/issues/9762 --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
91 lines
2.0 KiB
JavaScript
91 lines
2.0 KiB
JavaScript
import types from '../mutation-types';
|
|
import ContactAPI from '../../api/contacts';
|
|
|
|
const state = {
|
|
records: {},
|
|
uiFlags: {
|
|
isFetching: false,
|
|
isUpdating: false,
|
|
isError: false,
|
|
},
|
|
};
|
|
|
|
export const getters = {
|
|
getUIFlags($state) {
|
|
return $state.uiFlags;
|
|
},
|
|
getContactLabels: $state => id => {
|
|
return $state.records[Number(id)] || [];
|
|
},
|
|
};
|
|
|
|
export const actions = {
|
|
get: async ({ commit }, contactId) => {
|
|
commit(types.SET_CONTACT_LABELS_UI_FLAG, {
|
|
isFetching: true,
|
|
});
|
|
try {
|
|
const response = await ContactAPI.getContactLabels(contactId);
|
|
commit(types.SET_CONTACT_LABELS, {
|
|
id: contactId,
|
|
data: response.data.payload,
|
|
});
|
|
commit(types.SET_CONTACT_LABELS_UI_FLAG, {
|
|
isFetching: false,
|
|
});
|
|
} catch (error) {
|
|
commit(types.SET_CONTACT_LABELS_UI_FLAG, {
|
|
isFetching: false,
|
|
});
|
|
}
|
|
},
|
|
update: async ({ commit }, { contactId, labels }) => {
|
|
commit(types.SET_CONTACT_LABELS_UI_FLAG, {
|
|
isUpdating: true,
|
|
});
|
|
try {
|
|
const response = await ContactAPI.updateContactLabels(contactId, labels);
|
|
commit(types.SET_CONTACT_LABELS, {
|
|
id: contactId,
|
|
data: response.data.payload,
|
|
});
|
|
commit(types.SET_CONTACT_LABELS_UI_FLAG, {
|
|
isUpdating: false,
|
|
isError: false,
|
|
});
|
|
} catch (error) {
|
|
commit(types.SET_CONTACT_LABELS_UI_FLAG, {
|
|
isUpdating: false,
|
|
isError: true,
|
|
});
|
|
throw new Error(error);
|
|
}
|
|
},
|
|
setContactLabel({ commit }, { id, data }) {
|
|
commit(types.SET_CONTACT_LABELS, { id, data });
|
|
},
|
|
};
|
|
|
|
export const mutations = {
|
|
[types.SET_CONTACT_LABELS_UI_FLAG]($state, data) {
|
|
$state.uiFlags = {
|
|
...$state.uiFlags,
|
|
...data,
|
|
};
|
|
},
|
|
[types.SET_CONTACT_LABELS]: ($state, { id, data }) => {
|
|
$state.records = {
|
|
...$state.records,
|
|
[id]: data,
|
|
};
|
|
},
|
|
};
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state,
|
|
getters,
|
|
actions,
|
|
mutations,
|
|
};
|