Skip to content

Commit

Permalink
Magento error params in error notifications (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobWez98 authored Jun 21, 2022
1 parent 97d1a05 commit 6846951
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion resources/js/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
window.axios = require('axios')
window.debug = process.env.MIX_DEBUG == 'true'
window.Notify = (message, type) => window.app.$emit('notification-message', message, type);
window.Notify = (message, type, params = []) => window.app.$emit('notification-message', message, type, params);

require('./lodash')
require('./vue')
Expand Down
10 changes: 8 additions & 2 deletions resources/js/components/Notifications/Notification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
})
},
created() {
this.message = this.notification.message
this.message = this.notification.message.includes('%') ? this.format(this.notification.message, this.notification.params) : this.notification.message
this.show = this.notification.show
this.type = this.notification.type
},
Expand All @@ -31,12 +31,18 @@
data: () => ({
message: null,
type: null,
show: null,
show: null
}),
methods: {
close() {
this.show = false
},
format(str, arr) {
return str.replace(/%(\d+)/g, function(_,m) {
return arr[--m];
});
}
},
computed: {
classes() {
Expand Down
3 changes: 2 additions & 1 deletion resources/js/components/Notifications/Notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
})
},
mounted() {
this.$root.$on('notification-message', (message, type) => {
this.$root.$on('notification-message', (message, type, params) => {
this.notifications.push({
message: message,
params: params,
type: type,
show: true
})
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/User/mixins/InteractWithUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default {
})
return response.data
} catch (error) {
Notify(error.response.data.message, 'error')
Notify(error.response.data.message, 'error', error.response.data.parameters)
return false
}
},
Expand Down

0 comments on commit 6846951

Please sign in to comment.