From 4b6d3ee16d0fdea3baa8f71475beb323cc6aeb78 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 31 Jul 2024 16:20:49 +0200 Subject: [PATCH] refactor(contact): support => contact --- ...rt_controller.rb => contact_controller.rb} | 18 +++++++-------- ...rt_controller.ts => contact_controller.ts} | 2 +- app/models/contact_form.rb | 22 +++++++++---------- .../{support => contact}/_form.html.haml | 10 ++++----- .../{support => contact}/admin.html.haml | 0 .../{support => contact}/index.html.haml | 0 .../locales/views/{support => contact}/en.yml | 2 +- .../locales/views/{support => contact}/fr.yml | 2 +- config/routes.rb | 6 ++--- ...ler_spec.rb => contact_controller_spec.rb} | 2 +- 10 files changed, 32 insertions(+), 32 deletions(-) rename app/controllers/{support_controller.rb => contact_controller.rb} (77%) rename app/javascript/controllers/{support_controller.ts => contact_controller.ts} (95%) rename app/views/{support => contact}/_form.html.haml (89%) rename app/views/{support => contact}/admin.html.haml (100%) rename app/views/{support => contact}/index.html.haml (100%) rename config/locales/views/{support => contact}/en.yml (99%) rename config/locales/views/{support => contact}/fr.yml (99%) rename spec/controllers/{support_controller_spec.rb => contact_controller_spec.rb} (99%) diff --git a/app/controllers/support_controller.rb b/app/controllers/contact_controller.rb similarity index 77% rename from app/controllers/support_controller.rb rename to app/controllers/contact_controller.rb index f76227226..ec2805df1 100644 --- a/app/controllers/support_controller.rb +++ b/app/controllers/contact_controller.rb @@ -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]}]

#{support_form_params[:text]}" + piece_jointe: contact_form_params[:piece_jointe], + body: "[#{contact_form_params[:subject]}]

#{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) diff --git a/app/javascript/controllers/support_controller.ts b/app/javascript/controllers/contact_controller.ts similarity index 95% rename from app/javascript/controllers/support_controller.ts rename to app/javascript/controllers/contact_controller.ts index 22d947f0e..436adc913 100644 --- a/app/javascript/controllers/support_controller.ts +++ b/app/javascript/controllers/contact_controller.ts @@ -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[]; diff --git a/app/models/contact_form.rb b/app/models/contact_form.rb index c1363e0bc..4e518e598 100644 --- a/app/models/contact_form.rb +++ b/app/models/contact_form.rb @@ -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 diff --git a/app/views/support/_form.html.haml b/app/views/contact/_form.html.haml similarity index 89% rename from app/views/support/_form.html.haml rename to app/views/contact/_form.html.haml index 6e8cf2411..c284df566 100644 --- a/app/views/support/_form.html.haml +++ b/app/views/contact/_form.html.haml @@ -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? diff --git a/app/views/support/admin.html.haml b/app/views/contact/admin.html.haml similarity index 100% rename from app/views/support/admin.html.haml rename to app/views/contact/admin.html.haml diff --git a/app/views/support/index.html.haml b/app/views/contact/index.html.haml similarity index 100% rename from app/views/support/index.html.haml rename to app/views/contact/index.html.haml diff --git a/config/locales/views/support/en.yml b/config/locales/views/contact/en.yml similarity index 99% rename from config/locales/views/support/en.yml rename to config/locales/views/contact/en.yml index ca545026a..c0815a287 100644 --- a/config/locales/views/support/en.yml +++ b/config/locales/views/contact/en.yml @@ -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 diff --git a/config/locales/views/support/fr.yml b/config/locales/views/contact/fr.yml similarity index 99% rename from config/locales/views/support/fr.yml rename to config/locales/views/contact/fr.yml index 9ceaa6df6..6d5b3d629 100644 --- a/config/locales/views/support/fr.yml +++ b/config/locales/views/contact/fr.yml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 9c2239267..cc1f9f7b3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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" diff --git a/spec/controllers/support_controller_spec.rb b/spec/controllers/contact_controller_spec.rb similarity index 99% rename from spec/controllers/support_controller_spec.rb rename to spec/controllers/contact_controller_spec.rb index 4e19ffb09..44bafc57d 100644 --- a/spec/controllers/support_controller_spec.rb +++ b/spec/controllers/contact_controller_spec.rb @@ -1,4 +1,4 @@ -describe SupportController, question_type: :controller do +describe ContactController, question_type: :controller do render_views context 'signed in' do