refactor(contact): support => contact

This commit is contained in:
Colin Darie 2024-07-31 16:20:49 +02:00
parent e71c1781a9
commit 4b6d3ee16d
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
10 changed files with 32 additions and 32 deletions

View file

@ -1,13 +1,13 @@
class SupportController < ApplicationController
class ContactController < ApplicationController
invisible_captcha only: [:create], on_spam: :redirect_to_root
def index
@form = ContactForm.new(tags: support_form_params.fetch(:tags, []), dossier_id: dossier&.id)
@form = ContactForm.new(tags: contact_form_params.fetch(:tags, []), dossier_id: dossier&.id)
@form.user = current_user
end
def admin
@form = ContactForm.new(tags: support_form_params.fetch(:tags, []), for_admin: true)
@form = ContactForm.new(tags: contact_form_params.fetch(:tags, []), for_admin: true)
@form.user = current_user
end
@ -20,7 +20,7 @@ class SupportController < ApplicationController
return
end
form_params = support_form_params
form_params = contact_form_params
@form = ContactForm.new(form_params.except(:piece_jointe))
@form.piece_jointe.attach(form_params[:piece_jointe]) if form_params[:piece_jointe].present?
@form.user = current_user
@ -40,8 +40,8 @@ class SupportController < ApplicationController
def create_commentaire!
attributes = {
piece_jointe: support_form_params[:piece_jointe],
body: "[#{support_form_params[:subject]}]<br><br>#{support_form_params[:text]}"
piece_jointe: contact_form_params[:piece_jointe],
body: "[#{contact_form_params[:subject]}]<br><br>#{contact_form_params[:text]}"
}
CommentaireService.create!(current_user, dossier, attributes)
end
@ -54,20 +54,20 @@ class SupportController < ApplicationController
def direct_message?
return false unless user_signed_in?
return false unless support_form_params[:question_type] == ContactForm::TYPE_INSTRUCTION
return false unless contact_form_params[:question_type] == ContactForm::TYPE_INSTRUCTION
dossier&.messagerie_available?
end
def dossier
@dossier ||= current_user&.dossiers&.find_by(id: support_form_params[:dossier_id])
@dossier ||= current_user&.dossiers&.find_by(id: contact_form_params[:dossier_id])
end
def redirect_to_root
redirect_to root_path, alert: t('invisible_captcha.sentence_for_humans')
end
def support_form_params
def contact_form_params
keys = [:email, :subject, :text, :question_type, :dossier_id, :piece_jointe, :phone, :for_admin, tags: []]
if params.key?(:contact_form) # submitting form
params.require(:contact_form).permit(*keys)

View file

@ -1,7 +1,7 @@
import { ApplicationController } from './application_controller';
import { hide, show } from '@utils';
export class SupportController extends ApplicationController {
export class ContactController extends ApplicationController {
static targets = ['inputRadio', 'content'];
declare readonly inputRadioTargets: HTMLInputElement[];

View file

@ -30,22 +30,22 @@ class ContactForm < ApplicationRecord
def self.default_options
[
[I18n.t(:question, scope: [:support, :index, TYPE_INFO]), TYPE_INFO, I18n.t("links.common.faq.contacter_service_en_charge_url")],
[I18n.t(:question, scope: [:support, :index, TYPE_PERDU]), TYPE_PERDU, LISTE_DES_DEMARCHES_URL],
[I18n.t(:question, scope: [:support, :index, TYPE_INSTRUCTION]), TYPE_INSTRUCTION, I18n.t("links.common.faq.ou_en_est_mon_dossier_url")],
[I18n.t(:question, scope: [:support, :index, TYPE_AMELIORATION]), TYPE_AMELIORATION, FEATURE_UPVOTE_URL],
[I18n.t(:question, scope: [:support, :index, TYPE_AUTRE]), TYPE_AUTRE]
[I18n.t(:question, scope: [:contact, :index, TYPE_INFO]), TYPE_INFO, I18n.t("links.common.faq.contacter_service_en_charge_url")],
[I18n.t(:question, scope: [:contact, :index, TYPE_PERDU]), TYPE_PERDU, LISTE_DES_DEMARCHES_URL],
[I18n.t(:question, scope: [:contact, :index, TYPE_INSTRUCTION]), TYPE_INSTRUCTION, I18n.t("links.common.faq.ou_en_est_mon_dossier_url")],
[I18n.t(:question, scope: [:contact, :index, TYPE_AMELIORATION]), TYPE_AMELIORATION, FEATURE_UPVOTE_URL],
[I18n.t(:question, scope: [:contact, :index, TYPE_AUTRE]), TYPE_AUTRE]
]
end
def self.admin_options
[
[I18n.t(:question, scope: [:support, :admin, ADMIN_TYPE_QUESTION], app_name: Current.application_name), ADMIN_TYPE_QUESTION],
[I18n.t(:question, scope: [:support, :admin, ADMIN_TYPE_RDV], app_name: Current.application_name), ADMIN_TYPE_RDV],
[I18n.t(:question, scope: [:support, :admin, ADMIN_TYPE_SOUCIS], app_name: Current.application_name), ADMIN_TYPE_SOUCIS],
[I18n.t(:question, scope: [:support, :admin, ADMIN_TYPE_PRODUIT]), ADMIN_TYPE_PRODUIT],
[I18n.t(:question, scope: [:support, :admin, ADMIN_TYPE_DEMANDE_COMPTE]), ADMIN_TYPE_DEMANDE_COMPTE],
[I18n.t(:question, scope: [:support, :admin, ADMIN_TYPE_AUTRE]), ADMIN_TYPE_AUTRE]
[I18n.t(:question, scope: [:contact, :admin, ADMIN_TYPE_QUESTION], app_name: Current.application_name), ADMIN_TYPE_QUESTION],
[I18n.t(:question, scope: [:contact, :admin, ADMIN_TYPE_RDV], app_name: Current.application_name), ADMIN_TYPE_RDV],
[I18n.t(:question, scope: [:contact, :admin, ADMIN_TYPE_SOUCIS], app_name: Current.application_name), ADMIN_TYPE_SOUCIS],
[I18n.t(:question, scope: [:contact, :admin, ADMIN_TYPE_PRODUIT]), ADMIN_TYPE_PRODUIT],
[I18n.t(:question, scope: [:contact, :admin, ADMIN_TYPE_DEMANDE_COMPTE]), ADMIN_TYPE_DEMANDE_COMPTE],
[I18n.t(:question, scope: [:contact, :admin, ADMIN_TYPE_AUTRE]), ADMIN_TYPE_AUTRE]
]
end

View file

@ -1,4 +1,4 @@
= form_for form, url: contact_path, method: :post, multipart: true, class: 'fr-form-group', data: {controller: :support } do |f|
= form_for form, url: contact_path, method: :post, multipart: true, class: 'fr-form-group', data: {controller: :contact } do |f|
%p.fr-hint-text= t('asterisk_html', scope: [:utils])
- if form.require_email?
@ -12,7 +12,7 @@
.fr-fieldset__content
- form.options.each do |(question, question_type, link)|
.fr-radio-group
= f.radio_button :question_type, question_type, required: true, data: {"support-target": "inputRadio" }, checked: question_type == form.question_type
= f.radio_button :question_type, question_type, required: true, data: {"contact-target": "inputRadio" }, checked: question_type == form.question_type
= f.label "question_type_#{question_type}", { 'aria-controls': link ? "card-#{question_type}" : nil, class: 'fr-label' } do
= question
@ -20,11 +20,11 @@
.fr-ml-3w{ id: "card-#{question_type}",
class: class_names('hidden' => question_type != form.question_type),
"aria-hidden": question_type != form.question_type,
data: { "support-target": "content" } }
data: { "contact-target": "content" } }
= render Dsfr::CalloutComponent.new(title: t('.our_answer')) do |c|
- c.with_html_body do
-# i18n-tasks-use t("support.index.#{question_type}.answer_html")
= t('answer_html', scope: [:support, :index, question_type], base_url: Current.application_base_url, "link_#{question_type}": link)
-# i18n-tasks-use t("contact.index.#{question_type}.answer_html")
= t('answer_html', scope: [:contact, :index, question_type], base_url: Current.application_base_url, "link_#{question_type}": link)
- if form.for_admin?

View file

@ -14,7 +14,7 @@ en:
models:
contact_form:
invalid_email_format: 'is not valid'
support:
contact:
form:
your_question: Your question
our_answer: Our answer

View file

@ -14,7 +14,7 @@ fr:
models:
contact_form:
invalid_email_format: 'est invalide'
support:
contact:
form:
your_question: Votre question
our_answer: Notre réponse

View file

@ -224,10 +224,10 @@ Rails.application.routes.draw do
get "suivi" => "root#suivi"
post "save_locale" => "root#save_locale"
get "contact", to: "support#index"
post "contact", to: "support#create"
get "contact", to: "contact#index"
post "contact", to: "contact#create"
get "contact-admin", to: "support#admin"
get "contact-admin", to: "contact#admin"
get "mentions-legales", to: "static_pages#legal_notice"
get "declaration-accessibilite", to: "static_pages#accessibility_statement"

View file

@ -1,4 +1,4 @@
describe SupportController, question_type: :controller do
describe ContactController, question_type: :controller do
render_views
context 'signed in' do