Refactor report removal to use request.js
This commit is contained in:
parent
389e1271d7
commit
fe6b6b198f
|
@ -1,4 +1,4 @@
|
||||||
import Rails from '@rails/ujs';
|
import { post } from '@rails/request.js';
|
||||||
import swal from 'sweetalert';
|
import swal from 'sweetalert';
|
||||||
|
|
||||||
import I18n from 'retrospring/i18n';
|
import I18n from 'retrospring/i18n';
|
||||||
|
@ -18,22 +18,24 @@ export function destroyReportHandler(event: Event): void {
|
||||||
cancelButtonText: I18n.translate('voc.cancel'),
|
cancelButtonText: I18n.translate('voc.cancel'),
|
||||||
closeOnConfirm: true
|
closeOnConfirm: true
|
||||||
}, () => {
|
}, () => {
|
||||||
Rails.ajax({
|
post('/ajax/mod/destroy_report', {
|
||||||
url: '/ajax/mod/destroy_report',
|
body: {
|
||||||
type: 'POST',
|
|
||||||
data: new URLSearchParams({
|
|
||||||
id: id
|
id: id
|
||||||
}).toString(),
|
},
|
||||||
success: (data) => {
|
contentType: 'application/json'
|
||||||
|
})
|
||||||
|
.then(async response => {
|
||||||
|
const data = await response.json;
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
document.querySelector(`.moderationbox[data-id="${id}"]`).remove();
|
document.querySelector(`.moderationbox[data-id="${id}"]`).remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
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'));
|
||||||
}
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue