2018-09-07 10:32:28 -04:00
|
|
|
import $ from 'jquery';
|
|
|
|
import axios from './lib/utils/axios_utils';
|
2020-08-20 05:09:55 -04:00
|
|
|
import { deprecatedCreateFlash as Flash, hideFlash } from './flash';
|
2018-11-21 10:13:04 -05:00
|
|
|
import { parseBoolean } from './lib/utils/common_utils';
|
2019-05-07 08:00:52 -04:00
|
|
|
import { __ } from './locale';
|
2018-09-07 10:32:28 -04:00
|
|
|
|
|
|
|
export default () => {
|
2020-12-23 16:10:24 -05:00
|
|
|
$('body').on('click', '.js-usage-consent-action', (e) => {
|
2018-09-07 10:32:28 -04:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopImmediatePropagation(); // overwrite rails listener
|
|
|
|
|
|
|
|
const { url, checkEnabled, pingEnabled } = e.target.dataset;
|
|
|
|
const data = {
|
|
|
|
application_setting: {
|
2018-11-21 10:13:04 -05:00
|
|
|
version_check_enabled: parseBoolean(checkEnabled),
|
|
|
|
usage_ping_enabled: parseBoolean(pingEnabled),
|
2018-09-07 10:32:28 -04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const hideConsentMessage = () => hideFlash(document.querySelector('.ping-consent-message'));
|
|
|
|
|
2018-10-10 03:13:34 -04:00
|
|
|
axios
|
|
|
|
.put(url, data)
|
2018-09-07 10:32:28 -04:00
|
|
|
.then(() => {
|
|
|
|
hideConsentMessage();
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
hideConsentMessage();
|
2019-05-07 08:00:52 -04:00
|
|
|
Flash(__('Something went wrong. Try again later.'));
|
2018-09-07 10:32:28 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|