diff --git a/js/src/components/Comment/CommentTree.vue b/js/src/components/Comment/CommentTree.vue index 363f517a8..d845ebc54 100644 --- a/js/src/components/Comment/CommentTree.vue +++ b/js/src/components/Comment/CommentTree.vue @@ -24,6 +24,9 @@ v-model="newComment.text" />

+

+ {{ $t("Comment text can't be empty") }} +

"].includes(newComment.text); + } + } + async createCommentForEvent(comment: IComment): Promise { + this.emptyCommentError = ["", "

"].includes(comment.text); + if (this.emptyCommentError) return; try { if (!comment.actor) return; await this.$apollo.mutate({ @@ -216,10 +230,13 @@ export default class CommentTree extends Vue { // and reset the new comment field this.newComment = new CommentModel(); - } catch (error) { - console.error(error); - if (error.graphQLErrors && error.graphQLErrors.length > 0) { - this.$notifier.error(error.graphQLErrors[0].message); + } catch (errors) { + console.error(errors); + if (errors.graphQLErrors && errors.graphQLErrors.length > 0) { + const error = errors.graphQLErrors[0]; + if (error.field !== "text" && error.message[0] !== "can't be blank") { + this.$notifier.error(error.message); + } } } } diff --git a/js/src/i18n/en_US.json b/js/src/i18n/en_US.json index b26ce8296..0953e0c0b 100644 --- a/js/src/i18n/en_US.json +++ b/js/src/i18n/en_US.json @@ -968,5 +968,6 @@ "{profile} posted a comment on the event {event}.": "{profile} posted a comment on the event {event}.", "You replied to a comment on the event {event}.": "You replied to a comment on the event {event}.", "{profile} replied to a comment on the event {event}.": "{profile} replied to a comment on the event {event}.", - "New post": "New post" + "New post": "New post", + "Comment text can't be empty": "Comment text can't be empty" } diff --git a/js/src/i18n/fr_FR.json b/js/src/i18n/fr_FR.json index 09642de70..992fc10ea 100644 --- a/js/src/i18n/fr_FR.json +++ b/js/src/i18n/fr_FR.json @@ -1062,5 +1062,6 @@ "{profile} posted a comment on the event {event}.": "{profile} a posté un commentaire sur l'événement {event}.", "You replied to a comment on the event {event}.": "Vous avez répondu à un commentaire sur l'événement {event}.", "{profile} replied to a comment on the event {event}.": "{profile} a répondu à un commentaire sur l'événement {event}.", - "New post": "Nouveau billet" + "New post": "Nouveau billet", + "Comment text can't be empty": "Le texte du commentaire ne peut être vide" } diff --git a/lib/graphql/resolvers/comment.ex b/lib/graphql/resolvers/comment.ex index ef9899dd4..0e2998bb6 100644 --- a/lib/graphql/resolvers/comment.ex +++ b/lib/graphql/resolvers/comment.ex @@ -42,6 +42,9 @@ defmodule Mobilizon.GraphQL.Resolvers.Comment do Comments.create_comment(args) do {:ok, comment} else + {:error, err} -> + {:error, err} + {:allowed, false} -> {:error, :unauthorized} end