Skip to content

Commit f66b335

Browse files
mfoclaude
andcommitted
views: extract envoyer_dossier and reaffectation into ViewComponents
Replace inline forms with Instructeurs::EnvoyerDossierFormComponent and Instructeurs::ReaffectationFormComponent. Both use DSFR fr-input-group/fr-select-group patterns with proper label[for] binding and i18n translations (fr/en). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d9b3711 commit f66b335

14 files changed

Lines changed: 179 additions & 124 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
class Instructeurs::EnvoyerDossierFormComponent < ApplicationComponent
4+
attr_reader :dossier, :potential_recipients
5+
6+
def initialize(dossier:, potential_recipients:)
7+
@dossier = dossier
8+
@potential_recipients = potential_recipients
9+
end
10+
11+
private
12+
13+
def recipient_items
14+
potential_recipients.map { [it.email, it.id] }
15+
end
16+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
en:
2+
title: Send this file to another instructor
3+
hint: The recipient will automatically follow the file
4+
no_recipients: You are the only instructor assigned to this procedure
5+
submit: Send
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fr:
2+
title: Envoyer ce dossier à un autre instructeur
3+
hint: Le destinataire suivra automatiquement le dossier
4+
no_recipients: Vous êtes le seul instructeur assigné sur cette démarche
5+
submit: Envoyer
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<% if potential_recipients.empty? %>
2+
<p><%= t(".title") %></p>
3+
<p class="tab-paragraph"><%= t(".no_recipients") %></p>
4+
<% else %>
5+
<%= form_for dossier, url: send_to_instructeurs_instructeur_dossier_path(dossier.procedure, dossier), method: :post, html: { class: 'form recipients-form fr-mb-4w' } do |f| %>
6+
<div class="fr-select-group">
7+
<label class="fr-label fr-mb-1w" for="envoyer-dossier-select">
8+
<span id="envoyer-dossier-label"><%= t(".title") %></span>
9+
<span class="fr-hint-text"><%= t(".hint") %></span>
10+
</label>
11+
12+
<div class="fr-grid-row fr-grid-row--gutters fr-grid-row--top">
13+
<div class="fr-col-8">
14+
<react-fragment>
15+
<%= render ReactComponent.new "Select/MultipleSelect",
16+
triggerId: 'envoyer-dossier-select',
17+
'aria-labelledby': 'envoyer-dossier-label',
18+
items: recipient_items,
19+
name: 'recipients[]' %>
20+
</react-fragment>
21+
</div>
22+
23+
<div class="fr-col-4">
24+
<%= f.submit t(".submit"), class: "fr-btn" %>
25+
</div>
26+
</div>
27+
</div>
28+
<% end %>
29+
<% end %>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
class Instructeurs::ReaffectationFormComponent < ApplicationComponent
4+
attr_reader :dossier, :groupe_instructeur, :groupes_instructeurs
5+
6+
def initialize(dossier:, groupe_instructeur:, groupes_instructeurs:)
7+
@dossier = dossier
8+
@groupe_instructeur = groupe_instructeur
9+
@groupes_instructeurs = groupes_instructeurs
10+
end
11+
12+
private
13+
14+
def group_items
15+
groupes_instructeurs.map { |g| { label: g.label, value: g.id.to_s } }
16+
end
17+
end
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
en:
2+
title: "Reassign the file n° %{dossier_id} to another group"
3+
hint:
4+
one: "This file is assigned to group « %{label} ». You can reassign it to the other group"
5+
other: "This file is assigned to group « %{label} ». You can reassign it to one of the %{count} other groups"
6+
submit: Reassign the file to this group
7+
select: Select
8+
confirm: "Are you sure you want to reassign the file n° %{dossier_id} from the group « %{label} »?"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fr:
2+
title: "Réaffecter le dossier n° %{dossier_id} à un autre groupe instructeur"
3+
hint:
4+
one: "Ce dossier est affecté au groupe « %{label} ». Vous pouvez le réaffecter à lʼautre groupe instructeur"
5+
other: "Ce dossier est affecté au groupe « %{label} ». Vous pouvez le réaffecter à lʼun des %{count} autres groupes instructeurs"
6+
submit: Réaffecter le dossier à ce groupe
7+
select: Sélectionner
8+
confirm: "Êtes-vous sûr de vouloir réaffecter le dossier n° %{dossier_id} du groupe « %{label} » ?"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<div class="fr-mt-2w">
2+
<%= form_with url: reaffecter_instructeur_dossier_path(procedure_id: dossier.procedure.id, dossier_id: dossier.id), method: :post, local: true, data: { controller: 'enable-submit-if-filled', action: 'change->enable-submit-if-filled#fillCombobox' } do |form| %>
3+
<div class="fr-input-group">
4+
<label class="fr-label fr-mb-1w" for="reaffectation-input">
5+
<%= t(".title", dossier_id: dossier.id) %>
6+
7+
<span class="fr-hint-text">
8+
<%= t(".hint", label: groupe_instructeur.label, count: groupes_instructeurs.count) %>
9+
</span>
10+
</label>
11+
12+
<div class="fr-grid-row fr-grid-row--gutters fr-grid-row--bottom">
13+
<div class="fr-col-8">
14+
<react-fragment>
15+
<%= render ReactComponent.new "ComboBox/SingleComboBox",
16+
inputId: 'reaffectation-input',
17+
name: 'groupe_instructeur_id',
18+
placeholder: t(".select"),
19+
items: group_items,
20+
data: { enable_submit_if_filled_target: 'input' } %>
21+
</react-fragment>
22+
</div>
23+
24+
<div class="fr-col-4">
25+
<%= form.submit t(".submit"),
26+
class: 'fr-btn',
27+
data: { enable_submit_if_filled_target: 'submit', confirm: t(".confirm", dossier_id: dossier.id, label: groupe_instructeur.label) },
28+
disabled: true %>
29+
</div>
30+
</div>
31+
</div>
32+
<% end %>
33+
</div>

app/views/instructeurs/dossiers/_personnes_impliquees_block.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
- if local_assigns[:title].present?
2-
.tab-title= title
2+
%p.fr-text--bold.fr-mb-1w= title
33

44
- if emails_collection.present?
55
%ul.tab-list

app/views/instructeurs/dossiers/suivi_et_decision.html.erb

Lines changed: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -38,76 +38,27 @@
3838
<% end %>
3939

4040
<%# Section 2: Suivi du dossier %>
41-
<section class="fr-accordion">
42-
<h3 class="fr-accordion__title">
43-
<button
44-
class="fr-accordion__btn"
45-
aria-expanded="true"
46-
aria-controls="accordion-suivi"
47-
>
48-
<%= t('views.instructeurs.dossiers.suivi_et_decision.suivi_du_dossier') %>
49-
</button>
50-
</h3>
51-
52-
<div class="fr-collapse fr-collapse--expanded" id="accordion-suivi">
53-
<%= render partial: 'instructeurs/dossiers/envoyer_dossier_block', locals: { dossier: @dossier, potential_recipients: @potential_recipients } %>
54-
55-
<%= render partial: 'instructeurs/dossiers/personnes_impliquees_block', locals: { emails_collection: @following_instructeurs_emails, title: "Instructeurs qui suivent actuellement le dossier", blank: "Aucun instructeur ne suit ce dossier" } %>
56-
57-
<% if @previous_following_instructeurs_emails.present? %>
58-
<%= render partial: 'instructeurs/dossiers/personnes_impliquees_block', locals: { emails_collection: @previous_following_instructeurs_emails, title: "Instructeurs ayant précédemment suivi le dossier", blank: " " } %>
59-
<% end %>
60-
</div>
61-
</section>
41+
<%= render Dsfr::AccordionComponent.new(id: "accordion-suivi", expanded: true) do |accordion| %>
42+
<% accordion.with_title { t('views.instructeurs.dossiers.suivi_et_decision.suivi_du_dossier') } %>
43+
44+
<%= render Instructeurs::EnvoyerDossierFormComponent.new(dossier: @dossier, potential_recipients: @potential_recipients) %>
45+
46+
<%= render partial: 'instructeurs/dossiers/personnes_impliquees_block', locals: { emails_collection: @following_instructeurs_emails, title: "Instructeurs qui suivent actuellement le dossier", blank: "Aucun instructeur ne suit ce dossier" } %>
47+
48+
<% if @previous_following_instructeurs_emails.present? %>
49+
<%= render partial: 'instructeurs/dossiers/personnes_impliquees_block', locals: { emails_collection: @previous_following_instructeurs_emails, title: "Instructeurs ayant précédemment suivi le dossier", blank: " " } %>
50+
<% end %>
51+
<% end %>
6252

6353
<%# Section 3: Affectation du dossier (conditionnel) %>
6454
<% if @dossier.procedure.routing_enabled? %>
65-
<section class="fr-accordion">
66-
<h3 class="fr-accordion__title">
67-
<button
68-
class="fr-accordion__btn"
69-
aria-expanded="true"
70-
aria-controls="accordion-affectation"
71-
>
72-
<%= t('views.instructeurs.dossiers.suivi_et_decision.affectation_du_dossier') %>
73-
</button>
74-
</h3>
75-
76-
<div class="fr-collapse fr-collapse--expanded" id="accordion-affectation">
77-
<%= render partial: 'instructeurs/dossiers/reaffectations_block', locals: { assignments: @assignments } %>
78-
79-
<div class="fr-mt-2w">
80-
<span class="fr-hint-text">
81-
<%= t('instructeurs.dossiers.reaffectation.hint', label: @groupe_instructeur.label, count: @groupes_instructeurs.count) %>
82-
</span>
55+
<%= render Dsfr::AccordionComponent.new(id: "accordion-affectation", expanded: true) do |accordion| %>
56+
<% accordion.with_title { t('views.instructeurs.dossiers.suivi_et_decision.affectation_du_dossier') } %>
8357

84-
<%= form_with url: reaffecter_instructeur_dossier_path(procedure_id: @dossier.procedure.id, dossier_id: @dossier.id), method: :post, local: true, data: { controller: 'enable-submit-if-filled', action: 'change->enable-submit-if-filled#fillCombobox' } do |form| %>
85-
<div class="fr-grid-row fr-grid-row--gutters fr-grid-row--bottom">
86-
<div class="fr-col-8">
87-
<div class="fr-select-group">
88-
<react-fragment>
89-
<%= render ReactComponent.new "ComboBox/SingleComboBox",
90-
id: 'groupe_instructeur_id',
91-
name: 'groupe_instructeur_id',
92-
placeholder: t('instructeurs.dossiers.reaffectation.select'),
93-
items: @groupes_instructeurs.map { |g| { label: g.label, value: g.id.to_s } },
94-
class: 'fr-mt-1w',
95-
data: { enable_submit_if_filled_target: 'input' } %>
96-
</react-fragment>
97-
</div>
98-
</div>
99-
100-
<div class="fr-col-4">
101-
<%= form.submit t('instructeurs.dossiers.reaffectation.submit'),
102-
class: 'fr-btn',
103-
data: { enable_submit_if_filled_target: 'submit', confirm: t('instructeurs.dossiers.reaffectation.confirm', dossier_id: @dossier.id, label: @groupe_instructeur.label) },
104-
disabled: true %>
105-
</div>
106-
</div>
107-
<% end %>
108-
</div>
109-
</div>
110-
</section>
58+
<%= render partial: 'instructeurs/dossiers/reaffectations_block', locals: { assignments: @assignments } %>
59+
60+
<%= render Instructeurs::ReaffectationFormComponent.new(dossier: @dossier, groupe_instructeur: @groupe_instructeur, groupes_instructeurs: @groupes_instructeurs) %>
61+
<% end %>
11162
<% end %>
11263

11364
<%# Section 4: Avis externes %>

0 commit comments

Comments
 (0)