diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index c8de927d6..3b4308385 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -20,6 +20,10 @@ class LocationsController < ApplicationController def show; end + def deactivate; + render "toggle_active", locals: { action: "deactivate" } + end + def create if date_params_missing?(location_params) || valid_date_params?(location_params) @location = Location.new(location_params) diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb index 5fbd4bb04..65e86014e 100644 --- a/app/views/locations/show.html.erb +++ b/app/views/locations/show.html.erb @@ -21,4 +21,8 @@ <% row.action(text: "Change", href: location_edit_name_path(location_id: @location.id, id: @scheme.id)) if attr[:edit] %> <% end %> <% end %> -<% end %> \ No newline at end of file +<% end %> + +<% if !Rails.env.production? %> + <%= govuk_button_link_to "Deactivate this location", location_deactivate_path(location_id: @location.id, id: @scheme.id), warning: true %> +<% end %> diff --git a/app/views/locations/toggle_active.html.erb b/app/views/locations/toggle_active.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/config/routes.rb b/config/routes.rb index eab3d3222..ad088fe11 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -53,6 +53,7 @@ Rails.application.routes.draw do resources :locations do get "edit-name", to: "locations#edit_name" get "edit-local-authority", to: "locations#edit_local_authority" + get "deactivate", to: "locations#deactivate" end end diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index eda4a63c4..48f386fa7 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -777,6 +777,11 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content "Location name for #{location.postcode}" end + it "allows to deactivate a location" do + click_link("Deactivate this location") + expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{location.id}/deactivate") + end + context "when I press the back button" do before do click_link "Back"