-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from jahseng-lee/feature/user-specific-visas
Feature/user specific visas
- Loading branch information
Showing
32 changed files
with
611 additions
and
237 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
app/controllers/citizenships/search_countries_controller.rb
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,21 @@ | ||
class Citizenships::SearchCountriesController < ApplicationController | ||
def index | ||
@query = params[:query] | ||
|
||
@countries = Country | ||
.search_by_name(I18n.transliterate(@query)) | ||
.limit(10) | ||
|
||
respond_to do |format| | ||
format.turbo_stream do | ||
render turbo_stream: turbo_stream.replace( | ||
"search-results", | ||
partial: "citizenships/search_results", | ||
locals: { | ||
countries: @countries, | ||
} | ||
) | ||
end | ||
end | ||
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,47 @@ | ||
class CitizenshipsController < ApplicationController | ||
def new | ||
respond_to do |format| | ||
format.turbo_stream do | ||
render turbo_stream: turbo_stream.replace( | ||
"profile-citizenship-section", | ||
partial: "citizenships/add_citizenship_form" | ||
) | ||
end | ||
end | ||
end | ||
|
||
def create | ||
@citizenship = Citizenship.new( | ||
citizenship_params.merge( | ||
user: current_user | ||
) | ||
) | ||
|
||
authorize(@citizenship) | ||
|
||
unless @citizenship.save | ||
flash.now[:error_create_citizenship] = "Oops! Something went wrong. Please try again" | ||
end | ||
|
||
respond_to do |format| | ||
format.turbo_stream do | ||
render turbo_stream: turbo_stream.replace( | ||
"profile-citizenship-section", | ||
partial: "profiles/citizenships" | ||
) | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
raise NotImplementedError, "TODO" | ||
end | ||
|
||
private | ||
|
||
def citizenship_params | ||
params.require(:citizenship).permit( | ||
:country_id | ||
) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
module VisaInformationHelper | ||
def helper_eligible_visas(country:, user:) | ||
if user.admin? || user.citizenships.none? | ||
country.visas | ||
else | ||
# Non-admin user who has added citizenships | ||
country | ||
.visas | ||
.left_joins(:eligible_countries_for_visas) | ||
.where( | ||
eligible_countries_for_visas: { | ||
country_id: user.citizenships.pluck(:country_id) | ||
} | ||
) | ||
end | ||
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
File renamed without changes.
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,4 @@ | ||
class Citizenship < ApplicationRecord | ||
belongs_to :user | ||
belongs_to :country | ||
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
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,5 @@ | ||
class CitizenshipPolicy < ApplicationPolicy | ||
def create? | ||
record.user == user | ||
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,32 @@ | ||
<%= turbo_frame_tag "profile-citizenship-section" do %> | ||
<div | ||
data-controller="search-countries" | ||
data-search-countries-search-url-value=<%= citizenships_search_countries_path %> | ||
> | ||
<ul> | ||
<li> | ||
TODO delete button for citizenships | ||
</li> | ||
<li> | ||
TODO cancel button for this section | ||
</li> | ||
</ul> | ||
|
||
<%= label_tag "I am a citizen of..." %> | ||
<%= text_field_tag( | ||
"search-countries", | ||
"", | ||
class: "form-control mb-2", | ||
placeholder: "Search countries...", | ||
data: { | ||
"search-countries-target": "searchField", | ||
action: "search-countries#searchOnDebounce" | ||
} | ||
) %> | ||
|
||
<%= turbo_frame_tag "search-results" do %> | ||
<div data-search-countries-target="searchResults"> | ||
</div> | ||
<% end %> | ||
</div> | ||
<% 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,17 @@ | ||
<%= turbo_frame_tag( | ||
"search-results", | ||
data: { | ||
"search-countries-target": "searchResults", | ||
} | ||
) do %> | ||
<% countries.each do |country| %> | ||
<%= form_for Citizenship.new do |f| %> | ||
<%= f.hidden_field :country_id, value: country.id %> | ||
|
||
<%= f.button "", class: 'btn btn-primary mb-1' do %> | ||
<i class="bi bi-plus-circle-fill" aria-hidden="true"></i> | ||
<%= country.name %> | ||
<% end %> | ||
<% end %> | ||
<% 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,49 @@ | ||
<%= turbo_frame_tag "profile-citizenship-section" do %> | ||
<% if flash[:error_create_citizenship].present? %> | ||
<div class="alert alert-danger alert-dismissible fade show" role="alert"> | ||
<%= flash[:error_create_citizenship] %> | ||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> | ||
</div> | ||
<% end %> | ||
|
||
<% if current_user.citizenships.any? %> | ||
<div> | ||
I am a citizen of | ||
<% if current_user.citizenships.count == 1 %> | ||
<span class="fw-bold"> | ||
<%= current_user.citizenships.first.country.name %> | ||
</span> | ||
<% else %> | ||
<ul> | ||
<% current_user.citizenships.each do |citizenship| %> | ||
<li> | ||
<span class="fw-bold"><%= citizenship.country.name %></span> | ||
</li> | ||
<% end %> | ||
</ul> | ||
<% end %> | ||
</div> | ||
|
||
<%= link_to( | ||
new_citizenship_path, | ||
"data-turbo-stream": "" | ||
) do %> | ||
<i class="bi bi-plus-circle-fill" aria-hidden="true"></i> | ||
Add citizenship | ||
<% end %> | ||
<% else %> | ||
<div class="mb-2"> | ||
<%= link_to( | ||
new_citizenship_path, | ||
"data-turbo-stream": "" | ||
) do %> | ||
<i class="bi bi-plus-circle-fill" aria-hidden="true"></i> | ||
Add citizenship | ||
<% end %> | ||
</div> | ||
|
||
<div class="fst-italic"> | ||
We use your citizenships to show ensure any visa information shown is relevant to you. | ||
</div> | ||
<% 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
Oops, something went wrong.