From df63d76a8619ce939a9a2c6ec1c3ae92f7606529 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 15 Feb 2022 11:18:50 +0100 Subject: [PATCH] global mixin for toasting error and success --- frontend/src/main.js | 3 +++ frontend/src/mixins/toaster.js | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 frontend/src/mixins/toaster.js diff --git a/frontend/src/main.js b/frontend/src/main.js index 0b47a7564..25e417359 100755 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -3,6 +3,7 @@ import DashboardPlugin from './plugins/dashboard-plugin' import App from './App.vue' import i18n from './i18n.js' import { loadAllRules } from './validation-rules' +import { toasters } from './mixins/toaster' import 'regenerator-runtime' @@ -18,6 +19,8 @@ import { apolloProvider } from './plugins/apolloProvider' Vue.use(DashboardPlugin) Vue.config.productionTip = false +Vue.mixin(toasters) + Vue.toasted.register( 'error', (payload) => { diff --git a/frontend/src/mixins/toaster.js b/frontend/src/mixins/toaster.js new file mode 100644 index 000000000..ec1bcfc0a --- /dev/null +++ b/frontend/src/mixins/toaster.js @@ -0,0 +1,24 @@ +export const toasters = { + methods: { + toastSuccess(message) { + this.toast(message, { + title: this.$t('success'), + variant: 'danger', + }) + }, + toastError(message) { + this.toast(message, { + title: this.$t('error.error'), + variant: 'success', + }) + }, + toast(message, options) { + this.$bvToast.toast(message, { + autoHideDelay: 5000, + appendToast: false, + solid: true, + ...options, + }) + }, + }, +}