feat: Add chatwoot:error sdk event (#3998)
This commit is contained in:
1
app/javascript/widget/constants/errorTypes.js
Normal file
1
app/javascript/widget/constants/errorTypes.js
Normal file
@@ -0,0 +1 @@
|
||||
export const SET_USER_ERROR = 'SET_USER_ERROR';
|
||||
2
app/javascript/widget/constants/sdkEvents.js
Normal file
2
app/javascript/widget/constants/sdkEvents.js
Normal file
@@ -0,0 +1,2 @@
|
||||
export const CHATWOOT_ERROR = 'chatwoot:error';
|
||||
export const CHATWOOT_READY = 'chatwoot:ready';
|
||||
@@ -1,5 +1,6 @@
|
||||
import { IFrameHelper } from 'widget/helpers/utils';
|
||||
import ContactsAPI from '../../api/contacts';
|
||||
|
||||
import { SET_USER_ERROR } from '../../constants/errorTypes';
|
||||
const state = {
|
||||
currentUser: {},
|
||||
};
|
||||
@@ -38,7 +39,14 @@ export const actions = {
|
||||
dispatch('conversation/fetchOldConversations', {}, { root: true });
|
||||
}
|
||||
} catch (error) {
|
||||
// Ignore error
|
||||
const {
|
||||
response: { data },
|
||||
} = error;
|
||||
IFrameHelper.sendMessage({
|
||||
event: 'error',
|
||||
errorType: SET_USER_ERROR,
|
||||
data,
|
||||
});
|
||||
}
|
||||
},
|
||||
setCustomAttributes: async (_, customAttributes = {}) => {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { API } from 'widget/helpers/axios';
|
||||
import { actions } from '../../contacts';
|
||||
|
||||
const commit = jest.fn();
|
||||
const dispatch = jest.fn();
|
||||
jest.mock('widget/helpers/axios');
|
||||
|
||||
describe('#actions', () => {
|
||||
@@ -11,11 +12,16 @@ describe('#actions', () => {
|
||||
email: 'thoma@sphadikam.com',
|
||||
name: 'Adu Thoma',
|
||||
avatar_url: '',
|
||||
identifier_hash: 'malana_hash',
|
||||
identifier_hash: 'random_hex_identifier_hash',
|
||||
};
|
||||
API.patch.mockResolvedValue({ data: { pubsub_token: 'token' } });
|
||||
await actions.update({ commit }, { identifier: 1, user });
|
||||
await actions.update({ commit, dispatch }, { identifier: 1, user });
|
||||
expect(commit.mock.calls).toEqual([]);
|
||||
expect(dispatch.mock.calls).toEqual([
|
||||
['get'],
|
||||
['conversation/clearConversations', {}, { root: true }],
|
||||
['conversation/fetchOldConversations', {}, { root: true }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user