From 9d3a18166d77988ffafa49b589b54a0a3d933306 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Fri, 18 Nov 2022 09:46:44 +0000 Subject: [PATCH] feat: copy behaviour for scheme reactivation 2 (wip) --- app/controllers/schemes_controller.rb | 2 +- app/models/scheme.rb | 10 ++++++---- app/views/schemes/show.html.erb | 2 +- app/views/schemes/toggle_active.html.erb | 4 ++-- config/locales/en.yml | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index 41d24688c..03e675d77 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -59,7 +59,7 @@ class SchemesController < ApplicationController @scheme.reactivation_date = reactivation_date @scheme.reactivation_date_type = params[:scheme][:reactivation_date_type] - if @scheme.valid? && @scheme.location_deactivation_periods.deactivations_without_reactivation.update!(reactivation_date:) + if @scheme.valid? && @scheme.scheme_deactivation_periods.deactivations_without_reactivation.update!(reactivation_date:) flash[:notice] = reactivate_success_notice redirect_to scheme_details_path(@scheme) else diff --git a/app/models/scheme.rb b/app/models/scheme.rb index b0e7ade3d..ac3226161 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -218,11 +218,13 @@ class Scheme < ApplicationRecord end def status - recent_deactivation = scheme_deactivation_periods.deactivations_without_reactivation.first - return :active if recent_deactivation.blank? - return :deactivating_soon if Time.zone.now < recent_deactivation.deactivation_date + open_deactivation = scheme_deactivation_periods.deactivations_without_reactivation.first + recent_deactivation = scheme_deactivation_periods.order("created_at").last + return :deactivated if open_deactivation&.deactivation_date.present? && Time.zone.now >= open_deactivation.deactivation_date + return :deactivating_soon if open_deactivation&.deactivation_date.present? && Time.zone.now < open_deactivation.deactivation_date + return :reactivating_soon if recent_deactivation&.reactivation_date.present? && Time.zone.now < recent_deactivation.reactivation_date - :deactivated + :active end def active? diff --git a/app/views/schemes/show.html.erb b/app/views/schemes/show.html.erb index 2c01c06f1..82b9899be 100644 --- a/app/views/schemes/show.html.erb +++ b/app/views/schemes/show.html.erb @@ -29,6 +29,6 @@ <% if @scheme.active? %> <%= govuk_button_link_to "Deactivate this scheme", scheme_new_deactivation_path(@scheme), warning: true %> <% else %> - <%= govuk_button_link_to "Reactivate this scheme", scheme_reactivate_path(@scheme) %> + <%= govuk_button_link_to "Reactivate this scheme", scheme_new_reactivation_path(@scheme) %> <% end %> <% end %> diff --git a/app/views/schemes/toggle_active.html.erb b/app/views/schemes/toggle_active.html.erb index f0bbd63d4..6cae1a4bf 100644 --- a/app/views/schemes/toggle_active.html.erb +++ b/app/views/schemes/toggle_active.html.erb @@ -12,9 +12,9 @@ <% collection_start_date = FormHandler.instance.current_collection_start_date %> <%= f.govuk_error_summary %> <%= f.govuk_radio_buttons_fieldset date_type_question(action), - legend: { text: I18n.t("questions.scheme.deactivate.apply_from") }, + legend: { text: I18n.t("questions.scheme.toggle_active.apply_from") }, caption: { text: title }, - hint: { text: I18n.t("hints.scheme.deactivate", date: collection_start_date.to_formatted_s(:govuk_date)) } do %> + hint: { text: I18n.t("hints.scheme.toggle_active", date: collection_start_date.to_formatted_s(:govuk_date)) } do %> <%= govuk_warning_text text: I18n.t("warnings.scheme.#{action}.existing_logs") %> <%= f.govuk_radio_button date_type_question(action), "default", diff --git a/config/locales/en.yml b/config/locales/en.yml index 146128216..c53c495b8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -377,7 +377,7 @@ en: deactivation: apply_from: "When should this change apply?" scheme: - deactivate: + toggle_active: apply_from: "When should this change apply?" descriptions: location: @@ -393,7 +393,7 @@ en: units: "A unit can be a bedroom in a shared house or flat, or a house with 4 bedrooms. Do not include bedrooms used for wardens, managers, volunteers or sleep-in staff." deactivation: "If the date is before %{date}, select ‘From the start of the current collection period’ because the previous period has now closed." scheme: - deactivate: "If the date is before %{date}, select ‘From the start of the current collection period’ because the previous period has now closed." + toggle_active: "If the date is before %{date}, select ‘From the start of the current collection period’ because the previous period has now closed." warnings: location: