diff --git a/app/components/form_elements/fieldset_toggle_component.html.erb b/app/components/form_elements/fieldset_toggle_component.html.erb
index f4acd3d..9965490 100644
--- a/app/components/form_elements/fieldset_toggle_component.html.erb
+++ b/app/components/form_elements/fieldset_toggle_component.html.erb
@@ -5,7 +5,9 @@
} : nil do %>
<%= render FormElements::ToggleComponent.new(
diff --git a/app/components/form_elements/fieldset_toggle_component.rb b/app/components/form_elements/fieldset_toggle_component.rb
index 686f5f1..09fd36d 100644
--- a/app/components/form_elements/fieldset_toggle_component.rb
+++ b/app/components/form_elements/fieldset_toggle_component.rb
@@ -3,7 +3,7 @@
module FormElements
class FieldsetToggleComponent < ViewComponent::Base
def initialize(tag: "li", form: nil, attribute: nil, field_name: nil,
- enabled: false, input_enabled: true, title:, description:)
+ enabled: false, input_enabled: true, title:, description: nil)
@tag = tag
@form = form
@attribute = attribute
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 1849fa6..6b6f510 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -1,7 +1,8 @@
class Admin::UsersController < Admin::BaseController
- before_action :set_user, only: [:show]
+ before_action :set_user, except: [:index]
before_action :set_current_section
+ # GET /admin/users
def index
ldap = LdapService.new
@ou = Setting.primary_domain
@@ -13,6 +14,7 @@ class Admin::UsersController < Admin::BaseController
}
end
+ # GET /admin/users/:username
def show
if Setting.lndhub_admin_enabled?
@lndhub_user = @user.lndhub_user
@@ -23,6 +25,30 @@ class Admin::UsersController < Admin::BaseController
@avatar = LdapManager::FetchAvatar.call(cn: @user.cn)
end
+ # POST /admin/users/:username/invitations
+ def create_invitations
+ amount = params[:amount].to_i
+ notify_user = ActiveRecord::Type::Boolean.new.cast(params[:notify_user])
+
+ CreateInvitations.call(user: @user, amount: amount, notify: notify_user)
+
+ redirect_to admin_user_path(@user.cn), flash: {
+ success: "Added #{amount} invitations to #{@user.cn}'s account"
+ }
+ end
+
+ # DELETE /admin/users/:username/invitations
+ def delete_invitations
+ invitations = @user.invitations.unused
+ amount = invitations.count
+
+ invitations.destroy_all
+
+ redirect_to admin_user_path(@user.cn), flash: {
+ success: "Removed #{amount} invitations from #{@user.cn}'s account"
+ }
+ end
+
private
def set_user
diff --git a/app/views/admin/users/_create_invitations.html.erb b/app/views/admin/users/_create_invitations.html.erb
new file mode 100644
index 0000000..dfffa36
--- /dev/null
+++ b/app/views/admin/users/_create_invitations.html.erb
@@ -0,0 +1,21 @@
+
Add new invitations to <%= @user.cn %>'s account
+<%= form_with(url: invitations_admin_user_path, method: :post) do |form| %>
+
+ <%= render FormElements::FieldsetComponent.new(
+ positioning: :horizontal,
+ title: "Amount"
+ ) do %>
+ <%= form.select :amount, options_for_select([
+ ["3", "3"], ["5", "5"], ["10", "10"], ["20", "20"]
+ ]) %>
+ <% end %>
+ <%= render FormElements::FieldsetToggleComponent.new(
+ field_name: "notify_user",
+ enabled: true,
+ title: "Notify user via email"
+ ) %>
+
+
+ <%= form.submit 'Add', class: "btn-md btn-blue w-full" %>
+
+<% end %>
diff --git a/app/views/admin/users/show.html.erb b/app/views/admin/users/show.html.erb
index 0003172..14f8c7d 100644
--- a/app/views/admin/users/show.html.erb
+++ b/app/views/admin/users/show.html.erb
@@ -42,27 +42,33 @@
Invitations available
-
+
<%= @user.invitations.count %>
- <%= render DropdownComponent.new(size: :small, icon_name: "edit") do %>
- <%= render DropdownLinkComponent.new(
- href: ""
- ) do %>
- Add more
- <% end %>
- <%= render DropdownLinkComponent.new(
- href: "",
- separator: true, add_class: "text-red-700"
- ) do %>
- Remove all
+
+ <%= render partial: "icons/plus-circle", locals: {
+ custom_class: "text-green-600 hover:text-green-500 -mt-2 -mb-1 h-6 w-6 inline-block"
+ } %>
+
+ <% if @user.invitations.unused.count > 0 %>
+ <%= link_to invitations_admin_user_path(@user.cn), data: {
+ turbo_method: :delete,
+ turbo_confirm: "Delete all of #{@user.cn}'s available invitations?"
+ } do %>
+ <%= render partial: "icons/x-circle", locals: {
+ custom_class: "text-red-600 hover:text-red-500 -mt-2 -mb-1 h-6 w-6 inline-block"
+ } %>
<% end %>
<% end %>
+ <%= render ModalComponent.new(show_close_button: false) do %>
+ <%= render partial: "admin/users/create_invitations",
+ locals: { user: @user } %>
+ <% end %>
diff --git a/app/views/icons/_plus-circle.html.erb b/app/views/icons/_plus-circle.html.erb
index 4291ff0..14ae0bf 100644
--- a/app/views/icons/_plus-circle.html.erb
+++ b/app/views/icons/_plus-circle.html.erb
@@ -1 +1 @@
-
\ No newline at end of file
+
diff --git a/app/views/icons/_x-circle.html.erb b/app/views/icons/_x-circle.html.erb
index 94aad5e..c1bea72 100644
--- a/app/views/icons/_x-circle.html.erb
+++ b/app/views/icons/_x-circle.html.erb
@@ -1 +1 @@
-
\ No newline at end of file
+
diff --git a/config/routes.rb b/config/routes.rb
index 8dee02d..39e69f2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -74,9 +74,14 @@ Rails.application.routes.draw do
root to: 'dashboard#index'
resources 'users', param: 'username', only: ['index', 'show'] do
-
+ member do
+ post 'invitations', to: 'users#create_invitations'
+ delete 'invitations', to: 'users#delete_invitations'
+ end
end
+ # post 'users/:username/invitations', to: 'users#create_invitations'
+
get 'invitations', to: 'invitations#index'
resources :donations