Chore: Send browser language in webwidget events (#952)
Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
This commit is contained in:
@@ -1,15 +1,8 @@
|
||||
import Vue from 'vue';
|
||||
import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
|
||||
|
||||
const sendMessage = content => {
|
||||
const locale = Vue.config.lang;
|
||||
const refererURL = window.refererURL || '';
|
||||
let search = window.location.search;
|
||||
if (search) {
|
||||
search = `${search}&locale=${locale}`;
|
||||
} else {
|
||||
search = `?locale=${locale}`;
|
||||
}
|
||||
|
||||
const search = buildSearchParamsWithLocale(window.location.search);
|
||||
return {
|
||||
url: `/api/v1/widget/messages${search}`,
|
||||
params: {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { API } from 'widget/helpers/axios';
|
||||
import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
|
||||
|
||||
export default {
|
||||
create(name) {
|
||||
return API.post(`/api/v1/widget/events${window.location.search}`, { name });
|
||||
const search = buildSearchParamsWithLocale(window.location.search);
|
||||
return API.post(`/api/v1/widget/events${search}`, { name });
|
||||
},
|
||||
};
|
||||
|
||||
16
app/javascript/widget/helpers/specs/urlParamsHelper.spec.js
Normal file
16
app/javascript/widget/helpers/specs/urlParamsHelper.spec.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { buildSearchParamsWithLocale } from '../urlParamsHelper';
|
||||
|
||||
jest.mock('vue', () => ({
|
||||
config: {
|
||||
lang: 'el',
|
||||
},
|
||||
}));
|
||||
|
||||
describe('#buildSearchParamsWithLocale', () => {
|
||||
it('returns correct search params', () => {
|
||||
expect(buildSearchParamsWithLocale('?test=1234')).toEqual(
|
||||
'?test=1234&locale=el'
|
||||
);
|
||||
expect(buildSearchParamsWithLocale('')).toEqual('?locale=el');
|
||||
});
|
||||
});
|
||||
10
app/javascript/widget/helpers/urlParamsHelper.js
Normal file
10
app/javascript/widget/helpers/urlParamsHelper.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import Vue from 'vue';
|
||||
export const buildSearchParamsWithLocale = search => {
|
||||
const locale = Vue.config.lang;
|
||||
if (search) {
|
||||
search = `${search}&locale=${locale}`;
|
||||
} else {
|
||||
search = `?locale=${locale}`;
|
||||
}
|
||||
return search;
|
||||
};
|
||||
Reference in New Issue
Block a user