amelioration(usagers.dossiers.erreurs): ETQ usager, lorsque je soumets un dossier avec des erreurs, le format des erreurs est au format du DSFR
Update app/components/dossiers/errors_full_messages.rb Update app/components/dossiers/errors_full_messages/errors_full_messages.html.haml Co-authored-by: Colin Darie <colin@darie.eu>
This commit is contained in:
parent
6abd0f8db0
commit
d8220395c8
15 changed files with 128 additions and 93 deletions
|
@ -207,9 +207,9 @@ module Users
|
|||
|
||||
def submit_brouillon
|
||||
@dossier = dossier_with_champs(pj_template: false)
|
||||
errors = submit_dossier_and_compute_errors
|
||||
@errors = submit_dossier_and_compute_errors
|
||||
|
||||
if errors.blank?
|
||||
if @errors.blank?
|
||||
@dossier.passer_en_construction!
|
||||
@dossier.process_declarative!
|
||||
@dossier.process_sva_svr!
|
||||
|
@ -218,8 +218,6 @@ module Users
|
|||
end
|
||||
redirect_to merci_dossier_path(@dossier)
|
||||
else
|
||||
flash.now.alert = errors
|
||||
|
||||
respond_to do |format|
|
||||
format.html { render :brouillon }
|
||||
format.turbo_stream
|
||||
|
@ -250,9 +248,9 @@ module Users
|
|||
|
||||
def submit_en_construction
|
||||
@dossier = dossier_with_champs(pj_template: false)
|
||||
errors = submit_dossier_and_compute_errors
|
||||
@errors = submit_dossier_and_compute_errors
|
||||
|
||||
if errors.blank?
|
||||
if @errors.blank?
|
||||
pending_correction_confirm = cast_bool(params.dig(:dossier, :pending_correction_confirm))
|
||||
editing_fork_origin = @dossier.editing_fork_origin
|
||||
editing_fork_origin.merge_fork(@dossier)
|
||||
|
@ -260,8 +258,6 @@ module Users
|
|||
|
||||
redirect_to dossier_path(editing_fork_origin)
|
||||
else
|
||||
flash.now.alert = errors
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
@dossier = @dossier.editing_fork_origin
|
||||
|
@ -279,11 +275,7 @@ module Users
|
|||
def update
|
||||
@dossier = dossier.en_construction? ? dossier.find_editing_fork(dossier.user) : dossier
|
||||
@dossier = dossier_with_champs(pj_template: false)
|
||||
errors = update_dossier_and_compute_errors
|
||||
|
||||
if errors.present?
|
||||
flash.now.alert = errors
|
||||
end
|
||||
@errors = update_dossier_and_compute_errors
|
||||
|
||||
respond_to do |format|
|
||||
format.turbo_stream do
|
||||
|
@ -531,46 +523,22 @@ module Users
|
|||
if @dossier.champs_public_all.any?(&:changed_for_autosave?)
|
||||
@dossier.last_champ_updated_at = Time.zone.now
|
||||
end
|
||||
|
||||
if !@dossier.save(**validation_options)
|
||||
errors += format_errors(errors: @dossier.errors)
|
||||
errors = @dossier.errors
|
||||
end
|
||||
|
||||
errors
|
||||
end
|
||||
|
||||
def submit_dossier_and_compute_errors
|
||||
errors = []
|
||||
|
||||
@dossier.valid?(**submit_validation_options)
|
||||
errors += format_errors(errors: @dossier.errors)
|
||||
errors += format_errors(errors: @dossier.check_mandatory_and_visible_champs)
|
||||
errors
|
||||
end
|
||||
|
||||
def format_errors(errors:)
|
||||
errors.map do |active_model_error|
|
||||
case active_model_error.class.name
|
||||
when "ActiveModel::NestedError"
|
||||
append_anchor_link(active_model_error.full_message, active_model_error.inner_error.base)
|
||||
when "ActiveModel::Error"
|
||||
append_anchor_link(active_model_error.full_message, active_model_error.base)
|
||||
else # "String"
|
||||
active_model_error
|
||||
end
|
||||
errors = @dossier.errors
|
||||
@dossier.check_mandatory_and_visible_champs.map do |error_on_champ|
|
||||
errors.import(error_on_champ)
|
||||
end
|
||||
end
|
||||
|
||||
def append_anchor_link(str_error, model)
|
||||
return str_error.full_message if !model.is_a?(Champ)
|
||||
|
||||
route_helper = @dossier.editing_fork? ? :modifier_dossier_path : :brouillon_dossier_path
|
||||
|
||||
[
|
||||
"Le champ « #{model.libelle.truncate(200)} » #{str_error}",
|
||||
helpers.link_to(t('views.users.dossiers.fix_champ'), public_send(route_helper, anchor: model.labelledby_id), class: 'error-anchor')
|
||||
].join(", ")
|
||||
rescue # case of invalid type de champ on champ
|
||||
str_error
|
||||
errors
|
||||
end
|
||||
|
||||
def ensure_ownership!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue