add alert on user dashboard to edit last editable dossier

This commit is contained in:
Lisa Durand 2023-04-11 15:50:17 +02:00
parent 0d1aa5cf96
commit bc3e67ab94
10 changed files with 58 additions and 6 deletions

View file

@ -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

View file

@ -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,

View file

@ -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?

View file

@ -448,7 +448,7 @@ en:
simple: Search
secondary_menu: Secondary menu
index:
dossiers: "Files"
dossiers: "My files"
dossiers_list:
caption: My files
procedure: "Procedure"

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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) }

View file

@ -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

View file

@ -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 'naffiche 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 ny 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 'naffiche la barre donglets' 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 donglets' do