Skip to content

Commit

Permalink
Add rather ugly invalid date error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
crutch committed Oct 7, 2023
1 parent ec5e37d commit fa03247
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
10 changes: 10 additions & 0 deletions app/controllers/steps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ def subscribe_to_deadline_notification
render 'step_subscription_updated'
end
end

rescue Date::Error => e
respond_to do |format|
format.html do
redirect_to [@journey, @current_step]
end
format.js do
render 'step_subscription_update_error'
end
end
end

def unsubscribe_deadline_notification
Expand Down
9 changes: 6 additions & 3 deletions app/views/steps/_step_footer_logged_in.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@
</div>
<%= form_tag subscribe_to_deadline_notification_journey_step_path(@current_step.journey, @current_step) , remote: true, authenticity_token: true do %>
<div class="govuk-form-group">
<span id="dob-error" class="govuk-error-message sdn-appear-link-hide">
<span class="govuk-visually-hidden">Chyba:</span> Zadali ste neplatný dátum
</span>
<div class="govuk-date-input" id="dob">
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<%= label_tag 'dob-day', 'Deň', class: "govuk-label govuk-date-input__label" %>
<%= number_field_tag 'day', current_user_step.expected_resolution_date.day, min: 1, max: 31, class: 'govuk-input govuk-date-input__input govuk-input--width-2', id: 'dob-day' %></div>
<%= number_field_tag 'day', current_user_step.expected_resolution_date.day, required: true, min: 1, max: 31, class: 'govuk-input govuk-date-input__input govuk-input--width-2', id: 'dob-day' %></div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<%= label_tag 'dob-month', 'Mesiac', class: "govuk-label govuk-date-input__label" %>
<%= number_field_tag 'month', current_user_step.expected_resolution_date.month, min: 1, max: 12, class: 'govuk-input govuk-date-input__input govuk-input--width-2', id: 'dob-month' %></div>
<%= number_field_tag 'month', current_user_step.expected_resolution_date.month, required: true, min: 1, max: 12, class: 'govuk-input govuk-date-input__input govuk-input--width-2', id: 'dob-month' %></div>
</div>
<div class="govuk-date-input__item">
<div class="govuk-form-group">
<%= label_tag 'dob-year', 'Rok', class: "govuk-label govuk-date-input__label" %>
<%= number_field_tag 'year', current_user_step.expected_resolution_date.year, min: 2023, class: 'govuk-input govuk-date-input__input govuk-input--width-2', id: 'dob-year' %></div>
<%= number_field_tag 'year', current_user_step.expected_resolution_date.year, required: true, min: 2023, class: 'govuk-input govuk-date-input__input govuk-input--width-2', id: 'dob-year' %></div>
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions app/views/steps/step_subscription_update_error.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$('#change-notification-date').find('.govuk-form-group').addClass('govuk-form-group--error')
$('#change-notification-date').find('#dob-error').removeClass('sdn-appear-link-hide')
2 changes: 2 additions & 0 deletions app/views/steps/step_subscription_updated.js.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$('#step_subscription').replaceWith('<%= j render "step_subscription", current_user_step: @user_step %>');
$('#next-steps-info').removeClass('sdn-appear-link-hide')
$('#change-notification-date').addClass('sdn-appear-link-hide')
$('#change-notification-date').find('.govuk-form-group').removeClass('govuk-form-group--error')
$('#change-notification-date').find('#dob-error').addClass('sdn-appear-link-hide')

0 comments on commit fa03247

Please sign in to comment.