Feature: Website SDK (#653)
Add SDK functions Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
28
app/javascript/widget/store/modules/contacts.js
Normal file
28
app/javascript/widget/store/modules/contacts.js
Normal 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: {},
|
||||
};
|
||||
32
app/javascript/widget/store/modules/conversationLabels.js
Normal file
32
app/javascript/widget/store/modules/conversationLabels.js
Normal 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,
|
||||
};
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user