apiService = $apiService; } public function mount() { // Check role-based access $userInfo = Session::get('userInfo'); if (!$userInfo || $userInfo['role'] != 1) { return redirect()->route('404'); } $this->loadUsers(); } public function loadUsers() { $this->loading = true; try { $response = $this->apiService->get('admin?page=1&page_size=10&_sort_by=create_dt&_sort_order=desc'); if ($response && isset($response['data'])) { $this->users = $response['data']; Log::info('User list loaded', ['source' => 'UserManagementUserList']); } } catch (\Exception $e) { Session::flash('error', 'Failed to load users: ' . $e->getMessage()); Log::error('Failed to load user list', ['error' => $e->getMessage(), 'source' => 'UserManagementUserList']); } finally { $this->loading = false; } } public function updateStatus($admin_uuid, $status) { $this->updating = true; try { $response = $this->apiService->post('adminChangeStatus', [ 'admin_uuid' => $admin_uuid, 'status' => $status, ]); if ($response && isset($response['status']) && $response['status'] === 200) { Session::flash('success', $response['message'] ?? 'Status updated successfully.'); Log::info('User status updated', ['source' => 'UserManagementUserList']); $this->loadUsers(); // Refresh the list } } catch (\Exception $e) { Session::flash('error', 'Something went wrong updating record: ' . $e->getMessage()); Log::error('Failed to update user status', ['error' => $e->getMessage(), 'source' => 'UserManagementUserList']); } finally { $this->updating = false; } } public function render() { return view('livewire.user-management.user-list')->layout('layouts.app', ['title' => 'User Management']); } }