Browse Source

feat: add specific datetimes for deactivation

pull/980/head
natdeanlewissoftwire 2 years ago
parent
commit
702db6d6fd
  1. 16
      app/controllers/schemes_controller.rb
  2. 44
      app/views/schemes/toggle_active.html.erb
  3. 2
      app/views/schemes/toggle_active_confirm.html.erb

16
app/controllers/schemes_controller.rb

@ -22,14 +22,14 @@ class SchemesController < ApplicationController
end end
def deactivate def deactivate
if params[:confirm] && params[:deactivation_date].present? if params[:confirm] && deactivation_date.present?
if @scheme.update!(deactivation_date: params[:deactivation_date]) if @scheme.update!(deactivation_date:)
# update the logs # update the logs
end end
redirect_to scheme_details_path(@scheme) redirect_to scheme_details_path(@scheme)
return return
elsif params[:deactivation_date].present? elsif deactivation_date.present?
render "toggle_active_confirm", locals: { action: "deactivate", deactivation_date: params[:deactivation_date] } render "toggle_active_confirm", locals: { action: "deactivate", deactivation_date: }
return return
end end
render "toggle_active", locals: { action: "deactivate" } render "toggle_active", locals: { action: "deactivate" }
@ -141,6 +141,14 @@ class SchemesController < ApplicationController
render "schemes/support_services_provider" render "schemes/support_services_provider"
end end
def deactivation_date
if params[:deactivation_date] == "other"
Time.utc(params["deactivation_date(1i)"].to_i, params["deactivation_date(2i)"].to_i, params["deactivation_date(3i)"].to_i)
else
params[:deactivation_date]
end
end
private private
def validation_errors(scheme_params) def validation_errors(scheme_params)

44
app/views/schemes/toggle_active.html.erb

@ -1,20 +1,38 @@
<% content_for :before_content do %>
<%= govuk_back_link(
text: "Back",
href: :back,
) %>
<% end %>
<%= form_with url: scheme_deactivate_path(@scheme), method: "get", local: true do |f| %> <%= form_with url: scheme_deactivate_path(@scheme), method: "get", local: true do |f| %>
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<% end %>
<h1 class="govuk-heading-l"> <h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @scheme.service_name %></span> <span class="govuk-caption-l"><%= @scheme.service_name %></span>
<%= "When should this change apply?" %> <%= "When should this change apply?" %>
</h1> </h1>
<%= govuk_warning_text text: "It will not be possible to add logs with this scheme if their tenancy start date is on or after the date you enter. Any existing logs may be affected." %> <div class="govuk-grid-row">
<div class="govuk-hint"> <div class="govuk-grid-column-two-thirds">
If the date is before 5 April 2022, select 'From the start of the current collection period' because the previous period has now closed. <%#= f.govuk_error_summary %>
<%= f.govuk_radio_buttons_fieldset :deactivation_date,
legend: nil,
hint: { text: "If the date is before 5 April 2022, select ‘From the start of the current collection period’ because the previous period has now closed."} do %>
<%= govuk_warning_text text: "It will not be possible to add logs with this scheme if their tenancy start date is on or after the date you enter. Any existing logs may be affected." %>
<%= f.govuk_radio_button :deactivation_date,
Time.utc(2022, 4, 1),
label: { text: "From the start of the current collection period (5 April 2022)" } %>
<%= f.govuk_radio_button :deactivation_date,
"other",
label: { text: "For tenancies starting after a certain date" },
**basic_conditional_html_attributes({"deactivation_date" => ["other"]}, "scheme") do %>
<%= f.govuk_date_field :deactivation_date,
legend: { text: "Date", size: "m" },
hint: { text: "For example, 27 3 2008" },
width: 20 %>
<% end %>
<% end %>
<%= f.govuk_submit "Continue" %>
</div>
</div> </div>
<% selection = [OpenStruct.new(date: Time.zone.now, name: "From the start of the current collection period (5 April 2022)"), OpenStruct.new(date: Time.zone.now, name: "For tenancies starting after a certain date")] %>
<%= f.govuk_collection_radio_buttons :deactivation_date,
selection,
:date,
:name,
legend: nil %>
<%= f.govuk_submit "Continue" %>
<% end %> <% end %>

2
app/views/schemes/toggle_active_confirm.html.erb

@ -8,7 +8,7 @@
</h1> </h1>
<%= govuk_warning_text text: "Your data providers will need to review these logs and answer a few questions again. We’ll email each log creator with a list of logs that need updating." %> <%= govuk_warning_text text: "Your data providers will need to review these logs and answer a few questions again. We’ll email each log creator with a list of logs that need updating." %>
<%= f.hidden_field :confirm %> <%= f.hidden_field :confirm %>
<%= f.hidden_field :deactivation_date, :value => params[:deactivation_date] %> <%= f.hidden_field :deactivation_date, :value => deactivation_date %>
<div class="govuk-button-group"> <div class="govuk-button-group">
<%= f.govuk_submit "Deactivate this scheme" %> <%= f.govuk_submit "Deactivate this scheme" %>
<%= govuk_button_link_to "Cancel", scheme_details_path, html: { method: :get }, secondary: true %> <%= govuk_button_link_to "Cancel", scheme_details_path, html: { method: :get }, secondary: true %>

Loading…
Cancel
Save