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
co-authored by Sojan
parent 7fcd2d0e85
commit cb22b396eb
38 changed files with 734 additions and 262 deletions
+10 -6
View File
@@ -1,17 +1,21 @@
import Vue from 'vue';
import Vuex from 'vuex';
import appConfig from 'widget/store/modules/appConfig';
import contact from 'widget/store/modules/contact';
import conversation from 'widget/store/modules/conversation';
import agent from 'widget/store/modules/agent';
import appConfig from 'widget/store/modules/appConfig';
import contacts from 'widget/store/modules/contacts';
import conversation from 'widget/store/modules/conversation';
import conversationLabels from 'widget/store/modules/conversationLabels';
import message from 'widget/store/modules/message';
Vue.use(Vuex);
export default new Vuex.Store({
modules: {
appConfig,
contact,
conversation,
agent,
appConfig,
message,
contacts,
conversation,
conversationLabels,
},
});
@@ -0,0 +1,28 @@
import ContactsAPI from '../../api/contacts';
import { refreshActionCableConnector } from '../../helpers/actionCable';
export const actions = {
update: async (_, { identifier, user: userObject }) => {
try {
const user = {
email: userObject.email,
name: userObject.name,
avatar_url: userObject.avatar_url,
};
const {
data: { pubsub_token: pubsubToken },
} = await ContactsAPI.update(identifier, user);
refreshActionCableConnector(pubsubToken);
} catch (error) {
// Ingore error
}
},
};
export default {
namespaced: true,
state: {},
getters: {},
actions,
mutations: {},
};
@@ -0,0 +1,32 @@
import conversationLabels from '../../api/conversationLabels';
const state = {};
export const getters = {};
export const actions = {
create: async (_, label) => {
try {
await conversationLabels.create(label);
} catch (error) {
// Ingore error
}
},
destroy: async (_, label) => {
try {
await conversationLabels.destroy(label);
} catch (error) {
// Ingore error
}
},
};
export const mutations = {};
export default {
namespaced: true,
state,
getters,
actions,
mutations,
};
@@ -1,4 +1,5 @@
import { updateContact } from 'widget/api/contact';
import MessageAPI from 'widget/api/message';
import { refreshActionCableConnector } from '../../helpers/actionCable';
const state = {
uiFlags: {
@@ -14,7 +15,11 @@ const actions = {
updateContactAttributes: async ({ commit }, { email, messageId }) => {
commit('toggleUpdateStatus', true);
try {
await updateContact({ email, messageId });
const {
data: {
contact: { pubsub_token: pubsubToken },
},
} = await MessageAPI.update({ email, messageId });
commit(
'conversation/updateMessage',
{
@@ -23,6 +28,7 @@ const actions = {
},
{ root: true }
);
refreshActionCableConnector(pubsubToken);
} catch (error) {
// Ignore error
}