Merge pull request #2531 from betagouv/ameliorations-messagerie
Améliorations à la messagerie
This commit is contained in:
commit
eb25c7b22d
10 changed files with 91 additions and 6 deletions
|
@ -34,4 +34,8 @@
|
||||||
.button.edit-form {
|
.button.edit-form {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.messagerie-explanation {
|
||||||
|
margin-bottom: $default-padding * 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ module NewUser
|
||||||
@commentaire = CommentaireService.create(current_user, dossier, commentaire_params)
|
@commentaire = CommentaireService.create(current_user, dossier, commentaire_params)
|
||||||
|
|
||||||
if @commentaire.save
|
if @commentaire.save
|
||||||
flash.notice = "Message envoyé"
|
flash.notice = "Votre message a bien été envoyé à l’instructeur en charge de votre dossier."
|
||||||
redirect_to messagerie_dossier_path(dossier)
|
redirect_to messagerie_dossier_path(dossier)
|
||||||
else
|
else
|
||||||
flash.now.alert = @commentaire.errors.full_messages
|
flash.now.alert = @commentaire.errors.full_messages
|
||||||
|
|
|
@ -4,4 +4,14 @@ module CommentaireHelper
|
||||||
"from-me"
|
"from-me"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def commentaire_is_from_guest(commentaire)
|
||||||
|
commentaire.dossier.invites.map(&:email).include?(commentaire.email)
|
||||||
|
end
|
||||||
|
|
||||||
|
def commentaire_date(commentaire)
|
||||||
|
is_current_year = (commentaire.created_at.year == Date.current.year)
|
||||||
|
template = is_current_year ? :message_date : :message_date_with_year
|
||||||
|
I18n.l(commentaire.created_at.localtime, format: template)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,4 +3,8 @@
|
||||||
#dossier-show
|
#dossier-show
|
||||||
= render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier }
|
= render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier }
|
||||||
|
|
||||||
|
.container
|
||||||
|
%p.messagerie-explanation
|
||||||
|
La messagerie vous permet de contacter l’instructeur en charge de votre dossier.
|
||||||
|
|
||||||
= render partial: "shared/dossiers/messagerie", locals: { dossier: @dossier, user_email: current_user.email, messagerie_seen_at: nil, new_commentaire: @commentaire, form_url: commentaire_dossier_path(@dossier) }
|
= render partial: "shared/dossiers/messagerie", locals: { dossier: @dossier, user_email: current_user.email, messagerie_seen_at: nil, new_commentaire: @commentaire, form_url: commentaire_dossier_path(@dossier) }
|
||||||
|
|
|
@ -7,5 +7,5 @@
|
||||||
.notice
|
.notice
|
||||||
(taille max : 20 Mo)
|
(taille max : 20 Mo)
|
||||||
|
|
||||||
.send-wrapper
|
%div
|
||||||
= f.submit 'Envoyer', class: 'button send', data: { disable: true }
|
= f.submit 'Envoyer', class: 'button primary send', data: { disable: true }
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
%h2
|
%h2
|
||||||
%span.mail
|
%span.mail
|
||||||
= render partial: 'shared/dossiers/messages/message_issuer', locals: { commentaire: commentaire, user_email: user_email }
|
= render partial: 'shared/dossiers/messages/message_issuer', locals: { commentaire: commentaire, user_email: user_email }
|
||||||
- if ![user_email, commentaire.dossier.user.email, OLD_CONTACT_EMAIL, CONTACT_EMAIL].include?(commentaire.email)
|
- if commentaire_is_from_guest(commentaire)
|
||||||
%span.guest Invité
|
%span.guest Invité
|
||||||
%span.date{ class: highlight_if_unseen_class(messagerie_seen_at, commentaire.created_at) }
|
%span.date{ class: highlight_if_unseen_class(messagerie_seen_at, commentaire.created_at) }
|
||||||
= I18n.l(commentaire.created_at.localtime, format: '%d/%m/%Y à %H:%M ')
|
= commentaire_date(commentaire)
|
||||||
.rich-text= sanitize(commentaire.body)
|
.rich-text= sanitize(commentaire.body)
|
||||||
|
|
||||||
- if commentaire.piece_justificative
|
- if commentaire.piece_justificative
|
||||||
|
|
|
@ -5,4 +5,4 @@
|
||||||
- when CONTACT_EMAIL
|
- when CONTACT_EMAIL
|
||||||
Email automatique
|
Email automatique
|
||||||
- else
|
- else
|
||||||
= commentaire.email
|
= commentaire.sender
|
||||||
|
|
10
config/locales/time_format.en.rb
Normal file
10
config/locales/time_format.en.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
:en => {
|
||||||
|
:time => {
|
||||||
|
:formats => {
|
||||||
|
:message_date => lambda { |time, _| "%B #{time.day.ordinalize} at %H:%M" },
|
||||||
|
:message_date_with_year => lambda { |time, _| "%B #{time.day.ordinalize} %Y at %H:%M" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
config/locales/time_format.fr.rb
Normal file
10
config/locales/time_format.fr.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
:fr => {
|
||||||
|
:time => {
|
||||||
|
:formats => {
|
||||||
|
:message_date => lambda { |time, _| "le #{time.day == 1 ? '1er' : time.day} %B à %H h %M" },
|
||||||
|
:message_date_with_year => lambda { |time, _| "le #{time.day == 1 ? '1er' : time.day} %B %Y à %H h %M" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,4 +18,51 @@ RSpec.describe CommentaireHelper, type: :helper do
|
||||||
it { is_expected.to eq nil }
|
it { is_expected.to eq nil }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.commentaire_is_from_guest' do
|
||||||
|
let(:dossier) { create(:dossier) }
|
||||||
|
let!(:guest) { create(:invite_user, dossier: dossier) }
|
||||||
|
|
||||||
|
subject { commentaire_is_from_guest(commentaire) }
|
||||||
|
|
||||||
|
context 'when the commentaire sender is not a guest' do
|
||||||
|
let(:commentaire) { create(:commentaire, dossier: dossier, email: "michel@pref.fr") }
|
||||||
|
it { is_expected.to be false }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the commentaire sender is a guest on this dossier' do
|
||||||
|
let(:commentaire) { create(:commentaire, dossier: dossier, email: guest.email) }
|
||||||
|
it { is_expected.to be true }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.commentaire_date' do
|
||||||
|
let(:present_date) { Time.local(2018, 9, 2, 10, 5, 0) }
|
||||||
|
let(:creation_date) { present_date }
|
||||||
|
let(:commentaire) do
|
||||||
|
Timecop.freeze(creation_date) { create(:commentaire, email: "michel@pref.fr") }
|
||||||
|
end
|
||||||
|
|
||||||
|
subject do
|
||||||
|
Timecop.freeze(present_date) { commentaire_date(commentaire) }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'doesn’t include the creation year' do
|
||||||
|
expect(subject).to eq 'le 2 septembre à 10 h 05'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when displaying a commentaire created on a previous year' do
|
||||||
|
let(:creation_date) { present_date.prev_year }
|
||||||
|
it 'includes the creation year' do
|
||||||
|
expect(subject).to eq 'le 2 septembre 2017 à 10 h 05'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when formatting the first day of the month' do
|
||||||
|
let(:present_date) { Time.local(2018, 9, 1, 10, 5, 0) }
|
||||||
|
it 'includes the ordinal' do
|
||||||
|
expect(subject).to eq 'le 1er septembre à 10 h 05'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue