diff --git a/package.json b/package.json index 477ce09c..d02ec5de 100644 --- a/package.json +++ b/package.json @@ -34,14 +34,13 @@ "lodash": "^4.17.13", "moment": "^2.29.1", "sweet-modal-vue": "^2.0.0", - "sweetalert": "^2.1.2", "tailwindcss": "^2.0.1", - "toastr": "^2.1.4", "v-tooltip": "^2.0.2", "vue": "^2.6.10", "vue-i18n": "^8.22.0", "vue-loader": "^15.9.3", "vue-router": "2.7.0", + "vue-sweetalert2": "^4.2.1", "vue2-transitions": "^0.3.0", "vuedraggable": "^2.24.2", "vuelidate": "^0.6.2", diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 244da98f..622bf512 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -8,7 +8,6 @@ import router from './router.js' import store from './store/index' import utils from './helpers/utilities' import i18n from './plugins/i18n' -import swal from 'sweetalert' require('./bootstrap') @@ -27,5 +26,4 @@ new Vue({ router, store, i18n, - swal, }).$mount('#app') diff --git a/resources/assets/js/bootstrap.js b/resources/assets/js/bootstrap.js index bb10eaea..956283ec 100644 --- a/resources/assets/js/bootstrap.js +++ b/resources/assets/js/bootstrap.js @@ -8,6 +8,8 @@ import money from 'v-money' import VTooltip from 'v-tooltip' import Transitions from 'vue2-transitions' import SpaceWind from '@bytefury/spacewind' +import swal from 'vue-sweetalert2' +import 'sweetalert2/dist/sweetalert2.min.css' /** * Theme @@ -22,6 +24,33 @@ Vue.use(SpaceWind, { theme }) Vue.use(Vuelidate) +Vue.use(swal, { + customClass: { + container: + 'fixed z-50 inset-0 overflow-y-auto bg-black bg-opacity-25 flex justify-center min-h-screen items-center sm:p-0 swal2-container', + popup: + 'flex items-center flex-col justify-center align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full sm:p-6', + header: 'swal2-header', + title: 'swal2-title', + closeButton: '', + icon: 'swal2-icon', + image: '', + content: 'swal2-content', + input: '', + inputLabel: '', + validationMessage: '', + actions: 'swal2-actions', + confirmButton: + 'w-full inline-flex py-2 px-4 text-sm leading-5 rounded items-center justify-center text-white font-normal transition duration-150 ease-in-out border border-transparent focus:outline-none bg-primary-500 hover:bg-opacity-75 whitespace-nowrap', + denyButton: '', + cancelButton: + 'w-full inline-flex py-2 px-4 text-sm leading-5 rounded justify-center items-center focus:outline-none font-normal transition ease-in-out duration-150 border border-transparent border border-solid border-primary-500 text-primary-500 hover:bg-primary-200 shadow-inner whitespace-nowrap', + loader: '', + footer: '', + }, + buttonsStyling: false, +}) + Vue.use(Transitions) window._ = require('lodash') @@ -89,10 +118,11 @@ global.axios.interceptors.response.use(undefined, function (err) { return true } if (!err.response) { - window.toastr['error']( - 'Please check your internet connection or wait until servers are back online', - 'Network Error' - ) + store.dispatch('notification/showNotification', { + type: 'error', + message: + 'Please check your internet connection or wait until servers are back online.', + }) } else { if ( err.response.data && @@ -100,24 +130,30 @@ global.axios.interceptors.response.use(undefined, function (err) { err.response.data === ' Unauthorized.') ) { // Unauthorized and log out - window.toastr['error']( - err.response.data.message ? err.response.data.message : 'Unauthorized' - ) + store.dispatch('notification/showNotification', { + type: 'error', + message: err.response.data.message + ? err.response.data.message + : 'Unauthorized', + }) store.dispatch('auth/logout', true) } else if (err.response.data.errors) { // Show a notification per error const errors = JSON.parse(JSON.stringify(err.response.data.errors)) for (const i in errors) { - window.toastr['error'](errors[i]) + store.dispatch('notification/showNotification', { + type: 'error', + message: errors[i], + }) } } else { // Unknown error - window.toastr['error']( - err.response.data.message + store.dispatch('notification/showNotification', { + type: 'error', + message: err.response.data.message ? err.response.data.message : err.response.data || 'Unknown error occurred', - 'Error' - ) + }) } } return Promise.reject(err) @@ -126,8 +162,6 @@ global.axios.interceptors.response.use(undefined, function (err) { /** * Global plugins */ -window.toastr = require('toastr') - Vue.use(VueRouter) Vue.use(Vuex) Vue.use(VTooltip) diff --git a/resources/assets/js/components/base/BaseNotification.vue b/resources/assets/js/components/base/BaseNotification.vue new file mode 100644 index 00000000..5d3da964 --- /dev/null +++ b/resources/assets/js/components/base/BaseNotification.vue @@ -0,0 +1,147 @@ + + + diff --git a/resources/assets/js/components/base/index.js b/resources/assets/js/components/base/index.js index e377c461..dc636bd4 100644 --- a/resources/assets/js/components/base/index.js +++ b/resources/assets/js/components/base/index.js @@ -13,6 +13,7 @@ import NoteSelectPopup from './popup/NoteSelectPopup.vue' import BaseDatePicker from '../base/BaseDatePicker.vue' import BaseTimePicker from './BaseTimePicker.vue' import BasePage from './BasePage.vue' +import BaseNotification from './BaseNotification.vue' import GlobalSearch from '../GlobalSearch.vue' @@ -39,6 +40,7 @@ Vue.component('tax-select-popup', TaxSelectPopup) Vue.component('note-select-popup', NoteSelectPopup) Vue.component('base-time-picker', BaseTimePicker) +Vue.component('base-notification', BaseNotification) Vue.component('dot-icon', DotIcon) Vue.component('save-icon', SaveIcon) diff --git a/resources/assets/js/components/base/modal/BackupModal.vue b/resources/assets/js/components/base/modal/BackupModal.vue index 33645195..5f275fc0 100644 --- a/resources/assets/js/components/base/modal/BackupModal.vue +++ b/resources/assets/js/components/base/modal/BackupModal.vue @@ -2,8 +2,8 @@
@@ -21,7 +21,7 @@ :show-labels="false" :placeholder="$t('settings.backup.select_backup_type')" :allow-empty="false" - :maxHeight="100" + :max-height="100" />
@@ -59,9 +59,9 @@ {{ $t('general.create') }} @@ -140,6 +140,8 @@ export default { ...mapActions('modal', ['closeModal']), + ...mapActions('notification', ['showNotification']), + getCustomLabel({ driver, name }) { return `${name} — [${driver}]` }, @@ -154,12 +156,18 @@ export default { this.isCreateLoading = true await this.createBackup(data) this.isCreateLoading = false - window.toastr['success'](this.$t('settings.backup.created_message')) + this.showNotification({ + type: 'success', + message: this.$t('settings.backup.created_message'), + }) this.refreshData ? this.refreshData() : '' this.cancelBackup() } catch (e) { this.isCreateLoading = false - window.toastr['error'](e.response.data.message) + this.showNotification({ + type: 'error', + message: e.response.data.message, + }) } }, diff --git a/resources/assets/js/components/base/modal/CategoryModal.vue b/resources/assets/js/components/base/modal/CategoryModal.vue index 8eff0924..78b9b719 100644 --- a/resources/assets/js/components/base/modal/CategoryModal.vue +++ b/resources/assets/js/components/base/modal/CategoryModal.vue @@ -41,7 +41,7 @@ > {{ $t('general.cancel') }} - + {{ !isEdit ? $t('general.save') : $t('general.update') }} @@ -135,6 +135,8 @@ export default { methods: { ...mapActions('modal', ['closeModal']), ...mapActions('category', ['addCategory', 'updateCategory']), + ...mapActions('notification', ['showNotification']), + resetFormData() { this.formData = { id: null, @@ -159,13 +161,15 @@ export default { if (response.data) { if (!this.isEdit) { - window.toastr['success']( - this.$t('settings.expense_category.created_message') - ) + this.showNotification({ + type: 'success', + message: this.$t('settings.expense_category.created_message'), + }) } else { - window.toastr['success']( - this.$t('settings.expense_category.updated_message') - ) + this.showNotification({ + type: 'success', + message: this.$t('settings.expense_category.updated_message'), + }) } window.hub.$emit('newCategory', response.data.category) this.refreshData ? this.refreshData() : '' @@ -173,7 +177,10 @@ export default { this.isLoading = false return true } - window.toastr['error'](response.data.error) + this.showNotification({ + type: 'error', + message: response.data.error, + }) }, async setData() { this.formData = { diff --git a/resources/assets/js/components/base/modal/CustomField/Index.vue b/resources/assets/js/components/base/modal/CustomField/Index.vue index c156b87a..630bc486 100644 --- a/resources/assets/js/components/base/modal/CustomField/Index.vue +++ b/resources/assets/js/components/base/modal/CustomField/Index.vue @@ -78,9 +78,9 @@ /> @@ -92,28 +92,28 @@ >
@@ -376,6 +376,7 @@ export default { 'fetchCustomField', ]), ...mapActions('modal', ['closeModal']), + ...mapActions('notification', ['showNotification']), resetFormData() { this.formData = { label: null, @@ -433,9 +434,10 @@ export default { if (this.isEdit) { this.isLoading = true response = await this.updateCustomField(data) - window.toastr['success']( - this.$tc('settings.custom_fields.updated_message') - ) + this.showNotification({ + type: 'success', + message: this.$tc('settings.custom_fields.updated_message'), + }) this.refreshData() this.closeCategoryModal() return true @@ -444,7 +446,10 @@ export default { this.isLoading = true response = await this.addCustomField(data) - window.toastr['success'](this.$tc('settings.custom_fields.added_message')) + this.showNotification({ + type: 'success', + message: this.$tc('settings.custom_fields.added_message'), + }) this.refreshData() this.closeCategoryModal() return true diff --git a/resources/assets/js/components/base/modal/CustomerModal.vue b/resources/assets/js/components/base/modal/CustomerModal.vue index d00fd915..4b43510f 100644 --- a/resources/assets/js/components/base/modal/CustomerModal.vue +++ b/resources/assets/js/components/base/modal/CustomerModal.vue @@ -62,7 +62,7 @@ :allow-empty="false" :show-labels="false" :placeholder="$t('customers.select_currency')" - :maxHeight="200" + :max-height="200" label="name" class="mt-1 md:mt-0" track-by="id" @@ -343,7 +343,7 @@ > {{ $t('general.cancel') }} - + {{ $t('general.save') }} @@ -444,6 +444,8 @@ export default { ...mapGetters(['currencies', 'countries']), ...mapGetters('company', ['defaultCurrency']), ...mapGetters('modal', ['modalDataID', 'modalData', 'modalActive']), + ...mapActions('notification', ['showNotification']), + nameError() { if (!this.$v.formData.name.$error) { return '' @@ -586,6 +588,7 @@ export default { 'updateCustomer', ]), ...mapActions('modal', ['closeModal']), + ...mapActions('notification', ['showNotification']), resetData() { this.formData = { name: null, @@ -700,9 +703,15 @@ export default { } if (response.data) { if (this.modalDataID) { - window.toastr['success'](this.$tc('customers.updated_message')) + this.showNotification({ + type: 'success', + message: this.$tc('customers.updated_message'), + }) } else { - window.toastr['success'](this.$tc('customers.created_message')) + this.showNotification({ + type: 'success', + message: this.$tc('customers.created_message'), + }) } this.isLoading = false diff --git a/resources/assets/js/components/base/modal/FileDiskModal.vue b/resources/assets/js/components/base/modal/FileDiskModal.vue index 7ae9cfdb..e1e78a16 100644 --- a/resources/assets/js/components/base/modal/FileDiskModal.vue +++ b/resources/assets/js/components/base/modal/FileDiskModal.vue @@ -5,9 +5,9 @@ :is="selected_disk" :loading="isLoading" :disks="getDiskDrivers" + :is-edit="isEdit" @on-change-disk="(disk) => (selected_disk = disk.value)" @submit="createNewDisk" - :is-edit="isEdit" >