Browse Source

feat: wip error behaviour

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

23
app/controllers/schemes_controller.rb

@ -22,15 +22,24 @@ class SchemesController < ApplicationController
end end
def deactivate def deactivate
if params[:confirm] && deactivation_date.present? if params[:scheme] && params[:scheme][:confirm] && deactivation_date.present?
if @scheme.update!(deactivation_date:) if @scheme.update!(deactivation_date:)
# update the logs # update the logs
end
flash[:notice] = "#{@scheme.service_name} has been deactivated" flash[:notice] = "#{@scheme.service_name} has been deactivated"
end
redirect_to scheme_details_path(@scheme) redirect_to scheme_details_path(@scheme)
return return
elsif deactivation_date.present? elsif deactivation_date.present?
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: } 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 return
end end
render "toggle_active", locals: { action: "deactivate" } render "toggle_active", locals: { action: "deactivate" }
@ -143,10 +152,12 @@ class SchemesController < ApplicationController
end end
def deactivation_date def deactivation_date
if params[:deactivation_date] == "other" if params[:scheme].blank?
Time.utc(params["deactivation_date(1i)"].to_i, params["deactivation_date(2i)"].to_i, params["deactivation_date(3i)"].to_i) 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 else
params[:deactivation_date] params[:scheme][:deactivation_date]
end end
end end
@ -275,7 +286,7 @@ private
def authenticate_scope! def authenticate_scope!
head :unauthorized and return unless current_user.data_coordinator? || current_user.support? 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 render_not_found and return
end end
end end

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

@ -5,7 +5,7 @@
) %> ) %>
<% end %> <% 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"> <h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @scheme.service_name %></span> <span class="govuk-caption-l"><%= @scheme.service_name %></span>
@ -13,7 +13,7 @@
</h1> </h1>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%#= f.govuk_error_summary %> <%= f.govuk_error_summary %>
<%= f.govuk_radio_buttons_fieldset :deactivation_date, <%= f.govuk_radio_buttons_fieldset :deactivation_date,
legend: nil, 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 %> 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 %> <% content_for :before_content do %>
<%= govuk_back_link(href: :back) %> <%= govuk_back_link(href: :back) %>
<% end %> <% end %>

Loading…
Cancel
Save