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,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: {},
};

View File

@@ -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,
};

View File

@@ -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
}