Use notification helpers instead of window reference everywhere

This commit is contained in:
Andreas Nedbal 2022-01-03 04:31:41 +01:00 committed by Andreas Nedbal
parent 0770dbfc21
commit 2e5f500d24
4 changed files with 12 additions and 8 deletions

View File

@ -1,4 +1,5 @@
import Rails from '@rails/ujs'; import Rails from '@rails/ujs';
import { showNotification, showErrorNotification } from 'utilities/notifications';
import I18n from '../../../legacy/i18n'; import I18n from '../../../legacy/i18n';
export function createListHandler(event: Event): void { export function createListHandler(event: Event): void {
@ -17,11 +18,11 @@ export function createListHandler(event: Event): void {
document.querySelector('#lists-list ul.list-group').insertAdjacentHTML('beforeend', data.render); document.querySelector('#lists-list ul.list-group').insertAdjacentHTML('beforeend', data.render);
} }
window['showNotification'](data.message, data.success); showNotification(data.message, data.success);
}, },
error: (data, status, xhr) => { error: (data, status, xhr) => {
console.log(data, status, xhr); console.log(data, status, xhr);
window['showNotification'](I18n.translate('frontend.error.message'), false); showErrorNotification(I18n.translate('frontend.error.message'));
} }
}); });
} }

View File

@ -1,5 +1,6 @@
import Rails from '@rails/ujs'; import Rails from '@rails/ujs';
import swal from 'sweetalert'; import swal from 'sweetalert';
import { showNotification, showErrorNotification } from 'utilities/notifications';
import I18n from '../../../legacy/i18n'; import I18n from '../../../legacy/i18n';
export function destroyListHandler(event: Event): void { export function destroyListHandler(event: Event): void {
@ -32,11 +33,11 @@ export function destroyListHandler(event: Event): void {
} }
} }
window['showNotification'](data.message, data.success); showNotification(data.message, data.success);
}, },
error: (data, status, xhr) => { error: (data, status, xhr) => {
console.log(data, status, xhr); console.log(data, status, xhr);
window['showNotification'](I18n.translate('frontend.error.message'), false); showErrorNotification(I18n.translate('frontend.error.message'));
} }
}); });
}); });

View File

@ -1,4 +1,5 @@
import Rails from '@rails/ujs'; import Rails from '@rails/ujs';
import { showNotification, showErrorNotification } from 'utilities/notifications';
import I18n from '../../../legacy/i18n'; import I18n from '../../../legacy/i18n';
export function listMembershipHandler(event: Event): void { export function listMembershipHandler(event: Event): void {
@ -24,11 +25,11 @@ export function listMembershipHandler(event: Event): void {
document.querySelector(`span#${list}-members`).innerHTML = memberCount.toString(); document.querySelector(`span#${list}-members`).innerHTML = memberCount.toString();
} }
window['showNotification'](data.message, data.success); showNotification(data.message, data.success);
}, },
error: (data, status, xhr) => { error: (data, status, xhr) => {
console.log(data, status, xhr); console.log(data, status, xhr);
window['showNotification'](I18n.translate('frontend.error.message'), false); showErrorNotification(I18n.translate('frontend.error.message'));
}, },
complete: () => { complete: () => {
checkbox.removeAttribute('disabled'); checkbox.removeAttribute('disabled');

View File

@ -1,4 +1,5 @@
import Rails from '@rails/ujs'; import Rails from '@rails/ujs';
import { showNotification, showErrorNotification } from 'utilities/notifications';
import I18n from '../../../legacy/i18n'; import I18n from '../../../legacy/i18n';
export function userActionHandler(event: Event): void { export function userActionHandler(event: Event): void {
@ -17,11 +18,11 @@ export function userActionHandler(event: Event): void {
}).toString(), }).toString(),
success: (data) => { success: (data) => {
success = data.success; success = data.success;
window['showNotification'](data.message, data.success); showNotification(data.message, data.success);
}, },
error: (data, status, xhr) => { error: (data, status, xhr) => {
console.log(data, status, xhr); console.log(data, status, xhr);
window['showNotification'](I18n.translate('frontend.error.message'), false); showErrorNotification(I18n.translate('frontend.error.message'));
}, },
complete: () => { complete: () => {
if (!success) return; if (!success) return;