feat(rc.1): refine with better translations, better design

This commit is contained in:
Martin 2021-11-15 14:15:05 +01:00
parent 3b78a9d81a
commit d4c74b5621
6 changed files with 41 additions and 9 deletions

View file

@ -6,9 +6,9 @@ module Instructeurs
def destroy def destroy
result = CommentaireService.soft_delete(current_instructeur, params.permit(:dossier_id, :id)) result = CommentaireService.soft_delete(current_instructeur, params.permit(:dossier_id, :id))
if result.status if result.status
flash[:notice] = 'Votre message a été supprimé' flash[:notice] = t('views.shared.commentaires.destroy.notice')
else else
flash[:alert] = "Votre message ne peut être supprimé: #{result.error_message}" flash[:alert] = t('views.shared.commentaires.destroy.alert', reason: result.error_message)
end end
redirect_to(messagerie_instructeur_dossier_path(params[:procedure_id], params[:dossier_id])) redirect_to(messagerie_instructeur_dossier_path(params[:procedure_id], params[:dossier_id]))
end end

View file

@ -27,13 +27,16 @@ class CommentaireService
.find(params[:id]) .find(params[:id])
if commentaire.sent_by?(user) if commentaire.sent_by?(user)
commentaire.piece_jointe.purge_later if commentaire.piece_jointe.attached? commentaire.piece_jointe.purge_later if commentaire.piece_jointe.attached?
commentaire.update!(body: "Message supprimé", deleted_at: Time.now.utc) commentaire.update!(body: I18n.t('views.shared.commentaires.destroy.deleted_body'),
deleted_at: Time.now.utc)
OpenStruct.new(status: true) OpenStruct.new(status: true)
else else
OpenStruct.new(status: false, error_message: "Impossible de supprimer le message, celui ci ne vous appartient pas") OpenStruct.new(status: false,
error_message: I18n.t('views.shared.commentaires.destroy.alert_reasons.acl'))
end end
rescue ActiveRecord::RecordNotFound => e rescue ActiveRecord::RecordNotFound => e
return OpenStruct.new(status: false, error_message: "#{e.model.humanize} introuvable") return OpenStruct.new(status: false,
error_message: I18n.t('views.shared.commentaires.destroy.alert_reasons.ar_not_found', model_name: e.model.humanize))
end end
end end
end end

View file

@ -12,8 +12,9 @@
.message-extras.flex.justify-start .message-extras.flex.justify-start
- if commentaire.sent_by?(connected_user) && commentaire.sent_by_instructeur? && commentaire.deleted_at.nil? - if commentaire.sent_by?(connected_user) && commentaire.sent_by_instructeur? && commentaire.deleted_at.nil?
= button_to instructeur_commentaire_path(commentaire.dossier.procedure, commentaire.dossier, commentaire), method: :delete do = button_to instructeur_commentaire_path(commentaire.dossier.procedure, commentaire.dossier, commentaire), method: :delete, class: 'button danger', data: { confirm: t('views.shared.commentaires.destroy.confirm') } do
Supprimer %span.icon.delete
= t('views.shared.commentaires.destroy.button')
- if commentaire.piece_jointe.attached? - if commentaire.piece_jointe.attached?
.attachment-link .attachment-link

View file

@ -1,6 +1,14 @@
en: en:
views: views:
shared: shared:
dossiers:
identite_entreprise:
warning_for_private_info: "The establishment %{etablissement} applied his right to not publish information regarding his identity. These informaiton won't be visible from instructor services"
avis:
demande_envoyee_le: "Feedback send at %{date}"
demande_revoquee_le: "Feedback revoked at %{date}"
reponse_donnee_le: "Response sent at %{date}"
en_attente: "Waiting for response"
france_connect_login: france_connect_login:
title: "With FranceConnect" title: "With FranceConnect"
description: "France connect is a solution proposed by the government to secure and simplify the connection to web services." description: "France connect is a solution proposed by the government to secure and simplify the connection to web services."
@ -12,3 +20,13 @@ en:
already_user: "I already have an account" already_user: "I already have an account"
create: 'Create an account' create: 'Create an account'
signin: 'Sign in' signin: 'Sign in'
commentaires:
destroy:
button: 'Destroy this message'
confirm: "Are you sure you want to destroy this message ?"
deleted_body: Message deleted
notice: 'Your message had been deleted'
alert: 'Can not destroy message: #{result.error_message}'
alert_reasons:
acl: "Can not destroy message: it does not belong to you"
ar_not_found: "%{model_name} not found"

View file

@ -20,3 +20,13 @@ fr:
already_user: 'Jai déjà un compte' already_user: 'Jai déjà un compte'
create: 'Créer un compte' create: 'Créer un compte'
signin: 'Connexion' signin: 'Connexion'
commentaires:
destroy:
button: 'Supprimer le message'
confirm: "Êtes-vous sûr de vouloir supprimer ce message ?"
deleted_body: Message supprimé
notice: 'Votre message a été supprimé'
alert: 'Votre message ne peut être supprimé: #{result.error_message}'
alert_reasons:
acl: "Impossible de supprimer le message, celui ci ne vous appartient pas"
ar_not_found: "%{model_name} introuvable"

View file

@ -14,7 +14,7 @@ describe Instructeurs::CommentairesController, type: :controller do
end end
it 'flash success' do it 'flash success' do
subject subject
expect(flash[:notice]).to eq('Votre message a été supprimé') expect(flash[:notice]).to eq(I18n.t('views.shared.commentaires.destroy.notice'))
end end
context 'when it fails' do context 'when it fails' do
@ -27,7 +27,7 @@ describe Instructeurs::CommentairesController, type: :controller do
end end
it 'flash success' do it 'flash success' do
subject subject
expect(flash[:alert]).to eq("Votre message ne peut être supprimé: #{error.error_message}") expect(flash[:alert]).to eq(I18n.t('views.shared.commentaires.destroy.alert', reason: error.error_message))
end end
end end
end end