2020-04-03 07:34:58 +00:00
|
|
|
import MessageAPI from 'widget/api/message';
|
|
|
|
import { refreshActionCableConnector } from '../../helpers/actionCable';
|
2020-01-09 07:36:40 +00:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
uiFlags: {
|
|
|
|
isUpdating: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const getters = {
|
|
|
|
getUIFlags: $state => $state.uiFlags,
|
|
|
|
};
|
|
|
|
|
|
|
|
const actions = {
|
|
|
|
updateContactAttributes: async ({ commit }, { email, messageId }) => {
|
|
|
|
commit('toggleUpdateStatus', true);
|
|
|
|
try {
|
2020-04-03 07:34:58 +00:00
|
|
|
const {
|
|
|
|
data: {
|
|
|
|
contact: { pubsub_token: pubsubToken },
|
|
|
|
},
|
|
|
|
} = await MessageAPI.update({ email, messageId });
|
2020-01-09 07:36:40 +00:00
|
|
|
commit(
|
|
|
|
'conversation/updateMessage',
|
|
|
|
{
|
|
|
|
id: messageId,
|
|
|
|
content_attributes: { submitted_email: email },
|
|
|
|
},
|
|
|
|
{ root: true }
|
|
|
|
);
|
2020-04-03 07:34:58 +00:00
|
|
|
refreshActionCableConnector(pubsubToken);
|
2020-01-09 07:36:40 +00:00
|
|
|
} catch (error) {
|
|
|
|
// Ignore error
|
|
|
|
}
|
|
|
|
commit('toggleUpdateStatus', false);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const mutations = {
|
|
|
|
toggleUpdateStatus($state, status) {
|
|
|
|
$state.uiFlags.isUpdating = status;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations,
|
|
|
|
};
|