2018-09-07 10:32:28 -04:00
|
|
|
import $ from 'jquery';
|
2021-06-20 23:10:27 -04:00
|
|
|
import createFlash, { hideFlash } from './flash';
|
2021-02-14 13:09:20 -05:00
|
|
|
import axios from './lib/utils/axios_utils';
|
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 () => {
|
2021-06-29 08:08:48 -04:00
|
|
|
$('body').on('click', '.js-service-ping-consent-action', (e) => {
|
2018-09-07 10:32:28 -04:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopImmediatePropagation(); // overwrite rails listener
|
|
|
|
|
2021-06-29 08:08:48 -04:00
|
|
|
const { url, checkEnabled, servicePingEnabled } = e.target.dataset;
|
2018-09-07 10:32:28 -04:00
|
|
|
const data = {
|
|
|
|
application_setting: {
|
2018-11-21 10:13:04 -05:00
|
|
|
version_check_enabled: parseBoolean(checkEnabled),
|
2021-06-29 08:08:48 -04:00
|
|
|
service_ping_enabled: parseBoolean(servicePingEnabled),
|
2018-09-07 10:32:28 -04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-06-29 08:08:48 -04:00
|
|
|
const hideConsentMessage = () =>
|
|
|
|
hideFlash(document.querySelector('.service-ping-consent-message'));
|
2018-09-07 10:32:28 -04:00
|
|
|
|
2018-10-10 03:13:34 -04:00
|
|
|
axios
|
|
|
|
.put(url, data)
|
2018-09-07 10:32:28 -04:00
|
|
|
.then(() => {
|
|
|
|
hideConsentMessage();
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
hideConsentMessage();
|
2021-06-20 23:10:27 -04:00
|
|
|
createFlash({
|
|
|
|
message: __('Something went wrong. Try again later.'),
|
|
|
|
});
|
2018-09-07 10:32:28 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|