@@ -10,7 +10,7 @@ class DraftSessionsController < ApplicationController
1010 before_action :set_programmes , if : -> { current_step == :programmes }
1111 before_action :set_year_group_options , if : -> { current_step == :year_groups }
1212
13- with_options only : :show , if : -> { current_step == :dates_check } do
13+ with_options only : :show , if : :is_check_step? do
1414 before_action :set_catch_up_year_groups
1515 before_action :set_catch_up_patients_vaccinated_percentage
1616 before_action :set_catch_up_patients_receiving_consent_requests_count
@@ -24,7 +24,7 @@ class DraftSessionsController < ApplicationController
2424 def show
2525 authorize @session , @session . new_record? ? :new? : :edit?
2626
27- skip_step if current_step == :dates_check && should_skip_dates_check ?
27+ skip_step if is_check_step? && should_skip_check ?
2828
2929 render_wizard
3030 end
@@ -50,6 +50,8 @@ def update
5050
5151 private
5252
53+ def is_check_step? = step . end_with? ( "-check" )
54+
5355 def is_confirm_step? = step == "confirm"
5456
5557 def set_draft_session
@@ -191,11 +193,11 @@ def set_back_link_path
191193 wizard_path ( "dates" )
192194 elsif current_step == @draft_session . wizard_steps . first
193195 @draft_session . return_to == "school" ? schools_path : sessions_path
194- elsif previous_step == "dates-check"
195- # The `dates-check` page is special in that it skips forward if it
196- # doesn't need to be shown, however this leads to users getting stuck
197- # in a loop.
198- wizard_path ( "dates" )
196+ elsif is_check_step?
197+ # The checks page are special in that they skip forward if they don't
198+ # need to be shown, however this leads to users getting stuck in a
199+ # loop.
200+ wizard_path ( previous_step . split ( "-" ) . first )
199201 else
200202 previous_wizard_path
201203 end
@@ -284,6 +286,7 @@ def update_params
284286 programmes : {
285287 programme_types : [ ]
286288 } ,
289+ programmes_check : [ ] ,
287290 register_attendance : %i[ requires_registration ] ,
288291 school : %i[ location_id ] ,
289292 year_groups : {
@@ -333,7 +336,12 @@ def go_to_confirm_after_submission?
333336 # means we can't always skip straight to the confirmation page.
334337
335338 if current_step == :dates && steps . include? ( "dates-check" ) &&
336- !should_skip_dates_check?
339+ !should_skip_check?
340+ return false
341+ end
342+
343+ if current_step == :programmes && steps . include? ( "programmes-check" ) &&
344+ !should_skip_check?
337345 return false
338346 end
339347
@@ -348,19 +356,29 @@ def go_to_confirm_after_submission?
348356 return !is_confirm_step?
349357 end
350358
359+ # When first creating a session we go straight to the confirmation page
360+ # after setting the dates.
361+
351362 current_step == :dates_check ||
352363 (
353364 current_step == :dates && steps . include? ( "dates-check" ) &&
354- should_skip_dates_check ?
365+ should_skip_check ?
355366 ) || ( current_step == :dates && !steps . include? ( "dates-check" ) )
356367 end
357368
358- def should_skip_dates_check ?
369+ def should_skip_check ?
359370 if @draft_session . editing? &&
371+ @draft_session . session . programme_types ==
372+ @draft_session . programme_types &&
360373 @draft_session . session . dates == @draft_session . dates
361374 return true
362375 end
363376
377+ if @draft_session . programme_types . empty? ||
378+ @draft_session . year_groups . empty? || @draft_session . dates . empty?
379+ return true
380+ end
381+
364382 any_programme_has_high_unvaccinated_count =
365383 @draft_session . programmes . any? do |programme |
366384 programme_has_high_unvaccinated_count? ( programme )
0 commit comments