2020-04-10 11:12:37 +00:00
|
|
|
import MessageAPI from '../../api/message';
|
2020-01-09 07:36:40 +00:00
|
|
|
|
|
|
|
const state = {
|
|
|
|
uiFlags: {
|
|
|
|
isUpdating: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-07-13 06:01:21 +00:00
|
|
|
export const getters = {
|
2020-01-09 07:36:40 +00:00
|
|
|
getUIFlags: $state => $state.uiFlags,
|
|
|
|
};
|
|
|
|
|
2021-07-13 06:01:21 +00:00
|
|
|
export const actions = {
|
|
|
|
update: async (
|
|
|
|
{ commit, dispatch },
|
|
|
|
{ email, messageId, submittedValues }
|
|
|
|
) => {
|
2020-01-09 07:36:40 +00:00
|
|
|
commit('toggleUpdateStatus', true);
|
|
|
|
try {
|
2021-11-22 18:02:17 +00:00
|
|
|
await MessageAPI.update({
|
2020-04-10 11:12:37 +00:00
|
|
|
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 }
|
|
|
|
);
|
2021-07-13 06:01:21 +00:00
|
|
|
dispatch('contacts/get', {}, { root: true });
|
2020-01-09 07:36:40 +00:00
|
|
|
} catch (error) {
|
|
|
|
// Ignore error
|
|
|
|
}
|
|
|
|
commit('toggleUpdateStatus', false);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-07-13 06:01:21 +00:00
|
|
|
export const mutations = {
|
2020-01-09 07:36:40 +00:00
|
|
|
toggleUpdateStatus($state, status) {
|
|
|
|
$state.uiFlags.isUpdating = status;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
namespaced: true,
|
|
|
|
state,
|
|
|
|
getters,
|
|
|
|
actions,
|
|
|
|
mutations,
|
|
|
|
};
|