Add admin support contact form
This commit is contained in:
parent
5053d4a7d9
commit
b9af07b845
7 changed files with 155 additions and 4 deletions
|
@ -5,6 +5,10 @@ class SupportController < ApplicationController
|
||||||
setup_context
|
setup_context
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def admin
|
||||||
|
setup_context_admin
|
||||||
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if direct_message? && create_commentaire
|
if direct_message? && create_commentaire
|
||||||
flash.notice = "Votre message a été envoyé sur la messagerie de votre dossier."
|
flash.notice = "Votre message a été envoyé sur la messagerie de votre dossier."
|
||||||
|
@ -13,12 +17,21 @@ class SupportController < ApplicationController
|
||||||
elsif create_conversation
|
elsif create_conversation
|
||||||
flash.notice = "Votre message a été envoyé."
|
flash.notice = "Votre message a été envoyé."
|
||||||
|
|
||||||
redirect_to root_path(formulaire_contact_general_submitted: true)
|
if params[:admin]
|
||||||
|
redirect_to root_path(formulaire_contact_admin_submitted: true)
|
||||||
|
else
|
||||||
|
redirect_to root_path(formulaire_contact_general_submitted: true)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
setup_context
|
|
||||||
flash.now.alert = "Une erreur est survenue. Vous pouvez nous contacter à #{helpers.mail_to(CONTACT_EMAIL)}."
|
flash.now.alert = "Une erreur est survenue. Vous pouvez nous contacter à #{helpers.mail_to(CONTACT_EMAIL)}."
|
||||||
|
|
||||||
render :index
|
if params[:admin]
|
||||||
|
setup_context_admin
|
||||||
|
render :admin
|
||||||
|
else
|
||||||
|
setup_context
|
||||||
|
render :index
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -30,10 +43,16 @@ class SupportController < ApplicationController
|
||||||
@options = Helpscout::FormAdapter::OPTIONS
|
@options = Helpscout::FormAdapter::OPTIONS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def setup_context_admin
|
||||||
|
@tags = tags
|
||||||
|
@options = Helpscout::FormAdapter::ADMIN_OPTIONS
|
||||||
|
end
|
||||||
|
|
||||||
def create_conversation
|
def create_conversation
|
||||||
Helpscout::FormAdapter.new(
|
Helpscout::FormAdapter.new(
|
||||||
subject: params[:subject],
|
subject: params[:subject],
|
||||||
email: email,
|
email: email,
|
||||||
|
phone: params[:phone],
|
||||||
text: params[:text],
|
text: params[:text],
|
||||||
file: params[:file],
|
file: params[:file],
|
||||||
dossier_id: dossier&.id,
|
dossier_id: dossier&.id,
|
||||||
|
|
|
@ -3,6 +3,8 @@ class Helpscout::API
|
||||||
CONVERSATIONS = 'conversations'
|
CONVERSATIONS = 'conversations'
|
||||||
TAGS = 'tags'
|
TAGS = 'tags'
|
||||||
FIELDS = 'fields'
|
FIELDS = 'fields'
|
||||||
|
CUSTOMERS = 'customers'
|
||||||
|
PHONES = 'phones'
|
||||||
OAUTH2_TOKEN = 'oauth2/token'
|
OAUTH2_TOKEN = 'oauth2/token'
|
||||||
|
|
||||||
def add_tags(conversation_id, tags)
|
def add_tags(conversation_id, tags)
|
||||||
|
@ -42,6 +44,21 @@ class Helpscout::API
|
||||||
call_api(:post, CONVERSATIONS, body)
|
call_api(:post, CONVERSATIONS, body)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_phone_number(email, phone)
|
||||||
|
query = URI.encode("(email:#{email})")
|
||||||
|
response = call_api(:get, "#{CUSTOMERS}?mailbox=#{mailbox_id}&query=#{query}")
|
||||||
|
if response.success?
|
||||||
|
body = parse_response_body(response)
|
||||||
|
if body[:page][:totalElements] > 0
|
||||||
|
customer_id = body[:_embedded][:customers].first[:id]
|
||||||
|
call_api(:post, "#{CUSTOMERS}/#{customer_id}/#{PHONES}", {
|
||||||
|
type: "work",
|
||||||
|
value: phone
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def attachments(file)
|
def attachments(file)
|
||||||
|
|
|
@ -20,6 +20,18 @@ class Helpscout::FormAdapter
|
||||||
[I18n.t(TYPE_AUTRE, scope: [:support]), TYPE_AUTRE]
|
[I18n.t(TYPE_AUTRE, scope: [:support]), TYPE_AUTRE]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
ADMIN_TYPE_RDV = 'admin demande rdv'
|
||||||
|
ADMIN_TYPE_QUESTION = 'admin question'
|
||||||
|
ADMIN_TYPE_SOUCIS = 'admin soucis'
|
||||||
|
ADMIN_TYPE_AUTRE = 'admin autre'
|
||||||
|
|
||||||
|
ADMIN_OPTIONS = [
|
||||||
|
[I18n.t(ADMIN_TYPE_QUESTION, scope: [:supportadmin]), ADMIN_TYPE_QUESTION],
|
||||||
|
[I18n.t(ADMIN_TYPE_RDV, scope: [:supportadmin]), ADMIN_TYPE_RDV],
|
||||||
|
[I18n.t(ADMIN_TYPE_SOUCIS, scope: [:supportadmin]), ADMIN_TYPE_SOUCIS],
|
||||||
|
[I18n.t(ADMIN_TYPE_AUTRE, scope: [:supportadmin]), ADMIN_TYPE_AUTRE]
|
||||||
|
]
|
||||||
|
|
||||||
def send_form
|
def send_form
|
||||||
conversation_id = create_conversation
|
conversation_id = create_conversation
|
||||||
|
|
||||||
|
@ -51,6 +63,11 @@ class Helpscout::FormAdapter
|
||||||
params[:file]
|
params[:file]
|
||||||
)
|
)
|
||||||
|
|
||||||
response.success? ? response.headers['Resource-ID'] : nil
|
if response.success?
|
||||||
|
if params[:phone].present?
|
||||||
|
@api.add_phone_number(params[:email], params[:phone])
|
||||||
|
end
|
||||||
|
response.headers['Resource-ID']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
51
app/views/support/admin.html.haml
Normal file
51
app/views/support/admin.html.haml
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
- content_for(:title, 'Contact')
|
||||||
|
|
||||||
|
#contact-form
|
||||||
|
.container
|
||||||
|
%h1.new-h1 Contactez notre équipe
|
||||||
|
|
||||||
|
.description
|
||||||
|
En tant qu'administration, vous pouvez nous contactez via ce formulaire. Nous vous répondrons dans les plus brefs délais, par email ou par téléphone.
|
||||||
|
%br
|
||||||
|
%br
|
||||||
|
%strong
|
||||||
|
Attention, ce formulaire est réservée uniquement aux organismes publics.
|
||||||
|
Il ne concerne ni les particuliers, ni les entreprises, ni les associations (sauf celles reconnues d'utilité publique). Si c'est votre cas, rendez-vous sur notre
|
||||||
|
= link_to contact_path do
|
||||||
|
formulaire de contact public
|
||||||
|
\.
|
||||||
|
|
||||||
|
= form_tag contact_path, method: :post, class: 'form' do |f|
|
||||||
|
- if !logged_in?
|
||||||
|
.contact-champ
|
||||||
|
= label_tag :email do
|
||||||
|
Adresse email professionnelle
|
||||||
|
%span.mandatory *
|
||||||
|
= text_field_tag :email, params[:email], required: true
|
||||||
|
|
||||||
|
.contact-champ
|
||||||
|
= label_tag :type do
|
||||||
|
Catégorie
|
||||||
|
%span.mandatory *
|
||||||
|
= select_tag :type, options_for_select(@options, params[:type])
|
||||||
|
|
||||||
|
.contact-champ
|
||||||
|
= label_tag :phone, 'Numéro de téléphone professionnel (ligne directe)'
|
||||||
|
= text_field_tag :phone
|
||||||
|
|
||||||
|
.contact-champ
|
||||||
|
= label_tag :subject do
|
||||||
|
Sujet
|
||||||
|
= text_field_tag :subject, params[:subject], required: false
|
||||||
|
|
||||||
|
.contact-champ
|
||||||
|
= label_tag :text do
|
||||||
|
Message
|
||||||
|
%span.mandatory *
|
||||||
|
= text_area_tag :text, params[:text], rows: 6, required: true
|
||||||
|
|
||||||
|
= hidden_field_tag :tags, @tags&.join(',')
|
||||||
|
= hidden_field_tag :admin, true
|
||||||
|
|
||||||
|
.send-wrapper
|
||||||
|
= button_tag 'Envoyer le message', type: :submit, class: 'button send primary'
|
|
@ -61,6 +61,11 @@ fr:
|
||||||
produit: J'ai une idée d'amélioration pour votre site
|
produit: J'ai une idée d'amélioration pour votre site
|
||||||
usager perdu: Je ne trouve pas la démarche que je veux faire
|
usager perdu: Je ne trouve pas la démarche que je veux faire
|
||||||
autre: Autre sujet
|
autre: Autre sujet
|
||||||
|
supportadmin:
|
||||||
|
admin demande rdv: Demande de RDV pour une présentation à distance de demarches-simplifiees.fr
|
||||||
|
admin question: J'ai une question sur demarches-simplifiees.fr
|
||||||
|
admin soucis: J'ai un problème technique avec demarches-simplifiees.fr
|
||||||
|
admin autre: Autre sujet
|
||||||
|
|
||||||
number:
|
number:
|
||||||
currency:
|
currency:
|
||||||
|
|
|
@ -137,6 +137,8 @@ Rails.application.routes.draw do
|
||||||
get "contact", to: "support#index"
|
get "contact", to: "support#index"
|
||||||
post "contact", to: "support#create"
|
post "contact", to: "support#create"
|
||||||
|
|
||||||
|
get "contact-admin", to: "support#admin"
|
||||||
|
|
||||||
post "webhooks/helpscout", to: "webhook#helpscout"
|
post "webhooks/helpscout", to: "webhook#helpscout"
|
||||||
match "webhooks/helpscout", to: lambda { |_| [204, {}, nil] }, via: :head
|
match "webhooks/helpscout", to: lambda { |_| [204, {}, nil] }, via: :head
|
||||||
|
|
||||||
|
|
|
@ -66,5 +66,45 @@ describe Helpscout::FormAdapter do
|
||||||
.with(conversation_id, nil, nil)
|
.with(conversation_id, nil, nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'add_phone' do
|
||||||
|
before do
|
||||||
|
allow(api).to receive(:create_conversation)
|
||||||
|
.and_return(
|
||||||
|
double(
|
||||||
|
success?: true,
|
||||||
|
headers: {
|
||||||
|
'Resource-ID' => conversation_id
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
described_class.new(params, api).send_form
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:params) {
|
||||||
|
{
|
||||||
|
email: email,
|
||||||
|
subject: subject,
|
||||||
|
text: text,
|
||||||
|
phone: '0666666666'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let(:phone) { '0666666666' }
|
||||||
|
let(:email) { 'paul.chavard@beta.gouv.fr' }
|
||||||
|
let(:subject) { 'Bonjour' }
|
||||||
|
let(:text) { "J'ai un problem" }
|
||||||
|
let(:tags) { ['info demarche'] }
|
||||||
|
let(:conversation_id) { '123' }
|
||||||
|
|
||||||
|
it 'should call method' do
|
||||||
|
expect(api).to have_received(:create_conversation)
|
||||||
|
.with(email, subject, text, nil)
|
||||||
|
expect(api).to have_received(:add_phone_number)
|
||||||
|
.with(email, phone)
|
||||||
|
expect(api).to have_received(:add_custom_fields)
|
||||||
|
.with(conversation_id, nil, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue