Browse Source

feat: wip error behaviour

pull/980/head
natdeanlewissoftwire 2 years ago
parent
commit
71c31d73ca
  1. 25
      app/controllers/schemes_controller.rb
  2. 4
      app/views/schemes/toggle_active.html.erb
  3. 2
      app/views/schemes/toggle_active_confirm.html.erb

25
app/controllers/schemes_controller.rb

@ -22,15 +22,24 @@ class SchemesController < ApplicationController
end
def deactivate
if params[:confirm] && deactivation_date.present?
if params[:scheme] && params[:scheme][:confirm] && deactivation_date.present?
if @scheme.update!(deactivation_date:)
# update the logs
flash[:notice] = "#{@scheme.service_name} has been deactivated"
end
flash[:notice] = "#{@scheme.service_name} has been deactivated"
redirect_to scheme_details_path(@scheme)
return
elsif deactivation_date.present?
render "toggle_active_confirm", locals: { action: "deactivate", deactivation_date: }
if deactivation_date == "other"
@scheme.errors.add(:deactivation_date, message: "Enter a date")
render "toggle_active", locals: { action: "deactivate", deactivation_date: }
else
render "toggle_active_confirm", locals: { action: "deactivate", deactivation_date: }
end
return
elsif params[:scheme]
@scheme.errors.add(:deactivation_date, message: "Select one of the options")
render "toggle_active", locals: { action: "deactivate", deactivation_date: }
return
end
render "toggle_active", locals: { action: "deactivate" }
@ -143,10 +152,12 @@ class SchemesController < ApplicationController
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)
if params[:scheme].blank?
nil
elsif params[:scheme][:deactivation_date] == "other" && params[:scheme]["deactivation_date(1i)"].present? && params[:scheme]["deactivation_date(2i)"].present? && params[:scheme]["deactivation_date(3i)"].present?
Time.utc(params[:scheme]["deactivation_date(1i)"].to_i, params[:scheme]["deactivation_date(2i)"].to_i, params[:scheme]["deactivation_date(3i)"].to_i)
else
params[:deactivation_date]
params[:scheme][:deactivation_date]
end
end
@ -275,7 +286,7 @@ private
def authenticate_scope!
head :unauthorized and return unless current_user.data_coordinator? || current_user.support?
if %w[show locations primary_client_group confirm_secondary_client_group secondary_client_group support details check_answers edit_name].include?(action_name) && !((current_user.organisation == @scheme&.owning_organisation) || current_user.support?)
if %w[show locations primary_client_group confirm_secondary_client_group secondary_client_group support details check_answers edit_name deactivate].include?(action_name) && !((current_user.organisation == @scheme&.owning_organisation) || current_user.support?)
render_not_found and return
end
end

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

@ -5,7 +5,7 @@
) %>
<% end %>
<%= form_with url: scheme_deactivate_path(@scheme), method: "get", local: true do |f| %>
<%= form_with model: @scheme, url: scheme_deactivate_path(@scheme), method: "get", local: true do |f| %>
<h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @scheme.service_name %></span>
@ -13,7 +13,7 @@
</h1>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%#= f.govuk_error_summary %>
<%= f.govuk_error_summary %>
<%= f.govuk_radio_buttons_fieldset :deactivation_date,
legend: nil,
hint: { text: "If the date is before 1 April 2022, select ‘From the start of the current collection period’ because the previous period has now closed."} do %>

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

@ -1,4 +1,4 @@
<%= form_with url: scheme_deactivate_path(@scheme), method: "get", local: true do |f| %>
<%= form_with model: @scheme, url: scheme_deactivate_path(@scheme), method: "get", local: true do |f| %>
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<% end %>

Loading…
Cancel
Save