diff --git a/app/components/button_component.rb b/app/components/button_component.rb index 29bca1161a5..027cfa642a6 100644 --- a/app/components/button_component.rb +++ b/app/components/button_component.rb @@ -13,7 +13,6 @@ class ButtonComponent < BaseComponent :tag_options def initialize( - action: nil, url: nil, method: nil, icon: nil, @@ -25,7 +24,6 @@ def initialize( danger: false, **tag_options ) - @action = action @url = url @method = method @icon = icon @@ -67,6 +65,8 @@ def content end end + private + def action @action ||= begin if url diff --git a/app/components/download_button_component.rb b/app/components/download_button_component.rb index b3efc180306..206d3d1053f 100644 --- a/app/components/download_button_component.rb +++ b/app/components/download_button_component.rb @@ -6,14 +6,8 @@ class DownloadButtonComponent < ButtonComponent def initialize(file_data:, file_name:, **tag_options) super( icon: :file_download, - action: ->(**tag_options, &block) do - link_to( - "data:text/plain;charset=utf-8,#{ERB::Util.url_encode(file_data)}", - download: file_name, - **tag_options, - &block - ) - end, + url: "data:text/plain;charset=utf-8,#{ERB::Util.url_encode(file_data)}", + download: file_name, **tag_options, ) diff --git a/app/components/manageable_authenticator_component.html.erb b/app/components/manageable_authenticator_component.html.erb index 6b411585a00..d26a684a5ec 100644 --- a/app/components/manageable_authenticator_component.html.erb +++ b/app/components/manageable_authenticator_component.html.erb @@ -91,7 +91,7 @@
<%= configuration.name %>
<%= render ButtonComponent.new( - action: ->(**tag_options, &block) { link_to(manage_url, **tag_options, &block) }, + url: manage_url, type: :button, unstyled: true, class: 'no-js', diff --git a/app/components/tab_navigation_component.html.erb b/app/components/tab_navigation_component.html.erb index 005bebd90f8..894cc9d0d29 100644 --- a/app/components/tab_navigation_component.html.erb +++ b/app/components/tab_navigation_component.html.erb @@ -3,7 +3,7 @@ <% routes.each do |route| %>
  • <%= render ButtonComponent.new( - action: ->(**tag_options, &block) { link_to(route[:path], **tag_options, &block) }, + url: route[:path], big: true, outline: !is_current_path?(route[:path]), aria: { current: is_current_path?(route[:path]) ? 'page' : nil }, diff --git a/app/views/accounts/_auth_apps.html.erb b/app/views/accounts/_auth_apps.html.erb index e13de333a53..43737b5e886 100644 --- a/app/views/accounts/_auth_apps.html.erb +++ b/app/views/accounts/_auth_apps.html.erb @@ -21,9 +21,7 @@ <% if current_user.auth_app_configurations.count < IdentityConfig.store.max_auth_apps_per_account %> <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - link_to(authenticator_setup_url, **tag_options, &block) - end, + url: authenticator_setup_url, icon: :add, class: 'usa-button usa-button--outline margin-top-2', ).with_content(t('account.index.auth_app_add')) %> diff --git a/app/views/accounts/_emails.html.erb b/app/views/accounts/_emails.html.erb index 06288236f59..42f1ca61cd4 100644 --- a/app/views/accounts/_emails.html.erb +++ b/app/views/accounts/_emails.html.erb @@ -32,7 +32,7 @@
  • <% if EmailPolicy.new(current_user).can_add_email? %> <%= render ButtonComponent.new( - action: ->(**tag_options, &block) { link_to(add_email_path, **tag_options, &block) }, + url: add_email_path, outline: true, icon: :add, class: 'margin-top-2', diff --git a/app/views/accounts/_phone.html.erb b/app/views/accounts/_phone.html.erb index 0e267f47f2b..2520c325977 100644 --- a/app/views/accounts/_phone.html.erb +++ b/app/views/accounts/_phone.html.erb @@ -25,7 +25,7 @@ <% if current_user.phone_configurations.count < IdentityConfig.store.max_phone_numbers_per_account %> <%= render ButtonComponent.new( - action: ->(**tag_options, &block) { link_to(phone_setup_path, **tag_options, &block) }, + url: phone_setup_path, outline: true, icon: :add, class: 'margin-top-2', diff --git a/app/views/accounts/_piv_cac.html.erb b/app/views/accounts/_piv_cac.html.erb index 820ab08457e..8489427904b 100644 --- a/app/views/accounts/_piv_cac.html.erb +++ b/app/views/accounts/_piv_cac.html.erb @@ -2,7 +2,7 @@ <%= t('headings.account.federal_employee_id') %> -
    +
    <% MfaContext.new(current_user).piv_cac_configurations.each do |configuration| %> <%= render ManageableAuthenticatorComponent.new( configuration:, @@ -21,9 +21,7 @@ <% if current_user.piv_cac_configurations.count < IdentityConfig.store.max_piv_cac_per_account %> <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - link_to(setup_piv_cac_url, **tag_options, &block) - end, + url: setup_piv_cac_url, icon: :add, outline: true, class: 'margin-top-2', diff --git a/app/views/accounts/_webauthn_platform.html.erb b/app/views/accounts/_webauthn_platform.html.erb index 2c88023f851..69bb8e2b23f 100644 --- a/app/views/accounts/_webauthn_platform.html.erb +++ b/app/views/accounts/_webauthn_platform.html.erb @@ -20,9 +20,7 @@
    <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - link_to(webauthn_setup_path(platform: true), **tag_options, &block) - end, + url: webauthn_setup_path(platform: true), icon: :add, outline: true, class: 'margin-top-2', diff --git a/app/views/accounts/_webauthn_roaming.html.erb b/app/views/accounts/_webauthn_roaming.html.erb index 7f098d10a04..e1d113ac705 100644 --- a/app/views/accounts/_webauthn_roaming.html.erb +++ b/app/views/accounts/_webauthn_roaming.html.erb @@ -25,9 +25,7 @@
    <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - link_to(webauthn_setup_path, **tag_options, &block) - end, + url: webauthn_setup_path, icon: :add, outline: true, class: 'margin-top-2', diff --git a/app/views/accounts/actions/_generate_backup_codes.html.erb b/app/views/accounts/actions/_generate_backup_codes.html.erb index 69f9e4750cf..ab61cf19af4 100644 --- a/app/views/accounts/actions/_generate_backup_codes.html.erb +++ b/app/views/accounts/actions/_generate_backup_codes.html.erb @@ -1,7 +1,5 @@ <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - link_to(backup_code_create_path, **tag_options, &block) - end, + url: backup_code_create_path, icon: :add, class: 'usa-button usa-button--outline margin-top-2', ).with_content(t('forms.backup_code.generate')) %> diff --git a/app/views/accounts/actions/_regenerate_backup_codes.html.erb b/app/views/accounts/actions/_regenerate_backup_codes.html.erb index 9b9e4c12fe5..13904cf9df6 100644 --- a/app/views/accounts/actions/_regenerate_backup_codes.html.erb +++ b/app/views/accounts/actions/_regenerate_backup_codes.html.erb @@ -1,7 +1,5 @@ <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - link_to(backup_code_regenerate_path, **tag_options, &block) - end, + url: backup_code_regenerate_path, icon: :add, outline: true, class: 'margin-top-2', diff --git a/app/views/idv/forgot_password/new.html.erb b/app/views/idv/forgot_password/new.html.erb index fee64d56a0c..16e7303982e 100644 --- a/app/views/idv/forgot_password/new.html.erb +++ b/app/views/idv/forgot_password/new.html.erb @@ -10,15 +10,12 @@ <% c.with_action_button( - action: ->(**tag_options, &block) do - link_to(idv_enter_password_path, **tag_options, &block) - end, + url: idv_enter_password_path, ) { t('idv.forgot_password.try_again') } %> <% c.with_action_button( - action: ->(**tag_options, &block) do - button_to(idv_forgot_password_path, method: :post, **tag_options, &block) - end, + url: idv_forgot_password_path, + method: :post, outline: true, ) { t('idv.forgot_password.reset_password') } %> <% end %> diff --git a/app/views/idv/mail_only_warning/show.html.erb b/app/views/idv/mail_only_warning/show.html.erb index 2c4a7e7dea0..e687e6cd4c1 100644 --- a/app/views/idv/mail_only_warning/show.html.erb +++ b/app/views/idv/mail_only_warning/show.html.erb @@ -24,17 +24,13 @@ <% end %> <% c.with_action_button( - action: ->(**tag_options, &block) do - link_to(idv_url, **tag_options, &block) - end, + url: idv_url, big: true, wide: true, class: 'usa-button', ).with_content(t('doc_auth.buttons.continue')) %> <% c.with_action_button( - action: ->(**tag_options, &block) do - link_to(exit_url, **tag_options, &block) - end, + url: exit_url, big: true, wide: true, outline: true, diff --git a/app/views/idv/otp_verification/show.html.erb b/app/views/idv/otp_verification/show.html.erb index 74b177a15d0..b0c444118d1 100644 --- a/app/views/idv/otp_verification/show.html.erb +++ b/app/views/idv/otp_verification/show.html.erb @@ -29,9 +29,8 @@ <% end %> <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - button_to(idv_resend_otp_path, method: :post, **tag_options, &block) - end, + url: idv_resend_otp_path, + method: :post, outline: true, icon: :loop, class: 'margin-bottom-4', diff --git a/app/views/idv/phone_errors/failure.html.erb b/app/views/idv/phone_errors/failure.html.erb index 81ec17e66c3..899290424e2 100644 --- a/app/views/idv/phone_errors/failure.html.erb +++ b/app/views/idv/phone_errors/failure.html.erb @@ -34,7 +34,7 @@ <% if @gpo_letter_available %>
    <%= render ButtonComponent.new( - action: ->(**tag_options, &block) { link_to idv_request_letter_path, **tag_options, &block }, + url: idv_request_letter_path, big: true, wide: true, ).with_content(t('idv.failure.phone.rate_limited.gpo.button')) %> diff --git a/app/views/idv/phone_errors/warning.html.erb b/app/views/idv/phone_errors/warning.html.erb index 1d83f972eed..a088ebd3b77 100644 --- a/app/views/idv/phone_errors/warning.html.erb +++ b/app/views/idv/phone_errors/warning.html.erb @@ -33,7 +33,7 @@
    <%= render ButtonComponent.new( - action: ->(**tag_options, &block) { link_to idv_phone_path, **tag_options, &block }, + url: idv_phone_path, big: true, wide: true, ).with_content(t('idv.failure.phone.warning.try_again_button')) %> @@ -51,7 +51,7 @@
    <%= render ButtonComponent.new( - action: ->(**tag_options, &block) { link_to idv_request_letter_path, **tag_options, &block }, + url: idv_request_letter_path, big: true, wide: true, outline: true, diff --git a/app/views/idv/session_errors/warning.html.erb b/app/views/idv/session_errors/warning.html.erb index 97f32940ff1..389c0371f4b 100644 --- a/app/views/idv/session_errors/warning.html.erb +++ b/app/views/idv/session_errors/warning.html.erb @@ -16,7 +16,7 @@

    <%= t('idv.warning.attempts_html', count: @remaining_submit_attempts) %>

    <% c.with_action_button( - action: ->(**tag_options, &block) { link_to(@try_again_path, **tag_options, &block) }, + url: @try_again_path, class: 'margin-bottom-2', ) { t('idv.forgot_password.try_again') } %> <% end %> diff --git a/app/views/idv/unavailable/show.html.erb b/app/views/idv/unavailable/show.html.erb index f146086e85f..762fd5dd998 100644 --- a/app/views/idv/unavailable/show.html.erb +++ b/app/views/idv/unavailable/show.html.erb @@ -28,13 +28,7 @@

    <% c.with_action_button( - action: ->(**tag_options, &block) do - link_to( - return_to_sp_failure_to_proof_path(step: :unavailable, location: :unavailable), - **tag_options, - &block - ) - end, + url: return_to_sp_failure_to_proof_path(step: :unavailable, location: :unavailable), big: true, wide: true, ).with_content(t('idv.unavailable.exit_button', app_name: APP_NAME)) %> diff --git a/app/views/sign_up/cancellations/new.html.erb b/app/views/sign_up/cancellations/new.html.erb index 441b4916573..330d7bf4f8e 100644 --- a/app/views/sign_up/cancellations/new.html.erb +++ b/app/views/sign_up/cancellations/new.html.erb @@ -15,15 +15,12 @@ <% c.with_action_button( - action: ->(**tag_options, &block) do - button_to(sign_up_destroy_path, method: :delete, **tag_options, &block) - end, + url: sign_up_destroy_path, + method: :delete, ) { t('forms.buttons.cancel') } %> <% c.with_action_button( - action: ->(**tag_options, &block) do - link_to(@presenter.go_back_path, **tag_options, &block) - end, + url: @presenter.go_back_path, outline: true, ) { t('links.go_back') } %> <% end %> diff --git a/app/views/two_factor_authentication/otp_verification/show.html.erb b/app/views/two_factor_authentication/otp_verification/show.html.erb index 949b607e0ed..cb2058b83d1 100644 --- a/app/views/two_factor_authentication/otp_verification/show.html.erb +++ b/app/views/two_factor_authentication/otp_verification/show.html.erb @@ -43,18 +43,12 @@ <%= hidden_field_tag 'otp_make_default_number', @presenter.otp_make_default_number %> <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - link_to( - otp_send_path( - otp_delivery_selection_form: { - otp_delivery_preference: @presenter.otp_delivery_preference, - resend: true, - }, - ), - **tag_options, - &block - ) - end, + url: otp_send_path( + otp_delivery_selection_form: { + otp_delivery_preference: @presenter.otp_delivery_preference, + resend: true, + }, + ), outline: true, icon: :loop, class: 'margin-bottom-neg-1', diff --git a/app/views/two_factor_authentication/piv_cac_verification/show.html.erb b/app/views/two_factor_authentication/piv_cac_verification/show.html.erb index 9e093a06df7..b0141e96384 100644 --- a/app/views/two_factor_authentication/piv_cac_verification/show.html.erb +++ b/app/views/two_factor_authentication/piv_cac_verification/show.html.erb @@ -8,9 +8,7 @@
    <%= render SpinnerButtonComponent.new( - action: ->(**tag_options, &block) do - link_to(@presenter.piv_cac_service_link, **tag_options, &block) - end, + url: @presenter.piv_cac_service_link, big: true, wide: true, ).with_content(@presenter.piv_cac_capture_text) %> diff --git a/app/views/users/backup_code_setup/confirm_backup_codes.html.erb b/app/views/users/backup_code_setup/confirm_backup_codes.html.erb index 8bc49771707..5e6791c86c1 100644 --- a/app/views/users/backup_code_setup/confirm_backup_codes.html.erb +++ b/app/views/users/backup_code_setup/confirm_backup_codes.html.erb @@ -11,7 +11,7 @@

    <%= render ButtonComponent.new( - action: ->(**tag_options, &block) { link_to(authentication_methods_setup_path, **tag_options, &block) }, + url: authentication_methods_setup_path, big: true, full_width: false, class: 'margin-top-3 margin-bottom-1', @@ -24,5 +24,5 @@ class: 'usa-button usa-button--unstyled', ) do %> <%= t('forms.buttons.continue') %> - <% end %> + <% end %> <% end %> diff --git a/app/views/users/piv_cac_login/new.html.erb b/app/views/users/piv_cac_login/new.html.erb index 4420343cdc5..fa368fdeea9 100644 --- a/app/views/users/piv_cac_login/new.html.erb +++ b/app/views/users/piv_cac_login/new.html.erb @@ -7,9 +7,7 @@

    <%= render SpinnerButtonComponent.new( - action: ->(**tag_options, &block) do - link_to(@presenter.piv_cac_service_link, **tag_options, &block) - end, + url: @presenter.piv_cac_service_link, big: true, wide: true, ).with_content(@presenter.piv_cac_capture_text) %> diff --git a/app/views/users/piv_cac_recommended/show.html.erb b/app/views/users/piv_cac_recommended/show.html.erb index 3e7ef1e0167..0390f1bb1fd 100644 --- a/app/views/users/piv_cac_recommended/show.html.erb +++ b/app/views/users/piv_cac_recommended/show.html.erb @@ -9,25 +9,15 @@

    <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - button_to( - login_piv_cac_recommended_add_path, - **tag_options, - &block - ) - end, + url: login_piv_cac_recommended_add_path, + method: :post, big: true, class: 'margin-top-5 margin-bottom-2', ).with_content(t('two_factor_authentication.piv_cac_upsell.add_piv')) %> <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - button_to( - login_piv_cac_recommended_skip_path, - **tag_options, - &block - ) - end, + url: login_piv_cac_recommended_skip_path, + method: :post, unstyled: true, ).with_content(@recommended_presenter.skip_text) %> diff --git a/app/views/users/piv_cac_setup_from_sign_in/prompt.html.erb b/app/views/users/piv_cac_setup_from_sign_in/prompt.html.erb index 5a9f2dec11c..bd7f7931cfb 100644 --- a/app/views/users/piv_cac_setup_from_sign_in/prompt.html.erb +++ b/app/views/users/piv_cac_setup_from_sign_in/prompt.html.erb @@ -28,9 +28,8 @@ <% end %> <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - button_to(login_add_piv_cac_prompt_path, **tag_options, method: :post, &block) - end, + url: login_add_piv_cac_prompt_path, + method: :post, big: true, wide: true, outline: true, diff --git a/app/views/users/second_mfa_reminder/new.html.erb b/app/views/users/second_mfa_reminder/new.html.erb index 9ed32547b23..939e54457c6 100644 --- a/app/views/users/second_mfa_reminder/new.html.erb +++ b/app/views/users/second_mfa_reminder/new.html.erb @@ -8,22 +8,16 @@
    <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - button_to( - second_mfa_reminder_path, - **tag_options, - params: { add_method: true }, - &block - ) - end, + url: second_mfa_reminder_path, + method: :post, + params: { add_method: true }, big: true, full_width: true, class: 'margin-bottom-2', ).with_content(t('users.second_mfa_reminder.add_method')) %> <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - button_to(second_mfa_reminder_path, **tag_options, &block) - end, + url: second_mfa_reminder_path, + method: :post, outline: true, big: true, full_width: true, diff --git a/app/views/users/verify_personal_key/new.html.erb b/app/views/users/verify_personal_key/new.html.erb index 5e18a7f4e56..2d67c9f9aaa 100644 --- a/app/views/users/verify_personal_key/new.html.erb +++ b/app/views/users/verify_personal_key/new.html.erb @@ -21,9 +21,8 @@ <%= t('forms.personal_key.alternative') %> <%= render ButtonComponent.new( - action: ->(**tag_options, &block) do - button_to(reactivate_account_path, method: :put, **tag_options, &block) - end, + url: reactivate_account_path, + method: :put, unstyled: true, ).with_content(t('links.reverify')) %> diff --git a/spec/components/button_component_spec.rb b/spec/components/button_component_spec.rb index 57bfc72d25a..4308b83c3f3 100644 --- a/spec/components/button_component_spec.rb +++ b/spec/components/button_component_spec.rb @@ -116,22 +116,6 @@ end end - context 'with custom button action' do - it 'calls the action with content and tag_options' do - rendered = render_inline ButtonComponent.new( - action: ->(**tag_options, &block) do - content_tag(:'lg-custom-button', **tag_options, data: { extra: '' }, &block) - end, - class: 'custom-class', - ).with_content(content) - - expect(rendered).to have_css( - 'lg-custom-button[data-extra].custom-class', - text: content, - ) - end - end - context 'with url' do let(:url) { '/' } let(:options) { { url: } } diff --git a/spec/components/previews/button_component_preview.rb b/spec/components/previews/button_component_preview.rb index a3480216907..dafe4588672 100644 --- a/spec/components/previews/button_component_preview.rb +++ b/spec/components/previews/button_component_preview.rb @@ -34,16 +34,6 @@ def unstyled def danger render(ButtonComponent.new(danger: true).with_content('Button')) end - - def with_custom_action - render( - ButtonComponent.new( - action: ->(**tag_options, &block) do - content_tag(:'lg-custom-button', **tag_options, &block) - end, - ).with_content('Button'), - ) - end # @!endgroup # rubocop:disable Layout/LineLength