Refactor inbox deleting to use request.js
This commit is contained in:
parent
eb0271210b
commit
f55efbb017
|
@ -1,4 +1,4 @@
|
|||
import Rails from '@rails/ujs';
|
||||
import { post } from '@rails/request.js';
|
||||
import swal from 'sweetalert';
|
||||
|
||||
import I18n from 'retrospring/i18n';
|
||||
|
@ -43,20 +43,18 @@ export function deleteAllQuestionsHandler(event: Event): void {
|
|||
return;
|
||||
}
|
||||
|
||||
Rails.ajax({
|
||||
url: '/ajax/delete_all_inbox',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
success: (data) => {
|
||||
post('/ajax/delete_all_inbox')
|
||||
.then(async response => {
|
||||
const data = await response.json;
|
||||
|
||||
if (!data.success) return false;
|
||||
|
||||
updateDeleteButton(false);
|
||||
document.querySelector('#entries').innerHTML = 'Nothing to see here!';
|
||||
},
|
||||
error: (data, status, xhr) => {
|
||||
console.log(data, status, xhr);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -77,20 +75,18 @@ export function deleteAllAuthorQuestionsHandler(event: Event): void {
|
|||
}, (returnValue) => {
|
||||
if (returnValue === null) return false;
|
||||
|
||||
Rails.ajax({
|
||||
url: `/ajax/delete_all_inbox/${location.pathname.split('/')[2]}`,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
success: (data) => {
|
||||
post(`/ajax/delete_all_inbox/${location.pathname.split('/')[2]}`)
|
||||
.then(async response => {
|
||||
const data = await response.json;
|
||||
|
||||
if (!data.success) return false;
|
||||
|
||||
updateDeleteButton(false);
|
||||
document.querySelector('#entries').innerHTML = 'Nothing to see here!';
|
||||
},
|
||||
error: (data, status, xhr) => {
|
||||
console.log(data, status, xhr);
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue