Merge pull request #7316 from tchak/refactor-dossier-change-state

refactor(dossier): change state with turbo
This commit is contained in:
Paul Chavard 2022-05-13 17:45:38 +02:00 committed by GitHub
commit 72e5adc694
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 35 deletions

View file

@ -124,7 +124,8 @@ module Instructeurs
flash.alert = aasm_error_message(e, target_state: :en_instruction)
end
render partial: 'state_button_refresh', locals: { dossier: dossier }
@dossier = dossier
render :change_state
end
def repasser_en_construction
@ -135,7 +136,8 @@ module Instructeurs
flash.alert = aasm_error_message(e, target_state: :en_construction)
end
render partial: 'state_button_refresh', locals: { dossier: dossier }
@dossier = dossier
render :change_state
end
def repasser_en_instruction
@ -146,7 +148,8 @@ module Instructeurs
flash.alert = aasm_error_message(e, target_state: :en_instruction)
end
render partial: 'state_button_refresh', locals: { dossier: dossier }
@dossier = dossier
render :change_state
end
def terminer
@ -174,7 +177,8 @@ module Instructeurs
flash.alert = aasm_error_message(e, target_state: target_state)
end
render partial: 'state_button_refresh', locals: { dossier: dossier }
@dossier = dossier
render :change_state
end
def create_commentaire

View file

@ -18,8 +18,8 @@
%h4 En construction
Vous permettez à l'usager de modifier ses réponses au formulaire
%li
= link_to passer_en_instruction_instructeur_dossier_path(dossier.procedure, dossier), method: :post, data: { remote: true, confirm: "Confirmez-vous le passage en instruction de ce dossier ?" } do
%li{ 'data-turbo': 'true' }
= link_to passer_en_instruction_instructeur_dossier_path(dossier.procedure, dossier), data: { turbo_method: :post, turbo_confirm: "Confirmez-vous le passage en instruction de ce dossier ?" } do
%span.icon.in-progress
.dropdown-description
%h4 Passer en instruction
@ -31,8 +31,8 @@
-# ------------------------------------------------------
%ul.dropdown-items
%li
= link_to repasser_en_construction_instructeur_dossier_path(dossier.procedure, dossier), method: :post, data: { remote:true, confirm: "Confirmez-vous le passage en construction de ce dossier ?" } do
%li{ 'data-turbo': 'true' }
= link_to repasser_en_construction_instructeur_dossier_path(dossier.procedure, dossier), data: { turbo_method: :post, turbo_confirm: "Confirmez-vous le passage en construction de ce dossier ?" } do
%span.icon.edit
.dropdown-description
%h4 Repasser en construction
@ -100,8 +100,8 @@
%p Cette attestation a été envoyée automatiquement au demandeur.
- if dossier.can_repasser_en_instruction?
%li
= link_to repasser_en_instruction_instructeur_dossier_path(dossier.procedure, dossier), method: :post, data: { remote:true, confirm: "Voulez vous remettre le dossier #{dossier.id} en instruction ?" } do
%li{ 'data-turbo': 'true' }
= link_to repasser_en_instruction_instructeur_dossier_path(dossier.procedure, dossier), data: { turbo_method: :post, turbo_confirm: "Voulez vous remettre le dossier #{dossier.id} en instruction ?" } do
%span.icon.in-progress
.dropdown-description
%h4 Repasser en instruction

View file

@ -3,7 +3,7 @@
%span.icon{ class: popup_class }
#{popup_title}
= form_tag(terminer_instructeur_dossier_path(dossier.procedure, dossier), remote: true, method: :post, class: 'form') do
= form_tag(terminer_instructeur_dossier_path(dossier.procedure, dossier), data: { turbo: true, turbo_confirm: confirm }, method: :post, multipart: true, class: 'form') do
- if title == 'Accepter'
= text_area :dossier, :motivation, class: 'motivation-text-area', placeholder: placeholder, required: false
- if dossier.procedure.attestation_template&.activated?
@ -37,4 +37,4 @@
= file_field :dossier, :justificatif_motivation, direct_upload: true
.text-right
%span.button{ onclick: 'DS.motivationCancel();' } Annuler
= button_tag 'Valider la décision', name: :process_action, value: process_action, class: 'button primary', title: title, data: { confirm: confirm }
= button_tag 'Valider la décision', name: :process_action, value: process_action, class: 'button primary', title: title

View file

@ -1,7 +0,0 @@
<%= render_flash %>
<%= render_to_element('.header-actions', partial: 'header_actions', locals: { dossier: dossier }) %>
<% attachment = dossier.justificatif_motivation.attachment %>
<% if attachment && attachment.virus_scanner.pending? %>
<%= fire_event('attachment:update', { url: attachment_url(attachment.id, { signed_id: attachment.blob.signed_id }) }.to_json ) %>
<% end %>

View file

@ -0,0 +1 @@
= turbo_stream.update_all '.header-actions', partial: 'header_actions', locals: { dossier: @dossier }

View file

@ -99,7 +99,7 @@ describe Instructeurs::DossiersController, type: :controller do
before do
sign_in(instructeur.user)
post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js'
post :passer_en_instruction, params: { procedure_id: procedure.id, dossier_id: dossier.id }, format: :turbo_stream
end
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction)) }
@ -113,7 +113,7 @@ describe Instructeurs::DossiersController, type: :controller do
it 'warns about the error' do
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
expect(response).to have_http_status(:ok)
expect(response.body).to have_text('Le dossier est déjà en instruction.')
expect(response.body).to include('Le dossier est déjà en instruction.')
end
end
@ -126,7 +126,7 @@ describe Instructeurs::DossiersController, type: :controller do
it 'warns about the error' do
expect(response).to have_http_status(:ok)
expect(response.body).to have_text('Le dossier est en ce moment accepté : il nest pas possible de le passer en instruction.')
expect(response.body).to include('Le dossier est en ce moment accepté : il nest pas possible de le passer en instruction.')
end
end
end
@ -138,7 +138,7 @@ describe Instructeurs::DossiersController, type: :controller do
sign_in(instructeur.user)
post :repasser_en_construction,
params: { procedure_id: procedure.id, dossier_id: dossier.id },
format: 'js'
format: :turbo_stream
end
it { expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction)) }
@ -151,7 +151,7 @@ describe Instructeurs::DossiersController, type: :controller do
it 'warns about the error' do
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction))
expect(response).to have_http_status(:ok)
expect(response.body).to have_text('Le dossier est déjà en construction.')
expect(response.body).to include('Le dossier est déjà en construction.')
end
end
end
@ -163,7 +163,7 @@ describe Instructeurs::DossiersController, type: :controller do
subject do
post :repasser_en_instruction,
params: { procedure_id: procedure.id, dossier_id: dossier.id },
format: 'js'
format: :turbo_stream
end
before do
@ -186,7 +186,7 @@ describe Instructeurs::DossiersController, type: :controller do
it 'warns about the error' do
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_instruction))
expect(response).to have_http_status(:ok)
expect(response.body).to have_text('Le dossier est déjà en instruction.')
expect(response.body).to include('Le dossier est déjà en instruction.')
end
end
@ -224,7 +224,7 @@ describe Instructeurs::DossiersController, type: :controller do
end
context 'simple refusal' do
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id }, format: :turbo_stream }
it 'change state to refuse' do
subject
@ -244,7 +244,7 @@ describe Instructeurs::DossiersController, type: :controller do
end
context 'refusal with a justificatif' do
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: 'js' }
subject { post :terminer, params: { process_action: "refuser", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: :turbo_stream }
it 'attachs a justificatif' do
subject
@ -264,7 +264,7 @@ describe Instructeurs::DossiersController, type: :controller do
sign_in(instructeur.user)
end
context 'without attachment' do
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id }, format: :turbo_stream }
it 'change state to sans_suite' do
subject
@ -286,7 +286,7 @@ describe Instructeurs::DossiersController, type: :controller do
end
context 'with attachment' do
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: 'js' }
subject { post :terminer, params: { process_action: "classer_sans_suite", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: :turbo_stream }
it 'change state to sans_suite' do
subject
@ -312,7 +312,7 @@ describe Instructeurs::DossiersController, type: :controller do
expect(NotificationMailer).to receive(:deliver_later)
end
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id }, format: 'js' }
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id }, format: :turbo_stream }
it 'change state to accepte' do
subject
@ -361,7 +361,7 @@ describe Instructeurs::DossiersController, type: :controller do
procedure_id: procedure.id,
dossier_id: dossier.id,
dossier: { motivation: "Yallah" }
}, format: 'js'
}, format: :turbo_stream
end
before do
@ -374,7 +374,7 @@ describe Instructeurs::DossiersController, type: :controller do
end
context 'with an attachment' do
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: 'js' }
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: :turbo_stream }
it 'change state to accepte' do
subject
@ -393,7 +393,7 @@ describe Instructeurs::DossiersController, type: :controller do
before { allow(dossier).to receive(:after_accepter) }
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: 'js' }
subject { post :terminer, params: { process_action: "accepter", procedure_id: procedure.id, dossier_id: dossier.id, dossier: { justificatif_motivation: fake_justificatif } }, format: :turbo_stream }
it 'does not close it again' do
subject
@ -402,7 +402,7 @@ describe Instructeurs::DossiersController, type: :controller do
expect(dossier.state).to eq(Dossier.states.fetch(:accepte))
expect(response).to have_http_status(:ok)
expect(response.body).to have_text('Le dossier est déjà accepté.')
expect(response.body).to include('Le dossier est déjà accepté.')
end
end
end