Refactor answer smile to use request.js
This commit is contained in:
parent
508c7e844b
commit
0aff344581
|
@ -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';
|
||||||
|
@ -22,25 +22,27 @@ export function answerboxSmileHandler(event: Event): void {
|
||||||
|
|
||||||
button.disabled = true;
|
button.disabled = true;
|
||||||
|
|
||||||
Rails.ajax({
|
post(targetUrl, {
|
||||||
url: targetUrl,
|
body: {
|
||||||
type: 'POST',
|
|
||||||
data: new URLSearchParams({
|
|
||||||
id: id
|
id: id
|
||||||
}).toString(),
|
},
|
||||||
success: (data) => {
|
contentType: 'application/json'
|
||||||
|
})
|
||||||
|
.then(async response => {
|
||||||
|
const data = await response.json;
|
||||||
|
|
||||||
success = data.success;
|
success = data.success;
|
||||||
if (success) {
|
if (success) {
|
||||||
document.querySelector(`#ab-smile-count-${id}`).innerHTML = String(count);
|
document.querySelector(`#ab-smile-count-${id}`).innerHTML = String(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
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'));
|
||||||
},
|
})
|
||||||
complete: () => {
|
.finally(() => {
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
@ -53,6 +55,5 @@ export function answerboxSmileHandler(event: Event): void {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
Loading…
Reference in New Issue