refactor(routing_roules): simplify refresh conditions
This commit is contained in:
parent
3dd6a59101
commit
5aee51d5ac
2 changed files with 13 additions and 8 deletions
|
@ -556,19 +556,23 @@ module Users
|
||||||
|
|
||||||
def update_dossier_and_compute_errors
|
def update_dossier_and_compute_errors
|
||||||
@dossier.update_champs_attributes(champs_public_attributes_params, :public, updated_by: current_user.email)
|
@dossier.update_champs_attributes(champs_public_attributes_params, :public, updated_by: current_user.email)
|
||||||
if @dossier.champs.any?(&:changed_for_autosave?)
|
updated_champs = @dossier.champs.filter(&:changed_for_autosave?)
|
||||||
|
if updated_champs.present?
|
||||||
@dossier.last_champ_updated_at = Time.zone.now
|
@dossier.last_champ_updated_at = Time.zone.now
|
||||||
|
|
||||||
if @dossier.champs_public.any? { _1.changed_for_autosave? && _1.used_by_routing_rules? }
|
|
||||||
RoutingEngine.compute(@dossier)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# We save the dossier without validating fields, and if it is successful and the client
|
# We save the dossier without validating fields, and if it is successful and the client
|
||||||
# requests it, we ask for field validation errors.
|
# requests it, we ask for field validation errors.
|
||||||
if @dossier.save && params[:validate].present?
|
if @dossier.save
|
||||||
|
if updated_champs.any?(&:used_by_routing_rules?)
|
||||||
|
@update_contact_information = true
|
||||||
|
RoutingEngine.compute(@dossier)
|
||||||
|
end
|
||||||
|
|
||||||
|
if params[:validate].present?
|
||||||
@dossier.valid?(:champs_public_value)
|
@dossier.valid?(:champs_public_value)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
@dossier.errors
|
@dossier.errors
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,5 +5,6 @@
|
||||||
= turbo_stream.append('contenu', render(Dossiers::InvalidIneligibiliteRulesComponent.new(dossier: @dossier)))
|
= turbo_stream.append('contenu', render(Dossiers::InvalidIneligibiliteRulesComponent.new(dossier: @dossier)))
|
||||||
- else @ineligibilite_rules_is_computable
|
- else @ineligibilite_rules_is_computable
|
||||||
= turbo_stream.remove(dom_id(@dossier, :ineligibilite_rules_broken))
|
= turbo_stream.remove(dom_id(@dossier, :ineligibilite_rules_broken))
|
||||||
- if @dossier.champs.any? { _1.used_by_routing_rules? && params[:dossier][:champs_public_attributes].key?(_1.stable_id.to_s) }
|
|
||||||
|
- if @update_contact_information
|
||||||
= turbo_stream.update "contact_information", partial: 'shared/dossiers/update_contact_information', locals: { dossier: @dossier, procedure: @procedure }
|
= turbo_stream.update "contact_information", partial: 'shared/dossiers/update_contact_information', locals: { dossier: @dossier, procedure: @procedure }
|
||||||
|
|
Loading…
Reference in a new issue