diff --git a/app/components/dsfr/callout_component.rb b/app/components/dsfr/callout_component.rb index a84a67c03..cd69b9f56 100644 --- a/app/components/dsfr/callout_component.rb +++ b/app/components/dsfr/callout_component.rb @@ -4,13 +4,14 @@ class Dsfr::CalloutComponent < ApplicationComponent renders_one :html_body renders_one :bottom - attr_reader :title, :theme, :icon, :extra_class_names + attr_reader :title, :theme, :icon, :extra_class_names, :heading_level - def initialize(title:, theme: :info, icon: nil, extra_class_names: nil) + def initialize(title:, theme: :info, icon: nil, extra_class_names: nil, heading_level: 'h3') @title = title @theme = theme @icon = icon @extra_class_names = extra_class_names + @heading_level = heading_level end def callout_class diff --git a/app/components/dsfr/callout_component/callout_component.html.haml b/app/components/dsfr/callout_component/callout_component.html.haml index 8cb47f83a..7fd9697c3 100644 --- a/app/components/dsfr/callout_component/callout_component.html.haml +++ b/app/components/dsfr/callout_component/callout_component.html.haml @@ -1,6 +1,7 @@ %div{ class: callout_class } - if title.present? - %h3.fr-callout__title= title + = content_tag(heading_level, class: 'fr-callout__title') do + = title - if html_body? .fr-callout__text= html_body - if body? diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 390d4d2ac..c6672ccce 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]) + + @first_brouillon_recently_updated = current_user.dossiers.visible_by_user.brouillons_recently_updated.first end def show diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 4cd72becb..8eb6e95b5 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -296,6 +296,8 @@ class Dossier < ApplicationRecord champs: [:type_de_champ, piece_justificative_file_attachments: :blob] ]) } + + scope :brouillons_recently_updated, -> { updated_since(2.days.ago).state_brouillon.order_by_updated_at } 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 f18d86231..6e80186d2 100644 --- a/app/views/users/dossiers/index.html.haml +++ b/app/views/users/dossiers/index.html.haml @@ -8,7 +8,7 @@ .dossiers-headers.sub-header .container - %h1.page-title= t('views.users.dossiers.index.dossiers') + %h1.page-title.fr-h2= t('views.users.dossiers.index.dossiers') - if current_user.dossiers.count > 2 #search-2.fr-search-bar.fr-search-bar--lg{ role: "search", "aria-label": t('views.users.dossiers.search.search_file') } = form_tag recherche_dossiers_path, method: :get, :role => "search", class: "flex width-100 fr-mb-5w" do @@ -69,6 +69,13 @@ - else - if @statut == "en-cours" + - if @first_brouillon_recently_updated.present? + = render Dsfr::CalloutComponent.new(title: t('users.dossiers.header.callout.first_brouillon_recently_updated_title'), heading_level: 'h2') do |c| + - c.with_body do + %p + = t('users.dossiers.header.callout.first_brouillon_recently_updated_text', time_ago: time_ago_in_words(@first_brouillon_recently_updated.created_at), libelle: @first_brouillon_recently_updated.procedure.libelle ) + = link_to t('users.dossiers.header.callout.first_brouillon_recently_updated_button'), modifier_dossier_path(@first_brouillon_recently_updated), class: 'fr-btn' + = render partial: "dossiers_list", locals: { dossiers: @user_dossiers } - if @statut == "traites" diff --git a/config/locales/en.yml b/config/locales/en.yml index 0f57fb79c..1cdc3f631 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -447,7 +447,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 84c7b1dc1..df157d89f 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -448,7 +448,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..249c915cb 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: + first_brouillon_recently_updated_title: You already started to fill a file + first_brouillon_recently_updated_text: "%{time_ago} ago you started to fill a file on « %{libelle} » procedure." + first_brouillon_recently_updated_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..9f30a061a 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: + first_brouillon_recently_updated_title: Vous avez déjà commencé à remplir un dossier + first_brouillon_recently_updated_text: Il y a %{time_ago} vous avez commencé à remplir un dossier sur la démarche « %{libelle} ». + first_brouillon_recently_updated_button: Continuer à remplir diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index e395580ee..03f0c5af1 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 in brouillon recently updated' do + let!(:own_dossier) { create(:dossier, user: user) } + let!(:own_dossier_2) { create(:dossier, user: user) } + + before { get(:index) } + + it { expect(assigns(:first_brouillon_recently_updated)).to match(own_dossier_2) } + 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 71e314b64..9c15e2b53 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 'brouillons_recently_updated' do + let!(:dossier_en_brouillon) { create(:dossier) } + let!(:dossier_en_brouillon_2) { create(:dossier) } + + it { expect(Dossier.brouillons_recently_updated).to eq([dossier_en_brouillon_2, dossier_en_brouillon]) } + 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..9071a35f7 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 en brouillon récemment mis à jour' do + before do + assign(:first_brouillon_recently_updated, dossier_brouillon) + 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_brouillon)) + 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