Skip to content

Commit

Permalink
Rework how errors are displayed
Browse files Browse the repository at this point in the history
Use toast for all alerts.
  • Loading branch information
brunobesson committed Mar 18, 2021
1 parent 2241a65 commit 3e23813
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 101 deletions.
7 changes: 0 additions & 7 deletions src/js/vue-plugins/alert-window.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import VueHead from 'vue-head';

import App from '@/App.vue';
import config from '@/js/config';
import alertWindow from '@/js/vue-plugins/alert-window';
import dateUtils from '@/js/vue-plugins/date-utils';
import documentUtils from '@/js/vue-plugins/document-utils';
import fontAwesome from '@/js/vue-plugins/font-awesome-config';
Expand Down Expand Up @@ -66,7 +65,6 @@ Vue.use(documentUtils); // getDocumentType, getLocale functions
Vue.use(fontAwesome); // <fa-icon /> component
Vue.use(getText); // vm.$gettext() function and v-translate directive
Vue.use(helperWindow); // vm.$helper property
Vue.use(alertWindow); // vm.$alert property
Vue.use(imageViewer);
Vue.use(globalComponents); // Components available everywhere
Vue.use(screen); // screen reactives properties
Expand Down
3 changes: 2 additions & 1 deletion src/views/user/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
</template>

<script>
import { toast } from 'bulma-toast';
import VueRecaptcha from 'vue-recaptcha';
import BaseForm from './utils/BaseForm';
Expand Down Expand Up @@ -344,7 +345,7 @@ export default {
resetPassword() {
this.promise = c2c.userProfile
.requestPasswordChange(this.email)
.then(() => this.$alert.show([this.$gettext('Mail has been sent')]));
.then(() => toast({ message: this.$gettext('Mail has been sent'), type: 'is-danger' }));
},
validateNewPassword() {
Expand Down
8 changes: 1 addition & 7 deletions src/views/wiki/edition/AreaEditionView.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<template>
<edition-container
:mode="mode"
:document="document"
:generic-errors="genericErrors"
:is-loading="saving"
@save="save"
>
<edition-container :mode="mode" :document="document" :is-loading="saving" @save="save">
<div class="columns">
<form-field :document="document" :field="fields.title" />
<form-field class="is-narrow" :document="document" :field="fields.area_type" />
Expand Down
8 changes: 1 addition & 7 deletions src/views/wiki/edition/ArticleEditionView.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<template>
<edition-container
:mode="mode"
:document="document"
:generic-errors="genericErrors"
:is-loading="saving"
@save="save"
>
<edition-container :mode="mode" :document="document" :is-loading="saving" @save="save">
<div class="columns is-multiline">
<form-field :document="document" :field="fields.title" is-expanded />
<form-field class="is-narrow" :document="document" :field="fields.article_type" />
Expand Down
8 changes: 1 addition & 7 deletions src/views/wiki/edition/BookEditionView.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<template>
<edition-container
:mode="mode"
:document="document"
:generic-errors="genericErrors"
:is-loading="saving"
@save="save"
>
<edition-container :mode="mode" :document="document" :is-loading="saving" @save="save">
<form-section
:title="$gettext('general informations')"
:sub-title="$gettext('Title of the book, author, language and date of publication.')"
Expand Down
8 changes: 1 addition & 7 deletions src/views/wiki/edition/ImageEditionView.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<template>
<edition-container
:mode="mode"
:document="document"
:generic-errors="genericErrors"
:is-loading="saving || uploadingNewFile"
@save="save"
>
<edition-container :mode="mode" :document="document" :is-loading="saving || uploadingNewFile" @save="save">
<form-section
:title="$gettext('general informations')"
:sub-title="$gettext('Title, activity and characteristics of the picture')"
Expand Down
8 changes: 1 addition & 7 deletions src/views/wiki/edition/MapEditionView.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<template>
<edition-container
:mode="mode"
:document="document"
:generic-errors="genericErrors"
:is-loading="saving"
@save="save"
>
<edition-container :mode="mode" :document="document" :is-loading="saving" @save="save">
<div class="columns is-multiline">
<form-field class="is-12" :document="document" :field="fields.title" />
<form-field class="is-4" :document="document" :field="fields.editor" />
Expand Down
8 changes: 1 addition & 7 deletions src/views/wiki/edition/OutingEditionView.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<template>
<edition-container
:mode="mode"
:document="document"
:generic-errors="genericErrors"
:is-loading="saving"
@save="save"
>
<edition-container :mode="mode" :document="document" :is-loading="saving" @save="save">
<form-section
:title="$gettext('general informations')"
:sub-title="$gettext('Main informations about your outing')"
Expand Down
8 changes: 1 addition & 7 deletions src/views/wiki/edition/ProfileEditionView.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<template>
<edition-container
:mode="mode"
:document="document"
:generic-errors="genericErrors"
:is-loading="saving"
@save="save"
>
<edition-container :mode="mode" :document="document" :is-loading="saving" @save="save">
<div class="columns is-multiline">
<form-field class="is-12" :document="document" :field="fields.activities" />
<form-field class="is-12" :document="document" :field="fields.categories" />
Expand Down
8 changes: 1 addition & 7 deletions src/views/wiki/edition/RouteEditionView.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<template>
<edition-container
:mode="mode"
:document="document"
:generic-errors="genericErrors"
:is-loading="saving"
@save="save"
>
<edition-container :mode="mode" :document="document" :is-loading="saving" @save="save">
<form-section
:title="$gettext('general informations')"
:sub-title="
Expand Down
9 changes: 1 addition & 8 deletions src/views/wiki/edition/WaypointEditionView.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
<template>
<edition-container
class="edition-container"
:mode="mode"
:document="document"
:generic-errors="genericErrors"
:is-loading="saving"
@save="save"
>
<edition-container class="edition-container" :mode="mode" :document="document" :is-loading="saving" @save="save">
<form-section :title="$gettext('general informations')" :sub-title="$gettext('Waypoint\'s main properties')">
<div class="columns">
<form-field class="is-narrow" :document="document" :field="fields.waypoint_type" />
Expand Down
8 changes: 1 addition & 7 deletions src/views/wiki/edition/XreportEditionView.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<template>
<edition-container
:mode="mode"
:document="document"
:generic-errors="genericErrors"
:is-loading="saving"
@save="save"
>
<edition-container :mode="mode" :document="document" :is-loading="saving" @save="save">
<form-section
:title="$gettext('General information')"
:sub-title="$gettext('Report title, activity, linked routes or outings.')"
Expand Down
10 changes: 0 additions & 10 deletions src/views/wiki/edition/utils/EditionContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@

<!-- On mobile, expand button may go too low -->
<div style="clear: both" />

<div v-for="(error, i) of genericErrors" :key="i" class="has-text-danger has-text-weight-bold">
{{ error.name }}
:
{{ error.description }}
</div>
</div>

<component :is="documentType + '-view'" v-if="isPreview" :draft="document" />
Expand Down Expand Up @@ -109,10 +103,6 @@ export default {
type: Object,
default: null,
},
genericErrors: {
type: Array,
required: true,
},
mode: {
type: String,
required: true,
Expand Down
30 changes: 20 additions & 10 deletions src/views/wiki/edition/utils/document-edition-view-mixin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { toast } from 'bulma-toast';

import AssociationsInputRow from './AssociationsInputRow';
import EditionContainer from './EditionContainer';
import FormField from './FormField';
Expand Down Expand Up @@ -32,7 +34,6 @@ export default {
return {
promise: {},
fields: null, // keep fields here to set them reactive
genericErrors: [],
saving: false,
modified: false,
};
Expand Down Expand Up @@ -213,11 +214,11 @@ export default {
// $gettext('This field must be a valid ISBN.', 'API message');

if (fieldsWithError.length !== 0) {
const messages = fieldsWithError.map((field) => {
return `${this.$gettext(field.name)} : ${this.$gettext(field.error.description, i18nContext)}`;
});
const messages = fieldsWithError.map(
(field) => `${this.$gettext(field.name)} : ${this.$gettext(field.error.description, i18nContext)}`
);

this.$alert.show(messages);
toast({ message: `<ul><li>${messages.join('</li><li>')}</li></ul>`, type: 'is-danger', position: 'center' });

return true;
}
Expand All @@ -227,11 +228,13 @@ export default {

save(comment) {
if (this.lang === 'eu' && !this.$user.isModerator) {
this.$alert.show([
this.$gettext(
toast({
message: this.$gettext(
"Sorry, euskara lang has been frozen.\nWe're looking for a moderator, if you're interested, please contact board@camptocamp.org"
),
]);
type: 'is-danger',
position: 'center',
});
return;
}

Expand Down Expand Up @@ -309,14 +312,21 @@ export default {

dispatchError(fieldName, error) {
if (this.fields[fieldName] === undefined) {
this.genericErrors.push(error);
// $gettext('Conflict: version of locale 'en' has changed')
// $gettext('Conflict: version of locale 'es' has changed')
// $gettext('Conflict: version of locale 'eu' has changed')
// $gettext('Conflict: version of locale 'de' has changed')
// $gettext('Conflict: version of locale 'it' has changed')
// $gettext('Conflict: version of locale 'ca' has changed')
// $gettext('Conflict: version of locale 'fr' has changed')
// $gettext('Conflict: version of document has changed')
toast({ message: this.$gettext(`${error.name}: ${error.description}`), type: 'is-danger', position: 'center' });
} else {
this.fields[fieldName].error = error;
}
},

cleanErrors() {
this.genericErrors = [];
for (const field of Object.values(this.fields)) {
field.error = null;
}
Expand Down

0 comments on commit 3e23813

Please sign in to comment.