Refactor inbox answering to use request.js
This commit is contained in:
parent
f55efbb017
commit
a893d11aa1
|
@ -1,4 +1,4 @@
|
||||||
import Rails from '@rails/ujs';
|
import { post } from '@rails/request.js';
|
||||||
|
|
||||||
import { updateDeleteButton } from '../delete';
|
import { updateDeleteButton } from '../delete';
|
||||||
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
||||||
|
@ -22,11 +22,13 @@ export function answerEntryHandler(event: Event): void {
|
||||||
inbox: 'true'
|
inbox: 'true'
|
||||||
};
|
};
|
||||||
|
|
||||||
Rails.ajax({
|
post('/ajax/answer', {
|
||||||
url: '/ajax/answer',
|
body: data,
|
||||||
type: 'POST',
|
contentType: 'application/json'
|
||||||
data: new URLSearchParams(data).toString(),
|
})
|
||||||
success: (data) => {
|
.then(async response => {
|
||||||
|
const data = await response.json;
|
||||||
|
|
||||||
if (!data.success) {
|
if (!data.success) {
|
||||||
showErrorNotification(data.message);
|
showErrorNotification(data.message);
|
||||||
element.disabled = false;
|
element.disabled = false;
|
||||||
|
@ -35,11 +37,10 @@ export function answerEntryHandler(event: Event): void {
|
||||||
updateDeleteButton(false);
|
updateDeleteButton(false);
|
||||||
showNotification(data.message);
|
showNotification(data.message);
|
||||||
(inboxEntry as HTMLElement).remove();
|
(inboxEntry as HTMLElement).remove();
|
||||||
},
|
})
|
||||||
error: (data, status, xhr) => {
|
.catch(err => {
|
||||||
console.log(data, status, xhr);
|
console.log(err);
|
||||||
element.disabled = false;
|
element.disabled = false;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue