Skip to content

[Tech] Refactor Agents RDV creation wizard

Vincent Agnano requested to merge refactor/rdv-wizard into master

Created by: adipasquale

This PR refactors into quite some depth the current agent's RDV wizard before diving into this ticket that will make changes to this wizard.

The reasons for this refactor are :

  • the routes didn't feel very nice semantically
  • there was quite a lot of code duplication in the controllers
  • it should be slightly easier now to make changes to this wizard (reorder steps / change validations)
  • I personnally dislike having non-AR models mixed with the other actual AR models

Changes:

  • app/controllers/agents/rdvs/first_steps_controller.rb , second and third get all merged into a single app/controllers/agents/rdv_wizard_steps_controller.rb
  • the different step views move from app/views/agents/rdvs/first_steps/new.html.slim to app/views/agents/rdv_wizard_steps/step1.html.slim and so on
  • the last step of the wizard's form used to point to Agents::Rdvs::ThirdStepsController#create, it now points to Agents::RdvsController#create which feels more semantically correct
  • the app/models/rdv/first_step.rb , second and third get all merged into a single app/form_models/rdv_wizard.rb object. this is inspired by https://medium.com/@nicolasblanco/developing-a-wizard-or-multi-steps-forms-in-rails-d2f3b7c692ce
  • this form model object is very much refactored and tries to delegate even more to the underlying Rdv AR model. The Rdv#to_step_params method is deprecated and removed

as a reminder, here are the 3 steps of the RDV wizard

Step 1:

Screenshot 2020-04-08 at 10 56 29

Step 2 :

Screenshot 2020-04-08 at 10 58 48

Step 3 : Screenshot 2020-04-08 at 10 56 46

Merge request reports