Skip to content

Commit

Permalink
Dynamic language selection working. Needs some UI enhancements and to…
Browse files Browse the repository at this point in the history
… make the toggle only available to applicants
  • Loading branch information
GeorgeCodes19 committed Sep 27, 2024
1 parent 6a21eef commit 304265f
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ def base_params
cbv_flow_invitation_params.slice(
:first_name,
:middle_name,
:language,
:last_name,
:email_address,
:snap_application_date
:snap_application_date,
).merge(site_id: site_id)
end

Expand All @@ -80,6 +81,7 @@ def cbv_flow_invitation_params
params.fetch(:cbv_flow_invitation, {}).permit(
:first_name,
:middle_name,
:language,
:last_name,
:client_id_number,
:case_number,
Expand Down
14 changes: 14 additions & 0 deletions app/app/models/cbv_flow_invitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,27 @@ class CbvFlowInvitation < ApplicationRecord
# Paystub report range
PAYSTUB_REPORT_RANGE = 90.days

VALID_LANGUAGES = Rails.application.config.i18n.available_locales.map(&:to_s).freeze
puts "VALID_LANGUAGES: #{VALID_LANGUAGES}"

belongs_to :user
has_many :cbv_flows

has_secure_token :auth_token, length: 36

before_validation :parse_snap_application_date
before_validation :format_case_number, if: :nyc_site?
before_validation :normalize_language

validates :site_id, inclusion: Rails.application.config.sites.site_ids
validates :first_name, presence: true
validates :last_name, presence: true
validates :email_address, format: { with: EMAIL_REGEX, message: :invalid_format }
validates :language, inclusion: {
in: VALID_LANGUAGES,
message: :invalid_format,
case_sensitive: false
}

# MA specific validations
validates :agency_id_number, format: { with: MA_AGENCY_ID_REGEX, message: :invalid_format }, if: :ma_site?
Expand Down Expand Up @@ -158,4 +167,9 @@ def format_case_number
self.case_number = "000#{case_number}"
end
end

def normalize_language
self.language = language.to_s.downcase if language.present?
end

end
15 changes: 15 additions & 0 deletions app/app/views/application/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
<% end %>
</em>
</div>

<nav class="usa-language">
<button type="button" class="usa-language__link">
<%= I18n.locale.to_s.upcase %>
</button>
<ul class="usa-language__submenu">
<% I18n.available_locales.each do |locale| %>
<% next if locale == I18n.locale %>
<li class="usa-language__submenu-item">
<%= link_to locale.to_s.upcase, url_for(locale: locale) %>
</li>
<% end %>
</ul>
</nav>

<% if user_signed_in? %>
<button class="usa-menu-btn"><%= t("shared.header.menu") %></button>
<% end %>
Expand Down
2 changes: 2 additions & 0 deletions app/app/views/caseworker/cbv_flow_invitations/_ma.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<%= f.text_field :agency_id_number, label: t(".invite.agency_id_number") %>
<%= f.select :language, options_for_select(CbvFlowInvitation::VALID_LANGUAGES.map { |lang| [lang.to_s.upcase, lang] }), { label: t(".invite.language") } %>
<%= f.date_picker :snap_application_date, label: t(".invite.todays_date") %>
<%= f.email_field :email_address, label: t(".invite.email_address") %>
Expand Down
2 changes: 2 additions & 0 deletions app/app/views/caseworker/cbv_flow_invitations/_nyc.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<%= f.text_field :case_number, label: t(".invite.case_number") %>
<%= f.select :language, options_for_select(CbvFlowInvitation::VALID_LANGUAGES.map { |lang| [lang.to_s.upcase, lang] }), { label: t(".invite.language") } %>
<%= f.date_picker :snap_application_date, label: t(".invite.snap_application_date") %>
<%= f.email_field :email_address, label: t(".invite.email_address") %>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<%= f.text_field :case_number, label: t(".invite.case_number") %>
<%= f.select :language, options_for_select(CbvFlowInvitation::VALID_LANGUAGES.map { |lang| [lang.to_s.upcase, lang] }), { label: t(".invite.language") } %>
<%= f.date_picker :snap_application_date, label: t(".invite.todays_date") %>
<%= f.email_field :email_address, label: t(".invite.email_address") %>
2 changes: 2 additions & 0 deletions app/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ en:
models:
cbv_flow_invitation:
attributes:
language:
invalid_format: Language must be either English (en) or Spanish (es).
agency_id_number:
blank: Enter a valid agency ID number.
invalid_format: Agency ID number must be 7 digits.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddLanguageToCbvFlowInvitations < ActiveRecord::Migration[7.1]
def change
add_column :cbv_flow_invitations, :language, :string
end
end

0 comments on commit 304265f

Please sign in to comment.