Skip to content

Commit 37241ee

Browse files
committed
Add button to create sessions from school
This adds a button that allows users to create sessions directly from the school page, skipping the steps where you need to choose the school. Jira-Issue: MAV-2645
1 parent ccb9611 commit 37241ee

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

app/controllers/draft_sessions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def set_back_link_path
188188
elsif @draft_session.editing?
189189
wizard_path("confirm")
190190
elsif current_step == @draft_session.wizard_steps.first
191-
schools_path
191+
@draft_session.return_to == "school" ? schools_path : sessions_path
192192
else
193193
previous_wizard_path
194194
end

app/controllers/sessions_controller.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ def new
3030
@draft_session.clear_attributes
3131
@draft_session.assign_attributes(create_params)
3232

33+
if params[:school_id].present?
34+
@draft_session.location_type = "school"
35+
@draft_session.location_id = params[:school_id]
36+
@draft_session.return_to = "school"
37+
else
38+
@draft_session.return_to = "sessions"
39+
end
40+
3341
@draft_session.save!
3442

35-
redirect_to draft_session_path(Wicked::FIRST_STEP)
43+
first_step = params[:school_id].present? ? "programmes" : Wicked::FIRST_STEP
44+
redirect_to draft_session_path(first_step)
3645
end
3746

3847
def show

app/views/schools/sessions.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
<%= render "header" %>
1010

11+
<%= govuk_button_link_to "Add a new session", new_session_path(school_id: @location.id), secondary: true %>
12+
1113
<% if @scheduled_sessions.present? %>
1214
<h3 class="nhsuk-heading-m">Scheduled sessions</h3>
1315

0 commit comments

Comments
 (0)