debian-mirror-gitlab/app/assets/javascripts/service_ping_consent.js

36 lines
1,015 B
JavaScript
Raw Normal View History

2018-11-20 20:47:30 +05:30
import $ from 'jquery';
2023-05-27 22:25:52 +05:30
import { createAlert } from '~/alert';
2021-03-11 19:13:27 +05:30
import axios from './lib/utils/axios_utils';
2019-02-15 15:39:39 +05:30
import { parseBoolean } from './lib/utils/common_utils';
2019-09-04 21:01:54 +05:30
import { __ } from './locale';
2018-11-20 20:47:30 +05:30
export default () => {
2021-09-30 23:02:18 +05:30
$('body').on('click', '.js-service-ping-consent-action', (e) => {
2018-11-20 20:47:30 +05:30
e.preventDefault();
e.stopImmediatePropagation(); // overwrite rails listener
2021-09-30 23:02:18 +05:30
const { url, checkEnabled, servicePingEnabled } = e.target.dataset;
2018-11-20 20:47:30 +05:30
const data = {
application_setting: {
2019-02-15 15:39:39 +05:30
version_check_enabled: parseBoolean(checkEnabled),
2021-09-30 23:02:18 +05:30
service_ping_enabled: parseBoolean(servicePingEnabled),
2018-11-20 20:47:30 +05:30
},
};
2021-09-30 23:02:18 +05:30
const hideConsentMessage = () =>
2023-04-23 21:23:45 +05:30
document.querySelector('.service-ping-consent-message .js-close')?.click();
2018-11-20 20:47:30 +05:30
2018-12-13 13:39:08 +05:30
axios
.put(url, data)
2018-11-20 20:47:30 +05:30
.then(() => {
hideConsentMessage();
})
.catch(() => {
hideConsentMessage();
2022-11-25 23:54:43 +05:30
createAlert({
2021-09-30 23:02:18 +05:30
message: __('Something went wrong. Try again later.'),
});
2018-11-20 20:47:30 +05:30
});
});
};