Refactor success and error notifications to prevent html in them
continuous-integration/drone/push Build is passing Details

This commit is contained in:
kolaente 2021-06-22 22:41:29 +02:00
parent cdc805c8da
commit 0e53745e91
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 22 additions and 20 deletions

View File

@ -11,13 +11,17 @@
> >
<div <div
class="notification-title" class="notification-title"
v-html="props.item.title"
v-if="props.item.title" v-if="props.item.title"
></div> >
{{ props.item.title }}
</div>
<div <div
class="notification-content" class="notification-content"
v-html="props.item.text" >
></div> <template v-for="(t, k) in props.item.text">
{{ t }}<br :key="k"/>
</template>
</div>
<div <div
class="buttons is-right" class="buttons is-right"
v-if=" v-if="

View File

@ -1,31 +1,29 @@
const getText = t => {
if (t.response && t.response.data && t.response.data.message) {
return [
t.message,
t.response.data.message
]
}
return [t.message]
}
export default { export default {
error(e, context, actions = []) { error(e, context, actions = []) {
// Build the notification text from error response
let err = e.message
if (e.response && e.response.data && e.response.data.message) {
err += '<br/>' + e.response.data.message
}
// Fire a notification
context.$notify({ context.$notify({
type: 'error', type: 'error',
title: 'Error', title: 'Error',
text: err, text: getText(e),
actions: actions, actions: actions,
}) })
}, },
success(e, context, actions = []) { success(e, context, actions = []) {
// Build the notification text from error response
let err = e.message
if (e.response && e.response.data && e.response.data.message) {
err += '<br/>' + e.response.data.message
}
// Fire a notification
context.$notify({ context.$notify({
type: 'success', type: 'success',
title: 'Success', title: 'Success',
text: err, text: getText(e),
data: { data: {
actions: actions, actions: actions,
}, },