2020-01-21 13:12:44 +00:00
|
|
|
import Vue from 'vue';
|
|
|
|
import * as types from '../mutation-types';
|
|
|
|
import ConversationAPI from '../../api/conversations';
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
records: {},
|
|
|
|
uiFlags: {
|
|
|
|
isFetching: false,
|
2020-02-16 10:16:26 +00:00
|
|
|
isUpdating: false,
|
|
|
|
isError: false,
|
2020-01-21 13:12:44 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getters = {
|
|
|
|
getUIFlags($state) {
|
|
|
|
return $state.uiFlags;
|
|
|
|
},
|
|
|
|
getConversationLabels: $state => id => {
|
|
|
|
return $state.records[Number(id)] || [];
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export const actions = {
|
|
|
|
get: async ({ commit }, conversationId) => {
|
|
|
|
commit(types.default.SET_CONVERSATION_LABELS_UI_FLAG, {
|
|
|
|
isFetching: true,
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
const response = await ConversationAPI.getLabels(conversationId);
|
|
|
|
commit(types.default.SET_CONVERSATION_LABELS, {
|
|
|
|
id: conversationId,
|
|
|
|
data: response.data.payload,
|
|
|
|
});
|
|
|
|
commit(types.default.SET_CONVERSATION_LABELS_UI_FLAG, {
|
|
|
|
isFetching: false,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
commit(types.default.SET_CONVERSATION_LABELS_UI_FLAG, {
|
|
|
|
isFetching: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2020-02-16 10:16:26 +00:00
|
|
|
update: async ({ commit }, { conversationId, labels }) => {
|
|
|
|
commit(types.default.SET_CONVERSATION_LABELS_UI_FLAG, {
|
|
|
|
isUpdating: true,
|
|
|
|
});
|
|
|
|
try {
|
|
|
|
const response = await ConversationAPI.updateLabels(
|
|
|
|
conversationId,
|
|
|
|
labels
|
|
|
|
);
|
|
|
|
commit(types.default.SET_CONVERSATION_LABELS, {
|
|
|
|
id: conversationId,
|
|
|
|
data: response.data.payload,
|
|
|
|
});
|
|
|
|
commit(types.default.SET_CONVERSATION_LABELS_UI_FLAG, {
|
|
|
|
isUpdating: false,
|
|
|
|
isError: false,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
commit(types.default.SET_CONVERSATION_LABELS_UI_FLAG, {
|
|
|
|
isUpdating: false,
|
|
|
|
isError: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2020-01-21 13:12:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
[types.default.SET_CONVERSATION_LABELS_UI_FLAG]($state, data) {
|
|
|
|
$state.uiFlags = {
|
|
|
|
...$state.uiFlags,
|
|
|
|
...data,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
[types.default.SET_CONVERSATION_LABELS]: ($state, { id, data }) => {
|
|
|
|
Vue.set($state.records, id, data);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations,
|
|
|
|
};
|