feat(Dossier::EditFooterComponent): disable submit button when inligibilite_rules matches
This commit is contained in:
parent
5644692448
commit
2210db3b81
6 changed files with 83 additions and 5 deletions
|
@ -1,4 +1,6 @@
|
|||
class Dossiers::EditFooterComponent < ApplicationComponent
|
||||
delegate :can_passer_en_construction?, :ineligibilite_rules_computable?, to: :@dossier
|
||||
|
||||
def initialize(dossier:, annotation:)
|
||||
@dossier = dossier
|
||||
@annotation = annotation
|
||||
|
@ -14,24 +16,37 @@ class Dossiers::EditFooterComponent < ApplicationComponent
|
|||
@annotation.present?
|
||||
end
|
||||
|
||||
def disabled_submit_buttons_options
|
||||
{
|
||||
class: 'fr-text--sm fr-mb-0 fr-mr-2w',
|
||||
data: { 'fr-opened': "true" },
|
||||
aria: { controls: 'modal-eligibilite-rules-dialog' }
|
||||
}
|
||||
end
|
||||
|
||||
def submit_draft_button_options
|
||||
{
|
||||
class: 'fr-btn fr-btn--sm',
|
||||
disabled: !owner?,
|
||||
disabled: !owner? || ineligibilite_rules_invalid?,
|
||||
method: :post,
|
||||
data: { 'disable-with': t('.submitting'), controller: 'autosave-submit' }
|
||||
data: { 'disable-with': t('.submitting'), controller: 'autosave-submit', turbo_force: :server }
|
||||
}
|
||||
end
|
||||
|
||||
def submit_en_construction_button_options
|
||||
{
|
||||
class: 'fr-btn fr-btn--sm',
|
||||
disabled: ineligibilite_rules_invalid?,
|
||||
method: :post,
|
||||
data: { 'disable-with': t('.submitting'), controller: 'autosave-submit' },
|
||||
data: { 'disable-with': t('.submitting'), controller: 'autosave-submit', turbo_force: :server },
|
||||
form: { id: "form-submit-en-construction" }
|
||||
}
|
||||
end
|
||||
|
||||
def ineligibilite_rules_invalid?
|
||||
ineligibilite_rules_computable? && !can_passer_en_construction?
|
||||
end
|
||||
|
||||
def render?
|
||||
!@dossier.for_procedure_preview?
|
||||
end
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
en:
|
||||
submit: Submit the file
|
||||
submit_changes: Submit file changes
|
||||
submit_disabled: File submission disabled
|
||||
submitting: Submitting…
|
||||
invite_notice: You are invited to make amendments to this file but <strong>only the owner themselves can submit it</strong>.
|
||||
|
|
|
@ -2,5 +2,6 @@
|
|||
fr:
|
||||
submit: Déposer le dossier
|
||||
submit_changes: Déposer les modifications
|
||||
submit_disabled: Pourquoi je ne peux pas déposer mon dossier ?
|
||||
submitting: Envoi en cours…
|
||||
invite_notice: En tant qu’invité, vous pouvez remplir ce formulaire – mais <strong>le titulaire du dossier doit le déposer lui-même</strong>.
|
||||
|
|
|
@ -3,8 +3,13 @@
|
|||
= render Dossiers::AutosaveFooterComponent.new(dossier: @dossier, annotation: annotation?)
|
||||
|
||||
- if !annotation? && @dossier.can_transition_to_en_construction?
|
||||
- if ineligibilite_rules_invalid?
|
||||
= link_to t('.submit_disabled'), "#", disabled_submit_buttons_options
|
||||
= button_to t('.submit'), brouillon_dossier_url(@dossier), submit_draft_button_options
|
||||
- elsif @dossier.forked_with_changes?
|
||||
|
||||
- if @dossier.forked_with_changes?
|
||||
- if ineligibilite_rules_invalid?
|
||||
= link_to t('.submit_disabled'), "#", disabled_submit_buttons_options
|
||||
= button_to t('.submit_changes'), modifier_dossier_url(@dossier.editing_fork_origin), submit_en_construction_button_options
|
||||
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ class Dossier < ApplicationRecord
|
|||
state :sans_suite
|
||||
|
||||
event :passer_en_construction, after: :after_passer_en_construction, after_commit: :after_commit_passer_en_construction do
|
||||
transitions from: :brouillon, to: :en_construction
|
||||
transitions from: :brouillon, to: :en_construction, guard: :can_passer_en_construction?
|
||||
end
|
||||
|
||||
event :passer_en_instruction, after: :after_passer_en_instruction, after_commit: :after_commit_passer_en_instruction do
|
||||
|
@ -562,6 +562,12 @@ class Dossier < ApplicationRecord
|
|||
procedure.feature_enabled?(:blocking_pending_correction) && pending_correction?
|
||||
end
|
||||
|
||||
def can_passer_en_construction?
|
||||
return true if !revision.ineligibilite_enabled
|
||||
|
||||
!revision.ineligibilite_rules.compute(champs_for_revision(scope: :public))
|
||||
end
|
||||
|
||||
def can_passer_en_instruction?
|
||||
return false if blocked_with_pending_correction?
|
||||
|
||||
|
|
50
spec/components/dossiers/edit_footer_component_spec.rb
Normal file
50
spec/components/dossiers/edit_footer_component_spec.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
RSpec.describe Dossiers::EditFooterComponent, type: :component do
|
||||
let(:annotation) { false }
|
||||
let(:component) { Dossiers::EditFooterComponent.new(dossier:, annotation:) }
|
||||
|
||||
subject { render_inline(component).to_html }
|
||||
|
||||
before { allow(component).to receive(:owner?).and_return(true) }
|
||||
|
||||
context 'when brouillon' do
|
||||
let(:dossier) { create(:dossier, :brouillon) }
|
||||
|
||||
context 'when dossier can be submitted' do
|
||||
before { allow(component).to receive(:ineligibilite_rules_invalid?).and_return(false) }
|
||||
it 'renders submit button without disabled' do
|
||||
expect(subject).to have_selector('button', text: 'Déposer le dossier')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when dossier can not be submitted' do
|
||||
before { allow(component).to receive(:ineligibilite_rules_invalid?).and_return(true) }
|
||||
it 'renders submit button with disabled' do
|
||||
expect(subject).to have_selector('a', text: 'Pourquoi je ne peux pas déposer mon dossier ?')
|
||||
expect(subject).to have_selector('button[disabled]', text: 'Déposer le dossier')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when en construction' do
|
||||
let(:fork_origin) { create(:dossier, :en_construction) }
|
||||
let(:dossier) { fork_origin.clone(fork: true) }
|
||||
before { allow(dossier).to receive(:forked_with_changes?).and_return(true) }
|
||||
|
||||
context 'when dossier can be submitted' do
|
||||
before { allow(component).to receive(:ineligibilite_rules_invalid?).and_return(false) }
|
||||
|
||||
it 'renders submit button without disabled' do
|
||||
expect(subject).to have_selector('button', text: 'Déposer les modifications')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when dossier can not be submitted' do
|
||||
before { allow(component).to receive(:ineligibilite_rules_invalid?).and_return(true) }
|
||||
|
||||
it 'renders submit button with disabled' do
|
||||
expect(subject).to have_selector('a', text: 'Pourquoi je ne peux pas déposer mon dossier ?')
|
||||
expect(subject).to have_selector('button[disabled]', text: 'Déposer les modifications')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue