diff --git a/app/assets/stylesheets/application.bootstrap.scss b/app/assets/stylesheets/application.bootstrap.scss index 90dce17..5a0a5b5 100644 --- a/app/assets/stylesheets/application.bootstrap.scss +++ b/app/assets/stylesheets/application.bootstrap.scss @@ -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; } diff --git a/app/assets/stylesheets/visas.scss b/app/assets/stylesheets/visas.scss index 7610a70..cfc782b 100644 --- a/app/assets/stylesheets/visas.scss +++ b/app/assets/stylesheets/visas.scss @@ -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; } diff --git a/app/controllers/citizenships_controller.rb b/app/controllers/citizenships_controller.rb index 665842b..e51a296 100644 --- a/app/controllers/citizenships_controller.rb +++ b/app/controllers/citizenships_controller.rb @@ -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 diff --git a/app/policies/citizenship_policy.rb b/app/policies/citizenship_policy.rb index 89dbea8..8d8d2a5 100644 --- a/app/policies/citizenship_policy.rb +++ b/app/policies/citizenship_policy.rb @@ -2,4 +2,8 @@ class CitizenshipPolicy < ApplicationPolicy def create? record.user == user end + + def destroy? + create? + end end diff --git a/app/views/citizenships/_add_citizenship_form.html.erb b/app/views/citizenships/_add_citizenship_form.html.erb index e7a4f51..87a5c3b 100644 --- a/app/views/citizenships/_add_citizenship_form.html.erb +++ b/app/views/citizenships/_add_citizenship_form.html.erb @@ -3,15 +3,6 @@ data-controller="search-countries" data-search-countries-search-url-value=<%= citizenships_search_countries_path %> > - - <%= label_tag "I am a citizen of..." %> <%= text_field_tag( "search-countries", @@ -28,5 +19,12 @@
<% end %> + + <%= link_to( + "Cancel", + cancel_citizenships_path, + class: "btn btn-danger", + "data-turbo-stream": "" + ) %> <% end %> diff --git a/app/views/profiles/_citizenships.html.erb b/app/views/profiles/_citizenships.html.erb index 0a0198e..4dff599 100644 --- a/app/views/profiles/_citizenships.html.erb +++ b/app/views/profiles/_citizenships.html.erb @@ -10,14 +10,31 @@
I am a citizen of <% if current_user.citizenships.count == 1 %> + <% citizenship = current_user.citizenships.first %> - <%= 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 %> + + <% end %> <% else %> diff --git a/config/routes.rb b/config/routes.rb index 983577d..38e9b04 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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