-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefixes phone number based on selected country
as requested in https://www.notion.so/Apply-Form-pre-fill-country-code-13efee17e5754d4fa43690f2d80f7a25, this diff enables prefixing of volunteer Phone field with international country code based on selected country to speed up the submission process. - adds a new Gem [^1] for fetching country codes - adds a new route for sending GET requests with alpha2 country params and getting back the country code - adds a feature spec for checking the implementation. This spec is currently disabled because our JS is not loading in test env. Filed a separate issue here: #61 [^1]: [Countries Gem](https://github.com/hexorx/countries).
- Loading branch information
Showing
8 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class CountriesController < ApplicationController | ||
def show | ||
country = ISO3166::Country.find_country_by_alpha2(country_params[:country]) | ||
if country | ||
render partial: "country_code", locals: { | ||
country_code: country.country_code, | ||
} | ||
end | ||
end | ||
|
||
def country_params | ||
params.require(:volunteer).permit(:country) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var phoneInput = document.getElementsByName("volunteer[phone]")[0] | ||
var countryCode = "+#{ISO3166::Country.find_country_by_alpha2(e.target.value)}" | ||
phoneInput.value = "+" + <%= country_code %> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "A volunteer fills out registration form", js: true do | ||
scenario "their phone number if prefixed with country code" do | ||
pending "fix node sass error in test" | ||
visit "/" | ||
expect(page).to have_content(I18n.t("home.index.section-titles.form")) | ||
expect do | ||
select "Romania", from: "volunteer[country]" | ||
end. | ||
to change { find_field("volunteer[phone]").value }. | ||
from(""). | ||
to("+40") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters