Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/stylesheets/components/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

.modal-warning {
&::before {
background-image: url('alert/warning-lg.svg');
background-image: url('status/warning.svg');
}

hr {
Expand Down
8 changes: 7 additions & 1 deletion app/components/button_component.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
class ButtonComponent < BaseComponent
attr_reader :action, :icon, :outline, :tag_options
attr_reader :action, :icon, :big, :wide, :outline, :tag_options

def initialize(
action: ->(**tag_options, &block) { button_tag(**tag_options, &block) },
icon: nil,
big: false,
wide: false,
outline: false,
**tag_options
)
@action = action
@icon = icon
@big = big
@wide = wide
@outline = outline
@tag_options = tag_options
end

def css_class
classes = ['usa-button', *tag_options[:class]]
classes << 'usa-button--big' if big
classes << 'usa-button--wide' if wide
classes << 'usa-button--outline' if outline
classes
end
Expand Down
21 changes: 21 additions & 0 deletions app/components/status_page_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%= image_tag(icon_src, width: 54, height: 54, alt: icon_alt, class: 'display-block margin-bottom-4') %>

<%= header %>

<%= content %>

<% if action_buttons? %>
<div class="margin-top-4">
<% action_buttons.each do |action| %>
<div class="margin-top-2">
<%= action %>
</div>
<% end %>
</div>
<% end %>

<% if troubleshooting_options? %>
<div class="margin-top-5">
<%= troubleshooting_options %>
</div>
<% end %>
38 changes: 38 additions & 0 deletions app/components/status_page_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class StatusPageComponent < BaseComponent
ICONS = {
warning: [],
error: [:lock],
}.freeze

renders_one :header, ::PageHeadingComponent
renders_many :action_buttons, ->(**button_options) do
ButtonComponent.new(**button_options, big: true, wide: true)
end
renders_one :troubleshooting_options
Copy link
Copy Markdown
Contributor Author

@aduth aduth Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future work should adapt app/views/shared/_troubleshooting_options.html.erb into a component, so this could be implemented as a pass-through similar to PageHeadingComponent and ButtonComponent above.

Suggested change
renders_one :troubleshooting_options
renders_one :troubleshooting_options, ::TroubleshootingOptionsComponent


attr_reader :status, :icon

def initialize(status: :error, icon: nil)
if !ICONS.key?(status)
raise ArgumentError, "`status` #{status} is invalid, expected one of #{ICONS.keys}"
end

if icon && !ICONS[status].include?(icon)
raise ArgumentError, "`icon` #{icon} is invalid, expected one of #{ICONS[status]}"
end

@icon = icon
@status = status
end

def icon_src
image_path("status/#{[status, icon].compact.join('-')}")
end

def icon_alt
# i18n-tasks-use t('components.status_page.icons.error')
# i18n-tasks-use t('components.status_page.icons.warning')
# i18n-tasks-use t('components.status_page.icons.lock')
t(icon || status, scope: [:components, :status_page, :icons])
end
end
2 changes: 1 addition & 1 deletion app/controllers/concerns/idv/phone_otp_rate_limitable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def handle_max_attempts(type)
decorated_user,
)
sign_out
render_full_width('shared/_failure', locals: { presenter: presenter })
render_full_width('two_factor_authentication/_locked', locals: { presenter: presenter })
end

def decorated_user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def handle_max_attempts(type)
decorated_user,
)
sign_out
render_full_width('shared/_failure', locals: { presenter: presenter })
render_full_width('two_factor_authentication/_locked', locals: { presenter: presenter })
end

def require_current_password
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def process_locked_out_user
current_user.decorate,
)
sign_out
render_full_width('shared/_failure', locals: { presenter: presenter })
render_full_width('two_factor_authentication/_locked', locals: { presenter: presenter })
end

def handle_valid_authentication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function Warning({
<>
<img
alt={t('errors.alt.warning')}
src={getAssetPath('alert/warning-lg.svg')}
src={getAssetPath('status/warning.svg')}
width={54}
height={54}
className="display-block margin-bottom-4"
Expand Down
21 changes: 1 addition & 20 deletions app/presenters/cancellation_presenter.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
class CancellationPresenter < FailurePresenter
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yesss down with inheritance!

include ActionView::Helpers::TranslationHelper
class CancellationPresenter
include Rails.application.routes.url_helpers

attr_reader :referer

def initialize(referer:, url_options:)
super(:warning)
@referer = referer
@url_options = url_options
end

def title
t('headings.cancellations.prompt')
end

def header
t('headings.cancellations.prompt')
end

def cancellation_warnings
[
t('users.delete.bullet_1', app_name: APP_NAME),
t('users.delete.bullet_2_loa1'),
t('users.delete.bullet_3', app_name: APP_NAME),
t('users.delete.bullet_4', app_name: APP_NAME),
]
end

def go_back_path
referer_path || two_factor_options_path
end
Expand Down
40 changes: 0 additions & 40 deletions app/presenters/failure_presenter.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
module TwoFactorAuthCode
class MaxAttemptsReachedPresenter < FailurePresenter
class MaxAttemptsReachedPresenter
include ActionView::Helpers::TranslationHelper
include ActionView::Helpers::UrlHelper

attr_reader :type, :decorated_user

def initialize(type, decorated_user)
super(:locked)
@type = type
@decorated_user = decorated_user
end

def title
t('titles.account_locked')
end

def header
t('titles.account_locked')
end

def description(view_context)
[locked_reason, please_try_again(view_context)]
end

def troubleshooting_options
[read_about_two_factor_authentication, contact_support]
end

def locked_reason
case type.to_s
when 'backup_code_login_attempts'
Expand All @@ -45,30 +27,5 @@ def locked_reason
raise "Unsupported description type: #{type}"
end
end

def please_try_again(view_context)
t(
'two_factor_authentication.please_try_again_html',
countdown: view_context.render(
CountdownComponent.new(expiration: decorated_user.lockout_time_expiration),
),
)
end

def read_about_two_factor_authentication
{
text: t('two_factor_authentication.read_about_two_factor_authentication'),
url: MarketingSite.help_url,
new_tab: true,
}
end

def contact_support
{
url: MarketingSite.contact_url,
text: t('idv.troubleshooting.options.contact_support', app_name: APP_NAME),
new_tab: true,
}
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% title t('account_reset.confirm_delete_account.title') %>
<div class="margin-y-2 padding-y-6 padding-x-4 tablet:padding-x-6 border border-error rounded-xl position-relative">
<%= image_tag(
asset_url('alert/fail-x.svg'),
asset_url('status/error.svg'),
size: '48x48',
alt: t('errors.alt.error'),
class: 'pin-top pin-x margin-top-neg-3 margin-x-auto',
Expand Down
2 changes: 1 addition & 1 deletion app/views/banned_user/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% title t('banned_user.title') %>

<%= image_tag('alert/fail-x.svg', width: 54, alt: t('errors.alt.error'), class: 'display-block margin-bottom-4') %>
<%= image_tag('status/error.svg', width: 54, alt: t('errors.alt.error'), class: 'display-block margin-bottom-4') %>
<%= render PageHeadingComponent.new.with_content(t('banned_user.title')) %>
<p>
<%= t('banned_user.details') %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/idv/shared/_document_capture.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
'id-card.svg',
'spinner.gif',
'spinner@2x.gif',
'alert/warning-lg.svg',
'status/warning.svg',
'idv/capture-tips-clean.svg',
'idv/capture-tips-surface.svg',
'idv/capture-tips-lighting.svg',
Expand Down
4 changes: 2 additions & 2 deletions app/views/idv/shared/_error.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ locals:
* options: Array of troubleshooting options.
%>
<% if local_assigns.fetch(:type, :error) == :error
image_src = 'alert/fail-x.svg'
image_src = 'status/error.svg'
troubleshooting_heading = t('idv.troubleshooting.headings.need_assistance')
alt = t('errors.alt.error')
else
image_src = 'alert/warning-lg.svg'
image_src = 'status/warning.svg'
troubleshooting_heading = t('components.troubleshooting_options.default_heading')
alt = t('errors.alt.warning')
end
Expand Down
17 changes: 0 additions & 17 deletions app/views/shared/_failure.html.erb

This file was deleted.

42 changes: 25 additions & 17 deletions app/views/sign_up/cancellations/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
<%= render 'shared/failure', presenter: @presenter %>
<% title t('headings.cancellations.prompt') %>

<p class='margin-bottom-1 text-bold'>
<%= t('sign_up.cancel.warning_header') %>
</p>
<%= render StatusPageComponent.new(status: :warning) do |c| %>
<% c.header { t('headings.cancellations.prompt') } %>

<ul class='usa-list--unstyled <%= @presenter.state_color %>-dots'>
<% @presenter.cancellation_warnings.each do |warning| %>
<li><%= warning %></li>
<% end %>
</ul>
<p>
<strong><%= t('sign_up.cancel.warning_header') %></strong>
</p>

<div class='margin-top-4'>
<%= button_to t('forms.buttons.cancel'), destroy_user_path,
method: :delete, class: 'usa-button usa-button--big usa-button--wide' %>
</div>
<ul class="usa-list">
<li><%= t('users.delete.bullet_1', app_name: APP_NAME) %></li>
<li><%= t('users.delete.bullet_2_loa1') %></li>
<li><%= t('users.delete.bullet_3', app_name: APP_NAME) %></li>
<li><%= t('users.delete.bullet_4', app_name: APP_NAME) %></li>
</ul>
Comment on lines 10 to 15
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we consider refactoring to an array of translations while we're here? One bullet would get extra APP_NAME but that would be ok

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I like the idea. It's made complicated by the fact that these texts are reused for the "Delete Account" flow, where the second bullet point can have some variability.

<li class="margin-bottom-1"><%= t('users.delete.bullet_1', app_name: APP_NAME) %></li>
<li class="margin-bottom-1"><%= current_user.decorate.delete_account_bullet_key %></li>
<li class="margin-bottom-1"><%= t('users.delete.bullet_3', app_name: APP_NAME) %></li>
<li class="margin-bottom-1"><%= t('users.delete.bullet_4', app_name: APP_NAME) %></li>

I'm not sure how best to handle that, or if it's worth the trouble to refactor it. I'll probably leave it out of this pull request though.


<div class='margin-top-2'>
<%= link_to t('links.go_back'), @presenter.go_back_path,
class: 'usa-button usa-button--big usa-button--wide usa-button--outline' %>
</div>
<% c.action_button(
action: ->(**tag_options, &block) do
button_to(destroy_user_path, method: :delete, **tag_options, &block)
end,
) { t('forms.buttons.cancel') } %>

<% c.action_button(
action: ->(**tag_options, &block) do
link_to(@presenter.go_back_path, **tag_options, &block)
end,
outline: true,
) { t('links.go_back') } %>
<% end %>
Loading