Skip to content

Commit

Permalink
#3426 - Fix error handling on registration (#3883)
Browse files Browse the repository at this point in the history
* Fix account request error handling & view

* Fix: add flash to account_requests_controller and update javascript actions on account_requests new.html

* Refactor: Remove erroneous flash message and update script to select Essentials Bank to reveal the form with errors

* Fix: remove unnecessary flash message I had added for account_requests #create action

* Fix: Add parameter & controller method to reload form on render :new

* Refactor: Remove erroneous methods, variables, and script for re-rendering form with errors

* Fix: Add closing div tag
  • Loading branch information
westonio authored Oct 27, 2023
1 parent c0840f3 commit aac7dc4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/controllers/account_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def new

def create
@account_request = AccountRequest.new(account_request_params)
@bank_selected = true

if !verify_recaptcha(model: @account_request)
flash[:alert] = "Invalid captcha submission"
Expand Down
26 changes: 20 additions & 6 deletions app/views/account_requests/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@
<%= radio_button_tag(:account, :partner, false, class: 'form-check-input account_type') %>
<%= label_tag(:account, "I am a Partner Agency to an Essentials Bank. I distribute the diapers/period supplies that I receive from essentials banks directly to the public.", class: 'form-check-label') %>
</div>

<% if @bank_selected %>
<script type="module">
$(document).ready(function() {
const bankRadioButtons = $('.account_type[value="bank"]:not(:checked)');

if (bankRadioButtons.length > 0) {
bankRadioButtons.eq(0).click();
}
});
</script>
<% else %>
<script type="module">
$(document).ready(function() {
$('#create_bank').hide()
$('#partner_info').hide()
});
</script>
<% end %>

<script type="module">
$('.account_type').change(function() {
Expand All @@ -24,11 +43,6 @@
$('#partner_info').show()
}
})

$(document).ready(function() {
$('#create_bank').hide()
$('#partner_info').hide()
})
</script>

<div class='card-text' id='partner_info'>
Expand All @@ -46,7 +60,7 @@
<%= simple_form_for(@account_request) do |f| %>
<%= f.error_notification %>
<%= render partial: "shared/flash" %>

<div class="form-inputs">
<div class="form-inputs">
<%= f.input :name, autofocus: true %>
Expand Down
16 changes: 16 additions & 0 deletions spec/system/account_request_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,21 @@
expect(page).to have_link('here', href: 'https://humanessentials.app/users/sign_in')
end
end

context 'renders the #new template with the form and errors visible' do
it 'shows create bank form info and errors when required fields are missing' do
visit('/account_requests/new')
choose('account_bank')

fill_in 'Name', with: "Barbara Smith"
click_button 'Submit'

expect(find_field('account_bank')).to be_checked
expect(find_field('account_partner')).to_not be_checked
expect(page).to have_css('#create_bank', visible: true)
expect(page).to have_css('#partner_info', visible: :hidden)
expect(page).to have_content('Please review the problems below')
end
end
end
end

0 comments on commit aac7dc4

Please sign in to comment.