2020-04-10 11:12:37 +00:00
|
|
|
import MessageAPI from '../../api/message';
|
2020-04-03 07:34:58 +00:00
|
|
|
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 = {
|
2020-04-10 11:12:37 +00:00
|
|
|
update: async ({ commit }, { email, messageId, submittedValues }) => {
|
2020-01-09 07:36:40 +00:00
|
|
|
commit('toggleUpdateStatus', true);
|
|
|
|
try {
|
2020-04-03 07:34:58 +00:00
|
|
|
const {
|
2020-04-10 11:12:37 +00:00
|
|
|
data: { contact: { pubsub_token: pubsubToken } = {} },
|
|
|
|
} = await MessageAPI.update({
|
|
|
|
email,
|
|
|
|
messageId,
|
|
|
|
values: submittedValues,
|
|
|
|
});
|
2020-01-09 07:36:40 +00:00
|
|
|
commit(
|
|
|
|
'conversation/updateMessage',
|
|
|
|
{
|
|
|
|
id: messageId,
|
2020-04-10 11:12:37 +00:00
|
|
|
content_attributes: {
|
|
|
|
submitted_email: email,
|
|
|
|
submitted_values: email ? null : submittedValues,
|
|
|
|
},
|
2020-01-09 07:36:40 +00:00
|
|
|
},
|
|
|
|
{ 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,
|
|
|
|
};
|