diff --git a/app/Livewire/Admin/Index.php b/app/Livewire/Admin/Index.php index 16cd9152e..7078a21e9 100644 --- a/app/Livewire/Admin/Index.php +++ b/app/Livewire/Admin/Index.php @@ -3,16 +3,19 @@ namespace App\Livewire\Admin; use App\Models\User; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Livewire\Component; class Index extends Component { - public $active_subscribers = []; + public int $activeSubscribers; - public $inactive_subscribers = []; + public int $inactiveSubscribers; - public $search = ''; + public Collection $foundUsers; + + public string $search = ''; public function mount() { @@ -29,39 +32,21 @@ class Index extends Component public function submitSearch() { if ($this->search !== '') { - $this->inactive_subscribers = User::whereDoesntHave('teams', function ($query) { - $query->whereRelation('subscription', 'stripe_subscription_id', '!=', null); - })->where(function ($query) { + $this->foundUsers = User::where(function ($query) { $query->where('name', 'like', "%{$this->search}%") ->orWhere('email', 'like', "%{$this->search}%"); - })->get()->filter(function ($user) { - return $user->id !== 0; - }); - $this->active_subscribers = User::whereHas('teams', function ($query) { - $query->whereRelation('subscription', 'stripe_subscription_id', '!=', null); - })->where(function ($query) { - $query->where('name', 'like', "%{$this->search}%") - ->orWhere('email', 'like', "%{$this->search}%"); - })->get()->filter(function ($user) { - return $user->id !== 0; - }); - } else { - $this->getSubscribers(); + })->get(); } } public function getSubscribers() { - $this->inactive_subscribers = User::whereDoesntHave('teams', function ($query) { + $this->inactiveSubscribers = User::whereDoesntHave('teams', function ($query) { $query->whereRelation('subscription', 'stripe_subscription_id', '!=', null); - })->get()->filter(function ($user) { - return $user->id !== 0; - }); - $this->active_subscribers = User::whereHas('teams', function ($query) { + })->count(); + $this->activeSubscribers = User::whereHas('teams', function ($query) { $query->whereRelation('subscription', 'stripe_subscription_id', '!=', null); - })->get()->filter(function ($user) { - return $user->id !== 0; - }); + })->count(); } public function switchUser(int $user_id) diff --git a/app/Livewire/Team/AdminView.php b/app/Livewire/Team/AdminView.php index c9dabcb5c..cfb47d9d8 100644 --- a/app/Livewire/Team/AdminView.php +++ b/app/Livewire/Team/AdminView.php @@ -74,6 +74,9 @@ class AdminView extends Component public function delete($id, $password) { + if (! isInstanceAdmin()) { + return redirect()->route('dashboard'); + } if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) { if (! Hash::check($password, Auth::user()->password)) { $this->addError('password', 'The provided password is incorrect.'); diff --git a/resources/views/livewire/admin/index.blade.php b/resources/views/livewire/admin/index.blade.php index 99abdf0e5..cceb71bb2 100644 --- a/resources/views/livewire/admin/index.blade.php +++ b/resources/views/livewire/admin/index.blade.php @@ -6,26 +6,25 @@ Search -

Active Subscribers

-
- @forelse ($active_subscribers as $user) -
-

{{ $user->name }}

-

{{ $user->email }}

+
Active Subscribers : {{ $activeSubscribers }}
+
Inactive Subscribers : {{ $inactiveSubscribers }}
+ @if ($search) + @if ($foundUsers->count() > 0) +
+ @foreach ($foundUsers as $user) +
+
+
{{ $user->name }}
+
{{ $user->email }}
+
Active: + {{ $user->teams()->whereRelation('subscription', 'stripe_subscription_id', '!=', null)->exists() ? 'Yes' : 'No' }} +
+
+
+ @endforeach
- @empty -

No active subscribers

- @endforelse -
-

Inactive Subscribers

-
- @forelse ($inactive_subscribers as $user) -
-

{{ $user->name }}

-

{{ $user->email }}

-
- @empty -

No inactive subscribers

- @endforelse -
+ @else +
No users found with {{ $search }}
+ @endif + @endif