Refactor user privilege changing to use request.js
This commit is contained in:
parent
fe6b6b198f
commit
918c514f12
|
@ -1,4 +1,4 @@
|
||||||
import Rails from '@rails/ujs';
|
import { post } from '@rails/request.js';
|
||||||
|
|
||||||
import I18n from 'retrospring/i18n';
|
import I18n from 'retrospring/i18n';
|
||||||
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
||||||
|
@ -9,29 +9,29 @@ export function privilegeCheckHandler(event: Event): void {
|
||||||
|
|
||||||
const privilegeType = checkbox.dataset.type;
|
const privilegeType = checkbox.dataset.type;
|
||||||
|
|
||||||
Rails.ajax({
|
post('/ajax/mod/privilege', {
|
||||||
url: '/ajax/mod/privilege',
|
body: {
|
||||||
type: 'POST',
|
|
||||||
data: new URLSearchParams({
|
|
||||||
user: checkbox.dataset.user,
|
user: checkbox.dataset.user,
|
||||||
type: privilegeType,
|
type: privilegeType,
|
||||||
status: String(checkbox.checked)
|
status: String(checkbox.checked)
|
||||||
}).toString(),
|
},
|
||||||
success: (data) => {
|
contentType: 'application/json'
|
||||||
|
})
|
||||||
|
.then(async response => {
|
||||||
|
const data = await response.json;
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
checkbox.checked = data.checked;
|
checkbox.checked = data.checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
showNotification(data.message, data.success);
|
showNotification(data.message, data.success);
|
||||||
},
|
})
|
||||||
error: (data, status, xhr) => {
|
.catch(err => {
|
||||||
console.log(data, status, xhr);
|
console.log(err);
|
||||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||||
checkbox.checked = false;
|
checkbox.checked = false;
|
||||||
},
|
})
|
||||||
complete: () => {
|
.finally(() => {
|
||||||
checkbox.disabled = false;
|
checkbox.disabled = false;
|
||||||
}
|
});
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue