Refactor answer destroy to use request.js
This commit is contained in:
parent
5ea28e1830
commit
508c7e844b
|
@ -1,4 +1,4 @@
|
||||||
import Rails from '@rails/ujs';
|
import { post } from '@rails/request.js';
|
||||||
import { showErrorNotification, showNotification } from 'utilities/notifications';
|
import { showErrorNotification, showNotification } from 'utilities/notifications';
|
||||||
import swal from 'sweetalert';
|
import swal from 'sweetalert';
|
||||||
|
|
||||||
|
@ -24,23 +24,24 @@ export function answerboxDestroyHandler(event: Event): void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rails.ajax({
|
post('/ajax/destroy_answer', {
|
||||||
url: '/ajax/destroy_answer',
|
body: {
|
||||||
type: 'POST',
|
|
||||||
data: new URLSearchParams({
|
|
||||||
answer: answerId
|
answer: answerId
|
||||||
}).toString(),
|
},
|
||||||
success: (data) => {
|
contentType: 'application/json'
|
||||||
|
})
|
||||||
|
.then(async response => {
|
||||||
|
const data = await response.json;
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
document.querySelector(`.answerbox[data-id="${answerId}"]`).remove();
|
document.querySelector(`.answerbox[data-id="${answerId}"]`).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