Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Citizenship#destroy #14

Merged
merged 1 commit into from
Dec 12, 2023
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
14 changes: 14 additions & 0 deletions app/assets/stylesheets/application.bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ $primary: #262626;
@import 'search_location';
@import 'visas';

.delete-button {
background: none;
color: inherit;
border: none;
padding: 0;
font: inherit;
cursor: pointer;
outline: inherit;

i {
color: $danger;
}
}

.navbar-actions {
display: flex;
}
Expand Down
14 changes: 0 additions & 14 deletions app/assets/stylesheets/visas.scss
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
.delete-button {
background: none;
color: inherit;
border: none;
padding: 0;
font: inherit;
cursor: pointer;
outline: inherit;

i {
color: $danger;
}
}

.eligible-country-container {
display: flex;
}
25 changes: 24 additions & 1 deletion app/controllers/citizenships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,30 @@ def create
end

def destroy
raise NotImplementedError, "TODO"
@citizenship = Citizenship.find(params[:id])

authorize(@citizenship)
@citizenship.destroy!

respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.replace(
"profile-citizenship-section",
partial: "profiles/citizenships"
)
end
end
end

def cancel
respond_to do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.replace(
"profile-citizenship-section",
partial: "profiles/citizenships"
)
end
end
end

private
Expand Down
4 changes: 4 additions & 0 deletions app/policies/citizenship_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ class CitizenshipPolicy < ApplicationPolicy
def create?
record.user == user
end

def destroy?
create?
end
end
16 changes: 7 additions & 9 deletions app/views/citizenships/_add_citizenship_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
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",
Expand All @@ -28,5 +19,12 @@
<div data-search-countries-target="searchResults">
</div>
<% end %>

<%= link_to(
"Cancel",
cancel_citizenships_path,
class: "btn btn-danger",
"data-turbo-stream": ""
) %>
</div>
<% end %>
19 changes: 18 additions & 1 deletion app/views/profiles/_citizenships.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,31 @@
<div>
I am a citizen of
<% if current_user.citizenships.count == 1 %>
<% citizenship = current_user.citizenships.first %>
<span class="fw-bold">
<%= current_user.citizenships.first.country.name %>
<%= citizenship.country.name %>
<%= button_to(
citizenship_path(citizenship),
method: :delete,
class: "delete-button",
form_class: "d-inline-block"
) do %>
<i class="bi bi-x-circle-fill"></i>
<% end %>
</span>
<% else %>
<ul>
<% current_user.citizenships.each do |citizenship| %>
<li>
<span class="fw-bold"><%= citizenship.country.name %></span>
<%= button_to(
citizenship_path(citizenship),
method: :delete,
class: "delete-button",
form_class: "d-inline-block"
) do %>
<i class="bi bi-x-circle-fill"></i>
<% end %>
</li>
<% end %>
</ul>
Expand Down
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
end
end
resource :choose_plan, only: [:show]
resources :citizenships, only: [:new, :create, :destroy]
resources :citizenships, only: [:new, :create, :destroy] do
collection do
get :cancel
end
end
namespace :citizenships do
resources :search_countries, only: [:index]
end
Expand Down
Loading