Browse Source

feat: wip errors

pull/980/head
natdeanlewissoftwire 2 years ago
parent
commit
6501b09d91
  1. 20
      app/controllers/schemes_controller.rb
  2. 10
      app/views/schemes/toggle_active.html.erb

20
app/controllers/schemes_controller.rb

@ -28,21 +28,27 @@ class SchemesController < ApplicationController
flash[:notice] = "#{@scheme.service_name} has been deactivated"
end
redirect_to scheme_details_path(@scheme)
return
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: }
if params[:scheme]["deactivation_date(1i)"].blank? && params[:scheme]["deactivation_date(2i)"].blank? && params[:scheme]["deactivation_date(3i)"].blank?
@scheme.errors.add(:deactivation_date, message: "Enter a date")
elsif params[:scheme]["deactivation_date(3i)"].blank?
@scheme.errors.add(:deactivation_date, message: "Enter the day")
elsif params[:scheme]["deactivation_date(2i)"].blank?
@scheme.errors.add(:deactivation_date, message: "Enter the month")
elsif params[:scheme]["deactivation_date(1i)"].blank?
@scheme.errors.add(:deactivation_date, message: "Enter the year")
end
render "toggle_active", locals: { action: "deactivate", deactivation_date: }, status: :unprocessable_entity
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
render "toggle_active", locals: { action: "deactivate", deactivation_date: }, status: :unprocessable_entity
else
render "toggle_active", locals: { action: "deactivate" }
end
render "toggle_active", locals: { action: "deactivate" }
end
def new

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

@ -6,16 +6,12 @@
<% end %>
<%= 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>
<%= "When should this change apply?" %>
</h1>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %>
<%= f.govuk_radio_buttons_fieldset :deactivation_date,
legend: nil,
legend: { text: "When should this change apply?" },
caption: { text: @scheme.service_name },
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 %>
<%= 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,
@ -26,7 +22,7 @@
"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,
<%= f.govuk_date_field :deactivation_date_field,
legend: { text: "Date", size: "m" },
hint: { text: "For example, 27 3 2008" },
width: 20 %>

Loading…
Cancel
Save