fix: cloud admin view
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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.');
|
||||
|
||||
@@ -6,26 +6,25 @@
|
||||
<x-forms.input wire:model="search" placeholder="Search for a user" />
|
||||
<x-forms.button type="submit">Search</x-forms.button>
|
||||
</form>
|
||||
<h3 class="pt-4">Active Subscribers</h3>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
@forelse ($active_subscribers as $user)
|
||||
<div class="flex gap-2 box" wire:click="switchUser('{{ $user->id }}')">
|
||||
<p>{{ $user->name }}</p>
|
||||
<p>{{ $user->email }}</p>
|
||||
<div class="pt-4">Active Subscribers : {{ $activeSubscribers }}</div>
|
||||
<div>Inactive Subscribers : {{ $inactiveSubscribers }}</div>
|
||||
@if ($search)
|
||||
@if ($foundUsers->count() > 0)
|
||||
<div class="flex flex-wrap gap-2 pt-4">
|
||||
@foreach ($foundUsers as $user)
|
||||
<div class="box w-64 group">
|
||||
<div class="flex flex-col gap-2">
|
||||
<div class="box-title">{{ $user->name }}</div>
|
||||
<div class="box-description">{{ $user->email }}</div>
|
||||
<div class="box-description">Active:
|
||||
{{ $user->teams()->whereRelation('subscription', 'stripe_subscription_id', '!=', null)->exists() ? 'Yes' : 'No' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@empty
|
||||
<p>No active subscribers</p>
|
||||
@endforelse
|
||||
</div>
|
||||
<h3 class="pt-4">Inactive Subscribers</h3>
|
||||
<div class="flex flex-col flex-wrap gap-2">
|
||||
@forelse ($inactive_subscribers as $user)
|
||||
<div class="flex gap-2 box" wire:click="switchUser('{{ $user->id }}')">
|
||||
<p>{{ $user->name }}</p>
|
||||
<p>{{ $user->email }}</p>
|
||||
</div>
|
||||
@empty
|
||||
<p>No inactive subscribers</p>
|
||||
@endforelse
|
||||
</div>
|
||||
@else
|
||||
<div>No users found with {{ $search }}</div>
|
||||
@endif
|
||||
@endif
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user