From 736eb96077856eb5d1de088032ca7f4fa9add50c Mon Sep 17 00:00:00 2001 From: Shivam Singhal Date: Sun, 3 Nov 2024 03:43:49 +0530 Subject: [PATCH] Add delete button to delete an org member --- app/models/accounts/user.rb | 4 ++++ .../accounts/organizations/_teams.html.erb | 20 ++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/models/accounts/user.rb b/app/models/accounts/user.rb index 156adfe61..4b79dd4e1 100644 --- a/app/models/accounts/user.rb +++ b/app/models/accounts/user.rb @@ -162,6 +162,10 @@ def role_for(organization) access_for(organization).role end + def membership_for(organization) + access_for(organization) + end + def team_for(organization) access_for(organization)&.team end diff --git a/app/views/accounts/organizations/_teams.html.erb b/app/views/accounts/organizations/_teams.html.erb index 07c5af318..02064d3d3 100644 --- a/app/views/accounts/organizations/_teams.html.erb +++ b/app/views/accounts/organizations/_teams.html.erb @@ -102,10 +102,10 @@ <% end %> <% user_role = current_user_role %> <% member_role = member.role_for(current_organization) %> - <% if can_current_user_edit_role?(member) %> - <% row.with_cell(wrap: true) do %> + <% row.with_cell(wrap: true) do %>
- <%= render V2::ModalComponent.new(title: "Edit role") do |modal| %> + <% if can_current_user_edit_role?(member) %> + <%= render V2::ModalComponent.new(title: "Edit role") do |modal| %> <% modal.with_button(scheme: :light, type: :action, size: :xxs, @@ -114,10 +114,20 @@ <% modal.with_body do %> <%= render partial: "accounts/invitations/edit_form", locals: { email: member.email, member_role: member_role } %> <% end %> -
<% end %> + <% end %> + <% if can_current_user_remove_member?(member) %> + <%= render V2::ButtonComponent.new( + scheme: :danger, + type: :button, + size: :xxs, + options: accounts_organization_membership_path(current_organization, member.membership_for(current_organization)), + html_options: { method: :delete, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to remove #{member.email} from the organization?" } }) do |b| + b.with_icon("v2/trash.svg") + end %> + <% end %> + <% end %> - <% end %> <% end %> <% end %>