fix: cloud admin view
This commit is contained in:
@@ -3,16 +3,19 @@
|
|||||||
namespace App\Livewire\Admin;
|
namespace App\Livewire\Admin;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class Index extends 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()
|
public function mount()
|
||||||
{
|
{
|
||||||
@@ -29,39 +32,21 @@ class Index extends Component
|
|||||||
public function submitSearch()
|
public function submitSearch()
|
||||||
{
|
{
|
||||||
if ($this->search !== '') {
|
if ($this->search !== '') {
|
||||||
$this->inactive_subscribers = User::whereDoesntHave('teams', function ($query) {
|
$this->foundUsers = User::where(function ($query) {
|
||||||
$query->whereRelation('subscription', 'stripe_subscription_id', '!=', null);
|
|
||||||
})->where(function ($query) {
|
|
||||||
$query->where('name', 'like', "%{$this->search}%")
|
$query->where('name', 'like', "%{$this->search}%")
|
||||||
->orWhere('email', 'like', "%{$this->search}%");
|
->orWhere('email', 'like', "%{$this->search}%");
|
||||||
})->get()->filter(function ($user) {
|
})->get();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSubscribers()
|
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);
|
$query->whereRelation('subscription', 'stripe_subscription_id', '!=', null);
|
||||||
})->get()->filter(function ($user) {
|
})->count();
|
||||||
return $user->id !== 0;
|
$this->activeSubscribers = User::whereHas('teams', function ($query) {
|
||||||
});
|
|
||||||
$this->active_subscribers = User::whereHas('teams', function ($query) {
|
|
||||||
$query->whereRelation('subscription', 'stripe_subscription_id', '!=', null);
|
$query->whereRelation('subscription', 'stripe_subscription_id', '!=', null);
|
||||||
})->get()->filter(function ($user) {
|
})->count();
|
||||||
return $user->id !== 0;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function switchUser(int $user_id)
|
public function switchUser(int $user_id)
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ class AdminView extends Component
|
|||||||
|
|
||||||
public function delete($id, $password)
|
public function delete($id, $password)
|
||||||
{
|
{
|
||||||
|
if (! isInstanceAdmin()) {
|
||||||
|
return redirect()->route('dashboard');
|
||||||
|
}
|
||||||
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
|
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
|
||||||
if (! Hash::check($password, Auth::user()->password)) {
|
if (! Hash::check($password, Auth::user()->password)) {
|
||||||
$this->addError('password', 'The provided password is incorrect.');
|
$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.input wire:model="search" placeholder="Search for a user" />
|
||||||
<x-forms.button type="submit">Search</x-forms.button>
|
<x-forms.button type="submit">Search</x-forms.button>
|
||||||
</form>
|
</form>
|
||||||
<h3 class="pt-4">Active Subscribers</h3>
|
<div class="pt-4">Active Subscribers : {{ $activeSubscribers }}</div>
|
||||||
<div class="flex flex-wrap gap-2">
|
<div>Inactive Subscribers : {{ $inactiveSubscribers }}</div>
|
||||||
@forelse ($active_subscribers as $user)
|
@if ($search)
|
||||||
<div class="flex gap-2 box" wire:click="switchUser('{{ $user->id }}')">
|
@if ($foundUsers->count() > 0)
|
||||||
<p>{{ $user->name }}</p>
|
<div class="flex flex-wrap gap-2 pt-4">
|
||||||
<p>{{ $user->email }}</p>
|
@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>
|
||||||
@empty
|
|
||||||
<p>No active subscribers</p>
|
|
||||||
@endforelse
|
|
||||||
</div>
|
</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>
|
</div>
|
||||||
@empty
|
@endforeach
|
||||||
<p>No inactive subscribers</p>
|
|
||||||
@endforelse
|
|
||||||
</div>
|
</div>
|
||||||
|
@else
|
||||||
|
<div>No users found with {{ $search }}</div>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user