mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Hide invitation form when family is at capacity
This commit is contained in:
parent
5252388b8c
commit
2eb374676a
3 changed files with 30 additions and 5 deletions
|
|
@ -15,8 +15,8 @@ class Family < ApplicationRecord
|
||||||
scope :with_pending_invitations, -> { includes(family_invitations: :invited_by) }
|
scope :with_pending_invitations, -> { includes(family_invitations: :invited_by) }
|
||||||
|
|
||||||
def can_add_members?
|
def can_add_members?
|
||||||
# Use counter cache if available, otherwise count
|
# Check if family can accept more members (including pending invitations)
|
||||||
member_count < MAX_MEMBERS
|
(member_count + pending_invitations_count) < MAX_MEMBERS
|
||||||
end
|
end
|
||||||
|
|
||||||
def member_count
|
def member_count
|
||||||
|
|
@ -40,7 +40,7 @@ class Family < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def full?
|
def full?
|
||||||
member_count >= MAX_MEMBERS
|
(member_count + pending_invitations_count) >= MAX_MEMBERS
|
||||||
end
|
end
|
||||||
|
|
||||||
def active_invitations
|
def active_invitations
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ class FamilyInvitation < ApplicationRecord
|
||||||
|
|
||||||
before_validation :generate_token, :set_expiry, on: :create
|
before_validation :generate_token, :set_expiry, on: :create
|
||||||
|
|
||||||
# Clear family cache when invitation status changes
|
# Clear family cache when invitation status changes or is created/destroyed
|
||||||
|
after_create :clear_family_cache
|
||||||
after_update :clear_family_cache, if: :saved_change_to_status?
|
after_update :clear_family_cache, if: :saved_change_to_status?
|
||||||
after_destroy :clear_family_cache
|
after_destroy :clear_family_cache
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<!-- Invite New Member -->
|
<!-- Invite New Member -->
|
||||||
<% if policy(@family).invite? %>
|
<% if policy(@family).invite? && @family.can_add_members? %>
|
||||||
<div class="border-t pt-4">
|
<div class="border-t pt-4">
|
||||||
<h3 class="text-lg font-medium text-gray-900 dark:text-gray-100 mb-3">
|
<h3 class="text-lg font-medium text-gray-900 dark:text-gray-100 mb-3">
|
||||||
<%= t('families.show.invite_member', default: 'Invite New Member') %>
|
<%= t('families.show.invite_member', default: 'Invite New Member') %>
|
||||||
|
|
@ -141,6 +141,30 @@
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
<% elsif policy(@family).invite? %>
|
||||||
|
<!-- Family at capacity message -->
|
||||||
|
<div class="border-t pt-4">
|
||||||
|
<div class="bg-amber-50 dark:bg-amber-900/30 border border-amber-200 dark:border-amber-700 rounded-md p-4">
|
||||||
|
<div class="flex">
|
||||||
|
<div class="flex-shrink-0">
|
||||||
|
<svg class="h-5 w-5 text-amber-400" fill="currentColor" viewBox="0 0 20 20">
|
||||||
|
<path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<div class="ml-3">
|
||||||
|
<h3 class="text-sm font-medium text-amber-800 dark:text-amber-200">
|
||||||
|
Family at Capacity
|
||||||
|
</h3>
|
||||||
|
<div class="mt-2 text-sm text-amber-700 dark:text-amber-300">
|
||||||
|
<p>
|
||||||
|
Your family has reached the maximum of <%= @family.class::MAX_MEMBERS %> members (including pending invitations).
|
||||||
|
Cancel existing invitations or wait for them to expire to invite new members.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue