diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 390d4d2ac..80698fde4 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -28,6 +28,8 @@ module Users @dossiers_supprimes_definitivement = current_user.deleted_dossiers.order_by_updated_at.page(page) @dossier_transfers = DossierTransfer.for_email(current_user.email).page(page) @statut = statut(@user_dossiers, @dossiers_traites, @dossiers_invites, @dossiers_supprimes_recemment, @dossiers_supprimes_definitivement, @dossier_transfers, @dossiers_close_to_expiration, params[:statut]) + + @last_dossier_editable = current_user.dossiers.last_editable end def show diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 5866700c0..9868547c1 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -65,6 +65,7 @@ class Dossier < ApplicationRecord TERMINE = [states.fetch(:accepte), states.fetch(:refuse), states.fetch(:sans_suite)] INSTRUCTION_COMMENCEE = TERMINE + [states.fetch(:en_instruction)] SOUMIS = EN_CONSTRUCTION_OU_INSTRUCTION + TERMINE + EDITABLE = [states.fetch(:brouillon), states.fetch(:en_construction)] REMAINING_DAYS_BEFORE_CLOSING = 2 INTERVAL_BEFORE_CLOSING = "#{REMAINING_DAYS_BEFORE_CLOSING} days" @@ -222,6 +223,7 @@ class Dossier < ApplicationRecord scope :state_not_en_construction, -> { where.not(state: states.fetch(:en_construction)) } scope :state_en_instruction, -> { where(state: states.fetch(:en_instruction)) } scope :state_en_construction_ou_instruction, -> { where(state: EN_CONSTRUCTION_OU_INSTRUCTION) } + scope :state_editable, -> { where(state: EDITABLE) } scope :state_instruction_commencee, -> { where(state: INSTRUCTION_COMMENCEE) } scope :state_termine, -> { where(state: TERMINE) } scope :state_not_termine, -> { where.not(state: TERMINE) } @@ -294,6 +296,7 @@ class Dossier < ApplicationRecord champs: [:type_de_champ, piece_justificative_file_attachments: :blob] ]) } + scope :last_editable, -> { not_archived.state_editable.order_by_updated_at.first } scope :with_annotations, -> { includes(champs_private: [ :type_de_champ, diff --git a/app/views/users/dossiers/index.html.haml b/app/views/users/dossiers/index.html.haml index d5db5b69c..44d0e4deb 100644 --- a/app/views/users/dossiers/index.html.haml +++ b/app/views/users/dossiers/index.html.haml @@ -9,11 +9,19 @@ .dossiers-headers.sub-header .container - if @search_terms.present? - %h1.page-title Résultat de la recherche pour « #{@search_terms} » + %h1.page-title.fr-h2 Résultat de la recherche pour « #{@search_terms} » = render partial: "dossiers_list", locals: { dossiers: @dossiers } - else - %h1.page-title= t('views.users.dossiers.index.dossiers') + %h1.page-title.fr-h2= t('views.users.dossiers.index.dossiers') + + - if @last_dossier_editable.present? + = render Dsfr::CalloutComponent.new(title: t('users.dossiers.header.callout.last_dossier_editable_title')) do |c| + - c.with_body do + %p + = t('users.dossiers.header.callout.last_dossier_editable_text', time_ago: time_ago_in_words(@last_dossier_editable.created_at), libelle: @last_dossier_editable.procedure.libelle ) + = link_to t('users.dossiers.header.callout.last_dossier_editable_button'), modifier_dossier_path(@last_dossier_editable), class: 'fr-btn' + %nav.tabs{ role: 'navigation', 'aria-label': t('views.users.dossiers.secondary_menu') } %ul - if @user_dossiers.present? diff --git a/config/locales/en.yml b/config/locales/en.yml index f5d189fb9..4250de0b9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -448,7 +448,7 @@ en: simple: Search secondary_menu: Secondary menu index: - dossiers: "Files" + dossiers: "My files" dossiers_list: caption: My files procedure: "Procedure" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index cd52c4f3a..976d65256 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -449,7 +449,7 @@ fr: simple: Rechercher secondary_menu: Menu secondaire index: - dossiers: "Dossiers" + dossiers: "Mes dossiers" dossiers_list: caption: Mes dossiers procedure: "Démarche" diff --git a/config/locales/views/users/header/en.yml b/config/locales/views/users/header/en.yml index 97dc89189..dd34344e3 100644 --- a/config/locales/views/users/header/en.yml +++ b/config/locales/views/users/header/en.yml @@ -19,3 +19,7 @@ en: button_delay_expiration: one: "Keep for %{count} more month" other: "Keep for %{count} more months" + callout: + last_dossier_editable_title: You already started to fill a file + last_dossier_editable_text: "%{time_ago} ago you started to fill a file on « %{libelle} » procedure." + last_dossier_editable_button: Keep filling this file diff --git a/config/locales/views/users/header/fr.yml b/config/locales/views/users/header/fr.yml index 049831b4f..4d2714484 100644 --- a/config/locales/views/users/header/fr.yml +++ b/config/locales/views/users/header/fr.yml @@ -19,3 +19,7 @@ fr: button_delay_expiration: one: "Conserver %{count} mois supplémentaire" other: "Conserver %{count} mois supplémentaires" + callout: + last_dossier_editable_title: Vous avez déjà commencé à remplir un dossier + last_dossier_editable_text: Il y a %{time_ago} vous avez commencé à remplir un dossier sur la démarche « %{libelle} ». + last_dossier_editable_button: Continuer à remplir diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index e395580ee..c7ab7c7a0 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -795,6 +795,15 @@ describe Users::DossiersController, type: :controller do end end + context 'when the user has dossier he can edit' do + let!(:own_dossier) { create(:dossier, user: user) } + let!(:own_dossier_2) { create(:dossier, :en_instruction, user: user) } + + before { get(:index) } + + it { expect(assigns(:last_dossier_editable)).to match(own_dossier) } + end + describe 'sort order' do before do Timecop.freeze(4.days.ago) { create(:dossier, user: user) } diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index bcdde92d6..7d1a06828 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -18,6 +18,13 @@ describe Dossier do it { expect(Dossier.without_followers.to_a).to eq([dossier_without_follower]) } end + + describe 'last_editable' do + let!(:dossier_en_construction) { create(:dossier, :en_construction) } + let!(:dossier_en_construction_2) { create(:dossier, :en_construction) } + + it { expect(Dossier.last_editable).to eq(dossier_en_construction_2) } + end end describe 'validations' do diff --git a/spec/views/users/dossiers/index.html.haml_spec.rb b/spec/views/users/dossiers/index.html.haml_spec.rb index 79ee66595..c24d0980c 100644 --- a/spec/views/users/dossiers/index.html.haml_spec.rb +++ b/spec/views/users/dossiers/index.html.haml_spec.rb @@ -36,6 +36,21 @@ describe 'users/dossiers/index.html.haml', type: :view do expect(rendered).to have_link(dossier_en_construction.id.to_s, href: dossier_path(dossier_en_construction)) end + it 'n’affiche pas une alerte pour continuer à remplir un dossier' do + expect(rendered).not_to have_selector('.fr-callout', count: 1) + end + + context 'quand il y a un dossier à éditer' do + before do + assign(:last_dossier_editable, dossier_en_construction) + render + end + it 'affiche une alerte pour continuer à remplir un dossier' do + expect(rendered).to have_selector('.fr-callout', count: 1) + expect(rendered).to have_link(href: modifier_dossier_path(dossier_en_construction)) + end + end + context 'quand il n’y a aucun dossier' do let(:user_dossiers) { [] } let(:dossiers_invites) { [] } @@ -53,7 +68,7 @@ describe 'users/dossiers/index.html.haml', type: :view do let(:dossiers_invites) { [] } it 'affiche un titre adapté' do - expect(rendered).to have_selector('h1', text: 'Dossiers') + expect(rendered).to have_selector('h1', text: 'Mes dossiers') end it 'n’affiche la barre d’onglets' do @@ -65,7 +80,7 @@ describe 'users/dossiers/index.html.haml', type: :view do let(:dossiers_invites) { create_list(:dossier, 1) } it 'affiche un titre adapté' do - expect(rendered).to have_selector('h1', text: 'Dossiers') + expect(rendered).to have_selector('h1', text: 'Mes dossiers') end it 'affiche la barre d’onglets' do