Merge pull request #2488 from tchak/improve-contact-form
Improve contact form
This commit is contained in:
commit
6c1aee7d63
8 changed files with 99 additions and 21 deletions
|
@ -8,6 +8,11 @@
|
|||
.alert-danger {
|
||||
background-color: $medium-red;
|
||||
color: #FFFFFF;
|
||||
|
||||
a {
|
||||
color: #FFFFFF;
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
|
|
|
@ -16,7 +16,7 @@ class SupportController < ApplicationController
|
|||
redirect_to root_path
|
||||
else
|
||||
setup_context
|
||||
flash.now.alert = "Une erreur est survenue. Vous pouvez nous contactez à #{CONTACT_EMAIL}."
|
||||
flash.now.alert = "Une erreur est survenue. Vous pouvez nous contactez à #{view_context.mail_to(CONTACT_EMAIL)}."
|
||||
|
||||
render :index
|
||||
end
|
||||
|
@ -26,8 +26,7 @@ class SupportController < ApplicationController
|
|||
|
||||
def setup_context
|
||||
@dossier_id = dossier&.id
|
||||
@type = params[:type]
|
||||
@tags = params[:tags]
|
||||
@tags = tags
|
||||
@options = Helpscout::FormAdapter::OPTIONS
|
||||
end
|
||||
|
||||
|
@ -53,6 +52,9 @@ class SupportController < ApplicationController
|
|||
|
||||
def tags
|
||||
[params[:tags], params[:type]].flatten.compact
|
||||
.map { |tag| tag.split(',') }
|
||||
.flatten
|
||||
.reject(&:blank?).uniq
|
||||
end
|
||||
|
||||
def browser_name
|
||||
|
@ -62,7 +64,7 @@ class SupportController < ApplicationController
|
|||
end
|
||||
|
||||
def direct_message?
|
||||
user_signed_in? && params[:type] == Helpscout::FormAdapter::TYPE_INSTRUCTION && dossier.present?
|
||||
user_signed_in? && params[:type] == Helpscout::FormAdapter::TYPE_INSTRUCTION && dossier.present? && !dossier.brouillon?
|
||||
end
|
||||
|
||||
def dossier
|
||||
|
|
|
@ -55,8 +55,11 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def contact_link(title, options = {})
|
||||
tags, type, dossier_id = options.values_at(:tags, :type, :dossier_id)
|
||||
options.except!(:tags, :type, :dossier_id)
|
||||
|
||||
if Flipflop.support_form?
|
||||
params = { tags: options[:tags], type: options[:type] }.compact
|
||||
params = { tags: tags, type: type, dossier_id: dossier_id }.compact
|
||||
link_to title, contact_url(params), options
|
||||
else
|
||||
mail_to CONTACT_EMAIL, title,
|
||||
|
|
|
@ -9,4 +9,7 @@
|
|||
\-
|
||||
= link_to 'CGU / Mentions légales', CGU_URL
|
||||
\-
|
||||
= contact_link 'Contact'
|
||||
- if @facade.present? && @facade.respond_to?(:dossier)
|
||||
= contact_link 'Contact', dossier_id: @facade.dossier&.id
|
||||
- else
|
||||
= contact_link 'Contact'
|
||||
|
|
|
@ -36,4 +36,4 @@
|
|||
–
|
||||
= link_to "Mentions légales", MENTIONS_LEGALES_URL, :class => "footer-link", :target => "_blank", rel: "noopener noreferrer"
|
||||
–
|
||||
= contact_link "Contact technique", class: "footer-link"
|
||||
= contact_link "Contact technique", class: "footer-link", dossier_id: dossier.id
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
%div
|
||||
= contact_link "Contactez-nous",
|
||||
tags: 'landing',
|
||||
class: "cta-panel-button white",
|
||||
class: "cta-panel-button-white",
|
||||
target: "_blank",
|
||||
rel: "noopener noreferrer"
|
||||
|
||||
|
|
|
@ -14,13 +14,13 @@
|
|||
= label_tag :email do
|
||||
Email
|
||||
%span.mandatory *
|
||||
= text_field_tag :email, '', required: true
|
||||
= text_field_tag :email, params[:email], required: true
|
||||
|
||||
.contact-champ
|
||||
= label_tag :type do
|
||||
Votre problème
|
||||
%span.mandatory *
|
||||
= select_tag :type, options_for_select(@options, @type)
|
||||
= select_tag :type, options_for_select(@options, params[:type])
|
||||
|
||||
.contact-champ
|
||||
= label_tag :dossier_id, 'Numéro du dossier concerné'
|
||||
|
@ -30,19 +30,19 @@
|
|||
= label_tag :subject do
|
||||
Sujet
|
||||
%span.mandatory *
|
||||
= text_field_tag :subject, '', required: true
|
||||
= text_field_tag :subject, params[:subject], required: true
|
||||
|
||||
.contact-champ
|
||||
= label_tag :text do
|
||||
Message
|
||||
%span.mandatory *
|
||||
= text_area_tag :text, '', rows: 6, required: true
|
||||
= text_area_tag :text, params[:text], rows: 6, required: true
|
||||
|
||||
.contact-champ
|
||||
= label_tag :text, 'Pièce jointe'
|
||||
= file_field_tag :file
|
||||
|
||||
= hidden_field_tag :tags, @tags
|
||||
= hidden_field_tag :tags, @tags&.join(',')
|
||||
|
||||
.send-wrapper
|
||||
= button_tag 'Envoyer le message', type: :submit, class: 'button send primary'
|
||||
|
|
|
@ -9,6 +9,13 @@ describe SupportController, type: :controller do
|
|||
end
|
||||
let(:user) { create(:user) }
|
||||
|
||||
it 'should not have email field' do
|
||||
get :index
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.body).not_to have_content("Email *")
|
||||
end
|
||||
|
||||
describe "with dossier" do
|
||||
let(:user) { dossier.user }
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
@ -19,16 +26,9 @@ describe SupportController, type: :controller do
|
|||
expect(response.status).to eq(200)
|
||||
expect(response.body).to include("#{dossier.id}")
|
||||
end
|
||||
|
||||
it 'should not have email field' do
|
||||
get :index
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.body).not_to have_content("Email *")
|
||||
end
|
||||
end
|
||||
|
||||
describe "with dossier" do
|
||||
describe "with tag" do
|
||||
let(:tag) { 'yolo' }
|
||||
|
||||
it 'should fill tags' do
|
||||
|
@ -38,6 +38,71 @@ describe SupportController, type: :controller do
|
|||
expect(response.body).to include(tag)
|
||||
end
|
||||
end
|
||||
|
||||
describe "with multiple tags" do
|
||||
let(:tags) { ['yolo', 'toto'] }
|
||||
|
||||
it 'should fill tags' do
|
||||
get :index, params: { tags: tags }
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(response.body).to include(tags.join(','))
|
||||
end
|
||||
end
|
||||
|
||||
describe "send form" do
|
||||
it 'should create conversation' do
|
||||
expect(subject).not_to receive(:create_commentaire)
|
||||
allow(subject).to receive(:create_conversation).and_return(true)
|
||||
|
||||
post :create, params: {
|
||||
subject: 'bonjour',
|
||||
text: 'un message'
|
||||
}
|
||||
|
||||
expect(flash[:notice]).to match('Votre message a été envoyé.')
|
||||
expect(response).to redirect_to root_path
|
||||
end
|
||||
|
||||
context "with dossier" do
|
||||
let(:user) { dossier.user }
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
||||
it 'should create conversation' do
|
||||
expect(subject).not_to receive(:create_commentaire)
|
||||
allow(subject).to receive(:create_conversation).and_return(true)
|
||||
|
||||
post :create, params: {
|
||||
dossier_id: dossier.id,
|
||||
type: Helpscout::FormAdapter::TYPE_INSTRUCTION,
|
||||
subject: 'bonjour',
|
||||
text: 'un message'
|
||||
}
|
||||
|
||||
expect(flash[:notice]).to match('Votre message a été envoyé.')
|
||||
expect(response).to redirect_to root_path
|
||||
end
|
||||
|
||||
context "en_construction" do
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
|
||||
it 'should create commentaire' do
|
||||
allow(subject).to receive(:create_commentaire).and_return(true)
|
||||
expect(subject).not_to receive(:create_conversation)
|
||||
|
||||
post :create, params: {
|
||||
dossier_id: dossier.id,
|
||||
type: Helpscout::FormAdapter::TYPE_INSTRUCTION,
|
||||
subject: 'bonjour',
|
||||
text: 'un message'
|
||||
}
|
||||
|
||||
expect(flash[:notice]).to match('Votre message a été envoyé sur la messagerie de votre dossier.')
|
||||
expect(response).to redirect_to users_dossier_recapitulatif_path(dossier)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'signed out' do
|
||||
|
|
Loading…
Reference in a new issue