Refactor question asking on profiles to use request.js
This commit is contained in:
parent
9c9f56e231
commit
dba817c8b6
|
@ -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 I18n from 'retrospring/i18n';
|
import I18n from 'retrospring/i18n';
|
||||||
|
|
||||||
|
@ -15,15 +15,17 @@ export function questionboxUserHandler(event: Event): void {
|
||||||
document.querySelector<HTMLInputElement>('textarea[name=qb-question]').readOnly = true;
|
document.querySelector<HTMLInputElement>('textarea[name=qb-question]').readOnly = true;
|
||||||
button.disabled = true;
|
button.disabled = true;
|
||||||
|
|
||||||
Rails.ajax({
|
post('/ajax/ask', {
|
||||||
url: '/ajax/ask',
|
body: {
|
||||||
type: 'POST',
|
|
||||||
data: new URLSearchParams({
|
|
||||||
rcpt: document.querySelector<HTMLInputElement>('input[name=qb-to]').value,
|
rcpt: document.querySelector<HTMLInputElement>('input[name=qb-to]').value,
|
||||||
question: document.querySelector<HTMLInputElement>('textarea[name=qb-question]').value,
|
question: document.querySelector<HTMLInputElement>('textarea[name=qb-question]').value,
|
||||||
anonymousQuestion: String(anonymousQuestion)
|
anonymousQuestion: String(anonymousQuestion)
|
||||||
}).toString(),
|
},
|
||||||
success: (data) => {
|
contentType: 'application/json'
|
||||||
|
})
|
||||||
|
.then(async response => {
|
||||||
|
const data = await response.json;
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
document.querySelector<HTMLInputElement>('textarea[name=qb-question]').value = '';
|
document.querySelector<HTMLInputElement>('textarea[name=qb-question]').value = '';
|
||||||
|
|
||||||
|
@ -37,16 +39,15 @@ export function questionboxUserHandler(event: Event): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
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(() => {
|
||||||
document.querySelector<HTMLInputElement>('textarea[name=qb-question]').readOnly = false;
|
document.querySelector<HTMLInputElement>('textarea[name=qb-question]').readOnly = false;
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function questionboxPromoteHandler(): void {
|
export function questionboxPromoteHandler(): void {
|
||||||
|
|
Loading…
Reference in New Issue