diff --git a/app/Http/Controllers/UserManagementController.php b/app/Http/Controllers/UserManagementController.php new file mode 100644 index 0000000..b6e8a7d --- /dev/null +++ b/app/Http/Controllers/UserManagementController.php @@ -0,0 +1,70 @@ +route('login')->with('error', 'Please log in to view user management.'); + } + + // Make the API call to fetch admin users + $response = Http::withHeaders([ + 'Accept' => 'application/json', + 'Authorization' => 'Bearer ' . $accessToken, + ])->get("{$this->apiBaseUrl}/cms/admin"); + + $json = $response->json(); + + Log::info('User Management API Response: ', $json); + + if ($response->successful() && isset($json['data']) && is_array($json['data'])) { + // Transform the API response into the format expected by the table component + $users = array_map(function ($admin) { + return [ + + 'username' => $admin['username'], + 'firstName' => $admin['firstname'], + 'lastName' => $admin['lastname'], + 'role' => 'Admin', // Adjust if the API provides role data + 'email' => $admin['email'], + // 'status' => $admin['is_active'] ? 'Active' : 'Inactive', + ]; + }, $json['data']); + + // Pass the transformed data to the view + return view('pages.user-management', [ + 'users' => $users, + ]); + } else { + Log::warning('No user data found or invalid API response: ', $json); + return view('pages.user-management', [ + 'users' => [], // Pass an empty array if no data + ]); + } + } catch (\Exception $e) { + Log::error('Error fetching user data: ' . $e->getMessage()); + return view('pages.user-management', [ + 'users' => [], // Pass an empty array on error + ]); + } + } +} \ No newline at end of file diff --git a/resources/views/pages/user-management.blade.php b/resources/views/pages/user-management.blade.php index d011e47..57a7608 100644 --- a/resources/views/pages/user-management.blade.php +++ b/resources/views/pages/user-management.blade.php @@ -1,3 +1,4 @@ + @extends('layouts.app') @section('page_title', 'User Management') @@ -6,7 +7,7 @@