notification table integrated
This commit is contained in:
parent
bcce93175b
commit
c9ef8179ff
|
@ -23,11 +23,13 @@ class Table extends Component
|
|||
public $sortDirection = 'asc';
|
||||
public bool $hasSearch = true;
|
||||
|
||||
public $rowKey = 'id';
|
||||
|
||||
public $startDate;
|
||||
public $endDate;
|
||||
|
||||
// Pagination Configuration
|
||||
public $perPage = 5;
|
||||
public $perPage = 10;
|
||||
public $page = 1;
|
||||
public $renderKey = 0; // Dummy property to force re-render
|
||||
|
||||
|
@ -36,23 +38,26 @@ class Table extends Component
|
|||
public $modalMode = 'view';
|
||||
public $modalData = [];
|
||||
|
||||
public function mount($columns, $rows, $addRoute = null)
|
||||
{
|
||||
$this->columns = $columns;
|
||||
// Convert $rows to a plain array to ensure consistent pagination
|
||||
$this->rows = collect($rows)->map(function ($row) {
|
||||
return is_array($row) ? $row : (array) $row;
|
||||
})->values()->toArray();
|
||||
$this->addRoute = $addRoute;
|
||||
Log::info("Initial rows count: " . count($this->rows));
|
||||
}
|
||||
public function mount($columns, $rows, $addRoute = null, $rowKey = 'id')
|
||||
{
|
||||
$this->columns = $columns;
|
||||
$this->rows = collect($rows)->map(function ($row) {
|
||||
return is_array($row) ? $row : (array) $row;
|
||||
})->values()->all();
|
||||
$this->addRoute = $addRoute;
|
||||
$this->rowKey = $rowKey;
|
||||
Log::info("Initial rows count: " . count($this->rows));
|
||||
}
|
||||
|
||||
public function viewRow($id)
|
||||
{
|
||||
$this->modalData = collect($this->rows)->firstWhere('id', $id) ?? [];
|
||||
$this->modalMode = 'view';
|
||||
$this->showModal = true;
|
||||
}
|
||||
|
||||
public function viewRow($id)
|
||||
{
|
||||
$this->modalData = collect($this->rows)->firstWhere($this->rowKey, $id) ?? [];
|
||||
$this->modalMode = 'view';
|
||||
$this->showModal = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function editRow($id)
|
||||
{
|
||||
|
|
|
@ -25,12 +25,19 @@ class LoginForm extends Component
|
|||
]);
|
||||
|
||||
$json = $response->json();
|
||||
// dd($json);
|
||||
|
||||
|
||||
if ($response->successful()) {
|
||||
if ($json['code'] === 200) {
|
||||
Session::put('user', $json['data']['user'] ?? null);
|
||||
Session::put('user', [
|
||||
'admin' => $json['data']['admin'] ?? null,
|
||||
'access_token' => $json['data']['token'] ?? null,
|
||||
]);
|
||||
// dd(Session::get('user')); // right before redirect
|
||||
|
||||
|
||||
return redirect('/main/profile');
|
||||
return $this->redirect('/main/profile');
|
||||
} else {
|
||||
$this->addError('username', $json['message'] ?? 'Login failed.');
|
||||
}
|
||||
|
@ -49,59 +56,4 @@ class LoginForm extends Component
|
|||
return view('livewire.auth.login-form'); // This will point to the resource/views/livewire/auth/login-form.blade.php component
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// <?php
|
||||
|
||||
// namespace App\Livewire;
|
||||
|
||||
// use console;
|
||||
// use Livewire\Component;
|
||||
// use Illuminate\Support\Facades\Http;
|
||||
// use Illuminate\Support\Facades\Session;
|
||||
|
||||
// class LoginForm extends Component
|
||||
// {
|
||||
// public $username, $password;
|
||||
|
||||
// public function submit()
|
||||
// {
|
||||
// $this->validate([
|
||||
// 'username' => 'required|string',
|
||||
// 'password' => 'required|string',
|
||||
// ]);
|
||||
|
||||
// try {
|
||||
// $response = Http::post(config('services.backend_api.url') . '/api/cms/login_password', [
|
||||
// 'username' => $this->username,
|
||||
// 'password' => $this->password,
|
||||
// ]);
|
||||
|
||||
// $json = $response->json();
|
||||
|
||||
// if ($response->successful()) {
|
||||
// if ($json['code'] === 200) {
|
||||
// Session::put('admin_uuid', $json['data']['admin_uuid'] ?? null);
|
||||
|
||||
// return redirect('/main/profile');
|
||||
// } else {
|
||||
// $this->addError('username', $json['message'] ?? 'Login failed.');
|
||||
// }
|
||||
// } else {
|
||||
// $message = $json['message'] ?? 'Login request failed. Please try again.';
|
||||
// $this->addError('username', $message);
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// $this->addError('username', 'An error occurred: ' . $e->getMessage());
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// public function render()
|
||||
// {
|
||||
// return view('livewire.auth.login-form'); // This will point to the resource/views/livewire/auth/login-form.blade.php component
|
||||
// }
|
||||
|
||||
// }
|
||||
}
|
|
@ -3,6 +3,9 @@
|
|||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class Notification extends Component
|
||||
{
|
||||
public $notifs = [];
|
||||
|
@ -13,10 +16,40 @@ class Notification extends Component
|
|||
$this->loadNotifications();
|
||||
}
|
||||
|
||||
// Get filtered users based on the search input
|
||||
// Get filtered notifications based on the search input
|
||||
public function loadNotifications()
|
||||
{
|
||||
$this->notifs = collect(json_decode(file_get_contents(storage_path('app/notifs.json')), true));
|
||||
try {
|
||||
$token = Session::get('user')['access_token'] ?? null;
|
||||
|
||||
if (!$token) {
|
||||
$this->addError('users', 'No access token found.');
|
||||
return;
|
||||
}
|
||||
|
||||
$response = Http::withToken($token)
|
||||
->get(config('services.backend_api.url') . '/api/cms/notification');
|
||||
|
||||
// dd($response->json());
|
||||
|
||||
if ($response->successful()) {
|
||||
// Properly use collect to handle the response data
|
||||
$this->notifs = collect($response->json()['data']['notifications'])->map(function ($notifs) {
|
||||
return [
|
||||
'id' => $notifs['id'],
|
||||
'subject' => $notifs['subject'],
|
||||
'content' => $notifs['description'],
|
||||
'is_scheduled' => $notifs['trigger_schedule'],
|
||||
'schedule' => $notifs['schedule']?? '-',
|
||||
'expiration' => $notifs['expiration_date'],
|
||||
];
|
||||
});
|
||||
} else {
|
||||
$this->addError('users', 'Failed to load notifications.');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('users', 'Error: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,14 +13,15 @@ class Profile extends Component
|
|||
public function mount()
|
||||
{
|
||||
$this->user = Session::get('user');
|
||||
|
||||
if (!$this->user) {
|
||||
return $this->redirect('/login'); // Livewire 3 way
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
if (!$this->user) {
|
||||
return $this->redirect('/login');
|
||||
}
|
||||
|
||||
return view('livewire.profile.profile');
|
||||
}
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
<?php
|
||||
|
||||
// UserManagement.php
|
||||
namespace App\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
|
||||
class UserManagement extends Component
|
||||
{
|
||||
|
@ -11,12 +12,42 @@ class UserManagement extends Component
|
|||
|
||||
public function mount()
|
||||
{
|
||||
$this->loadUsers(); // Load users initially
|
||||
$this->loadUsers();
|
||||
}
|
||||
|
||||
public function loadUsers()
|
||||
{
|
||||
$this->users = collect(json_decode(file_get_contents(storage_path('app/users.json')), true));
|
||||
try {
|
||||
$token = Session::get('user')['access_token'] ?? null;
|
||||
|
||||
if (!$token) {
|
||||
$this->addError('users', 'No access token found.');
|
||||
return;
|
||||
}
|
||||
|
||||
$response = Http::withToken($token)
|
||||
->get(config('services.backend_api.url') . '/api/cms/admin');
|
||||
|
||||
// dd($response->json());
|
||||
if ($response->successful()) {
|
||||
// Properly use collect to handle the response data
|
||||
$this->users = collect($response->json()['data'])->map(function ($user) {
|
||||
return [
|
||||
'admin_uuid' => $user['admin_uuid'],
|
||||
'username' => $user['username'],
|
||||
'firstname' => $user['firstname'],
|
||||
'lastname' => $user['lastname'],
|
||||
'email' => $user['email'],
|
||||
'role' => $user['role'],
|
||||
'status' => $user['status'],
|
||||
];
|
||||
});
|
||||
} else {
|
||||
$this->addError('users', 'Failed to load users.');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('users', 'Error: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
@ -26,3 +57,4 @@ class UserManagement extends Component
|
|||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ return [
|
|||
|
|
||||
*/
|
||||
|
||||
'driver' => env('SESSION_DRIVER', 'database'),
|
||||
'driver' => env('SESSION_DRIVER', 'file'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -82,16 +82,15 @@
|
|||
|
||||
<!-- Table Body -->
|
||||
<tbody>
|
||||
@php
|
||||
\Illuminate\Support\Facades\Log::info("Blade rows count: " . count($rows) . ", First Username: " . ($rows[0]['username'] ?? 'N/A'));
|
||||
@endphp
|
||||
@forelse ($rows as $index => $row)
|
||||
<tr class="hover:bg-gray-50 border-b" wire:key="row-{{ $row['id'] }}-{{ $index }}-{{ $renderKey }}">
|
||||
<tr class="hover:bg-gray-50 border-b" wire:key="row-{{ $row[$rowKey] }}-{{ $index }}-{{ $renderKey }}">
|
||||
<!-- Checkbox for row selection (if enabled) -->
|
||||
@if ($hasCheckbox)
|
||||
<td class="px-4 py-2">
|
||||
<input type="checkbox" wire:click="selectRow('{{ $row['id'] }}')"
|
||||
@if(in_array($row['id'], $selected)) checked @endif class="cursor-pointer">
|
||||
<input type="checkbox"
|
||||
wire:click="selectRow('{{ $row[$rowKey] ?? $index }}')"
|
||||
@if(in_array($row[$rowKey] ?? $index, $selected)) checked @endif
|
||||
class="cursor-pointer">
|
||||
</td>
|
||||
@endif
|
||||
|
||||
|
@ -106,17 +105,17 @@
|
|||
@if ($hasActions)
|
||||
<td class="px-4 py-2 gap-2 flex">
|
||||
@if($isViewPage)
|
||||
<button wire:click="viewRow({{ $row['id'] }})" class="text-gray-500 hover:text-gray-700">
|
||||
<button wire:click="viewRow('{{ $row[$rowKey] ?? $index }}')" class="text-gray-500 hover:text-gray-700">
|
||||
<i class="fas fa-eye"></i>
|
||||
</button>
|
||||
@else
|
||||
<button wire:click="editRow({{ $row['id'] }})" class="text-blue-500 hover:text-blue-700">
|
||||
<button wire:click="editRow('{{ $row[$rowKey] ?? $index }}')" class="text-blue-500 hover:text-blue-700">
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
<button wire:click="viewRow({{ $row['id'] }})" class="text-gray-500 hover:text-gray-700">
|
||||
<button wire:click="viewRow('{{ $row[$rowKey] ?? $index }}')" class="text-gray-500 hover:text-gray-700">
|
||||
<i class="fas fa-eye"></i>
|
||||
</button>
|
||||
<button wire:click="deleteRow({{ $row['id'] }})" class="text-red-500 hover:text-red-700">
|
||||
<button wire:click="deleteRow('{{ $row[$rowKey] ?? $index }}')" class="text-red-500 hover:text-red-700">
|
||||
<i class="fas fa-trash-alt"></i>
|
||||
</button>
|
||||
@endif
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
@case('profile')
|
||||
<livewire:profile />
|
||||
@break
|
||||
|
||||
@break
|
||||
|
||||
@case('user-management')
|
||||
<livewire:user-management />
|
||||
@break
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
<div>
|
||||
{{-- Top Nav --}}
|
||||
@include('livewire.notification.top-nav.notification')
|
||||
|
||||
|
||||
<livewire:components.table
|
||||
:columns="[
|
||||
['label' => 'Subject', 'field' => 'subject'],
|
||||
['label' => 'Content', 'field' => 'content'],
|
||||
['label' => 'Is Scheduled', 'field' => 'is_scheduled'],
|
||||
['label' => 'Schedule', 'field' => 'schedule'],
|
||||
['label' => 'Expiration', 'field' => 'expiration'],
|
||||
]"
|
||||
['label' => 'ID', 'field' => 'id'],
|
||||
['label' => 'Subject', 'field' => 'subject'],
|
||||
['label' => 'Content', 'field' => 'content'],
|
||||
['label' => 'Is Scheduled', 'field' => 'is_scheduled'],
|
||||
['label' => 'Schedule', 'field' => 'schedule'],
|
||||
['label' => 'Expiration', 'field' => 'expiration_date'],
|
||||
]"
|
||||
:rows="$notifs"
|
||||
:hasActions="false"
|
||||
:addRoute="route('notification-create')"
|
||||
|
|
|
@ -6,18 +6,18 @@
|
|||
<div class="flex items-center space-x-4 px-5 py-4 bg-gray-300">
|
||||
<x-heroicon-s-user-circle class="w-20 h-20 mr-2 text-gray-500"/>
|
||||
<h3 class="text-2xl font-semibold text-gray-800">
|
||||
{{ $user['firstname'] }} {{ $user['lastname'] }}
|
||||
{{ $user['admin']['name'] }}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<div class="text-md px-10 p-10 bg-white">
|
||||
<div>
|
||||
<h4 class="font-bold mb-5">My Information</h4>
|
||||
<p><span class="font-semibold">Username:</span> {{ $user['username'] ?? '-' }}</p>
|
||||
<p><span class="font-semibold">Username:</span> {{ $user['admin']['username'] ?? '-' }}</p>
|
||||
<p>
|
||||
<span class="font-semibold">Email:</span>
|
||||
<a href="mailto:{{ $user['email'] }}" class="text-blue-600 hover:underline">
|
||||
{{ $user['email'] }}
|
||||
<a href="mailto:{{ $user['admin']['email'] }}" class="text-blue-600 hover:underline">
|
||||
{{ $user['admin']['email'] }}
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
|
@ -26,7 +26,7 @@
|
|||
<h4 class="font-bold mt-10 mb-5">Access Role</h4>
|
||||
<p>
|
||||
<span class="font-semibold">Role:</span>
|
||||
{{ $user['role'] === 1 ? 'System Admin' : 'User' }}
|
||||
{{ $user['admin']['role'] === 1 ? 'System Admin' : 'User' }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
<livewire:components.table
|
||||
:columns="[
|
||||
['label' => 'Username', 'field' => 'username'],
|
||||
['label' => 'First Name', 'field' => 'first_name'],
|
||||
['label' => 'Last Name', 'field' => 'last_name'],
|
||||
['label' => 'First Name', 'field' => 'firstname'],
|
||||
['label' => 'Last Name', 'field' => 'lastname'],
|
||||
['label' => 'Email', 'field' => 'email'],
|
||||
['label' => 'Role', 'field' => 'role'],
|
||||
['label' => 'Status', 'field' => 'status'],
|
||||
|
@ -16,5 +16,6 @@
|
|||
:hasCheckbox="true"
|
||||
:hasActions="true"
|
||||
:isViewPage="false"
|
||||
:rowKey="'admin_uuid'"
|
||||
/>
|
||||
</div>
|
||||
|
|
|
@ -24,13 +24,13 @@ use Illuminate\Support\Facades\Route;
|
|||
|
||||
|
||||
//laravel page
|
||||
Route::get('/', function () {
|
||||
return redirect()->route('login');
|
||||
});
|
||||
Route::get('/login', function () {
|
||||
return view('auth.log-in');
|
||||
})->name('login');
|
||||
|
||||
// Route::get('/', function () {
|
||||
// return redirect()->route('login');
|
||||
// });
|
||||
// Route::get('/login', function () {
|
||||
// return view('auth.log-in');
|
||||
// })->name('login');
|
||||
Route::get('/login', LoginForm::class)->name('login');
|
||||
|
||||
// // Route::get('/login', LoginForm::class)->name('layouts.app');
|
||||
|
||||
|
|
Loading…
Reference in New Issue