Feature: Website SDK (#653)

Add SDK functions

Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
Pranav Raj S
2020-04-03 13:04:58 +05:30
committed by GitHub
parent 7fcd2d0e85
commit cb22b396eb
38 changed files with 734 additions and 262 deletions

View File

@@ -0,0 +1,51 @@
import MessageAPI from 'widget/api/message';
import { refreshActionCableConnector } from '../../helpers/actionCable';
const state = {
uiFlags: {
isUpdating: false,
},
};
const getters = {
getUIFlags: $state => $state.uiFlags,
};
const actions = {
updateContactAttributes: async ({ commit }, { email, messageId }) => {
commit('toggleUpdateStatus', true);
try {
const {
data: {
contact: { pubsub_token: pubsubToken },
},
} = await MessageAPI.update({ email, messageId });
commit(
'conversation/updateMessage',
{
id: messageId,
content_attributes: { submitted_email: email },
},
{ root: true }
);
refreshActionCableConnector(pubsubToken);
} catch (error) {
// Ignore error
}
commit('toggleUpdateStatus', false);
},
};
const mutations = {
toggleUpdateStatus($state, status) {
$state.uiFlags.isUpdating = status;
},
};
export default {
namespaced: true,
state,
getters,
actions,
mutations,
};