feat(user): menambahkan fitur search dan menghapus default value untuk status
This commit is contained in:
parent
b81dbf303d
commit
3f0331de80
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Livewire\Studio\Master\User;
|
||||
|
||||
use App\Enums\UserStatus;
|
||||
use App\Models\Employee;
|
||||
use App\Models\User;
|
||||
use App\Traits\WithConfirmation;
|
||||
@ -18,18 +17,24 @@ class Index extends Component
|
||||
|
||||
public array $employees = [];
|
||||
|
||||
public string $search = '';
|
||||
|
||||
public array $status = [];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadEmployees();
|
||||
|
||||
$this->status = UserStatus::cases();
|
||||
}
|
||||
|
||||
protected function loadEmployees()
|
||||
{
|
||||
$this->employees = Employee::with(['user', 'user.referralCode', 'user.outlets'])
|
||||
->when(! empty($this->search), function ($query) {
|
||||
return $query->where('full_name', 'like', '%'.$this->search.'%')
|
||||
->orWhere('code', 'like', '%'.$this->search.'%')
|
||||
->orWhereHas('user', fn ($q) => $q->where('email', 'like', '%'.$this->search.'%'))
|
||||
->orWhereHas('user', fn ($q) => $q->where('username', 'like', '%'.$this->search.'%'));
|
||||
})
|
||||
->when(! empty($this->status), fn ($query) => $query->whereHas('user', fn ($q) => $q->whereIn('status', $this->status)))
|
||||
->latest()
|
||||
->get()
|
||||
@ -64,14 +69,15 @@ protected function loadEmployees()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function updatedSearch(string $value)
|
||||
{
|
||||
$this->search = $value;
|
||||
|
||||
$this->loadEmployees();
|
||||
}
|
||||
|
||||
public function updatedStatus()
|
||||
{
|
||||
if (empty($this->status)) {
|
||||
$this->employees = [];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->loadEmployees();
|
||||
}
|
||||
|
||||
|
||||
@ -16,16 +16,8 @@ class="text-sm">
|
||||
<div class="mt-6">
|
||||
<div class="mb-6 grid grid-cols-1 lg:grid-cols-2 gap-4">
|
||||
<flux:card class="flex flex-col justify-center">
|
||||
<div class="flex items-center gap-4 flex-wrap">
|
||||
<span class="text-sm font-semibold text-gray-700 dark:text-gray-300">Status:</span>
|
||||
@foreach (\App\Enums\UserStatus::cases() as $status)
|
||||
<div class="flex items-center gap-2">
|
||||
<flux:badge color="{{ $status->color() }}" size="sm">
|
||||
{{ $status->label() }}
|
||||
</flux:badge>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<flux:input icon="magnifying-glass" placeholder="Cari outlet..."
|
||||
wire:model.live.debounce.500ms="search" />
|
||||
</flux:card>
|
||||
|
||||
<flux:card>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user