From f3fecc40ba79d30e31c97a82324119eb37638df1 Mon Sep 17 00:00:00 2001 From: Mark Hendriksen Date: Mon, 22 Sep 2025 09:29:23 +0200 Subject: [PATCH] Add ability to delete invite codes (#153) * Add ability to delete invite codes Implemented destroy action in InviteCodesController and updated routes to support invite code deletion. Updated invite code partial to include a delete button and improved styling. Also refactored the generate tokens button in invite code settings to use DS::Button. * Show advanced settings only to admin users Updated the settings navigation to display the advanced section only for admin users. Also improved handling of hidden elements in the invite code CSS. --- app/assets/tailwind/application.css | 12 +++++++++ app/controllers/invite_codes_controller.rb | 6 +++++ app/views/invite_codes/_invite_code.html.erb | 25 +++++++++++------- app/views/settings/_settings_nav.html.erb | 26 ++++++++++--------- .../hostings/_invite_code_settings.html.erb | 11 ++++---- config/routes.rb | 2 +- 6 files changed, 54 insertions(+), 28 deletions(-) diff --git a/app/assets/tailwind/application.css b/app/assets/tailwind/application.css index bab9ea57f..05d43058d 100644 --- a/app/assets/tailwind/application.css +++ b/app/assets/tailwind/application.css @@ -172,4 +172,16 @@ &::-webkit-scrollbar-thumb:hover { background: #a6a6a6; } +} + +.invite_code [data-clipboard-target="iconDefault"], +.invite_code [data-clipboard-target="iconSuccess"] { + transition: opacity 0.2s; + opacity: 1; +} +.invite_code .hidden { + display: none !important; + opacity: 0; + pointer-events: none; + position: absolute; } \ No newline at end of file diff --git a/app/controllers/invite_codes_controller.rb b/app/controllers/invite_codes_controller.rb index fa8aa97cd..e97cb6ec0 100644 --- a/app/controllers/invite_codes_controller.rb +++ b/app/controllers/invite_codes_controller.rb @@ -11,6 +11,12 @@ class InviteCodesController < ApplicationController redirect_back_or_to invite_codes_path, notice: "Code generated" end + def destroy + code = InviteCode.find(params[:id]) + code.destroy + redirect_back_or_to invite_codes_path, notice: "Code deleted" + end + private def ensure_self_hosted diff --git a/app/views/invite_codes/_invite_code.html.erb b/app/views/invite_codes/_invite_code.html.erb index b4f52d456..0a7e6ee92 100644 --- a/app/views/invite_codes/_invite_code.html.erb +++ b/app/views/invite_codes/_invite_code.html.erb @@ -1,16 +1,21 @@ <%# app/views/invite_codes/_invite_code.html.erb %>
-
+
- <%= invite_code.token %> + <%= invite_code.token %> +
+
+ + <%= button_to invite_code_path(invite_code), method: :delete, data: { confirm: "Are you sure?" }, class: "ml-2 text-red-600 text-xs" do %> + <%= icon("trash-2", size: "sm", class: "inline mr-1") %> + <% end %>
-
diff --git a/app/views/settings/_settings_nav.html.erb b/app/views/settings/_settings_nav.html.erb index 758a810de..6e7397272 100644 --- a/app/views/settings/_settings_nav.html.erb +++ b/app/views/settings/_settings_nav.html.erb @@ -20,16 +20,18 @@ nav_sections = [ { label: t(".merchants_label"), path: family_merchants_path, icon: "store" } ] }, - { - header: t(".advanced_section_title"), - items: [ - { label: t(".ai_prompts_label"), path: settings_ai_prompts_path, icon: "bot" }, - { label: t(".api_keys_label"), path: settings_api_key_path, icon: "key" }, - { label: t(".self_hosting_label"), path: settings_hosting_path, icon: "database", if: self_hosted? }, - { label: t(".imports_label"), path: imports_path, icon: "download" }, - { label: "SimpleFin", path: simplefin_items_path, icon: "building-2" } - ] - }, + ( + Current.user.admin? ? { + header: t(".advanced_section_title"), + items: [ + { label: t(".ai_prompts_label"), path: settings_ai_prompts_path, icon: "bot" }, + { label: t(".api_keys_label"), path: settings_api_key_path, icon: "key" }, + { label: t(".self_hosting_label"), path: settings_hosting_path, icon: "database", if: self_hosted? }, + { label: t(".imports_label"), path: imports_path, icon: "download" }, + { label: "SimpleFin", path: simplefin_items_path, icon: "building-2" } + ] + } : nil + ), { header: t(".other_section_title"), items: [ @@ -54,7 +56,7 @@ nav_sections = [ <% end %>