Skip to content

Commit 44968d4

Browse files
feat:[lar-139] move notificationPage to notifications
1 parent 6406fce commit 44968d4

File tree

4 files changed

+255
-272
lines changed

4 files changed

+255
-272
lines changed

app/Livewire/NotificationPage.php

Lines changed: 0 additions & 62 deletions
This file was deleted.

app/Livewire/Pages/Notifications.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,59 @@
44

55
namespace App\Livewire\Pages;
66

7+
use App\Policies\NotificationPolicy;
8+
use Carbon\Carbon;
9+
use Filament\Notifications\Notification;
710
use Illuminate\Contracts\View\View;
11+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
12+
use Illuminate\Notifications\DatabaseNotification;
13+
use Illuminate\Support\Facades\Auth;
814
use Livewire\Component;
915

1016
final class Notifications extends Component
1117
{
18+
use AuthorizesRequests;
19+
20+
public string $notificationId;
21+
22+
public function mount(): void
23+
{
24+
abort_if(Auth::guest(), 403);
25+
}
26+
27+
public function getNotificationProperty(): DatabaseNotification
28+
{
29+
return DatabaseNotification::findOrFail($this->notificationId);
30+
}
31+
32+
public function markAsRead(string $notificationId): void
33+
{
34+
$this->notificationId = $notificationId;
35+
36+
$this->authorize(NotificationPolicy::MARK_AS_READ, $this->notification); // @phpstan-ignore-line
37+
38+
$this->notification->markAsRead(); // @phpstan-ignore-line
39+
40+
Notification::make()
41+
->title(__('Cette notification a été marquée comme lue.'))
42+
->success()
43+
->seconds(5)
44+
->send();
45+
46+
$this->dispatch('NotificationMarkedAsRead', Auth::user()->unreadNotifications()->count()); // @phpstan-ignore-line
47+
}
48+
1249
public function render(): View
1350
{
14-
return view('livewire.pages.notifications');
51+
return view('livewire.pages.notifications', [
52+
// @phpstan-ignore-next-line
53+
'notifications' => Auth::user()
54+
->unreadNotifications()
55+
->take(10)
56+
->get()
57+
->groupBy(
58+
fn ($notification) => Carbon::parse($notification->created_at)->format('M, Y')
59+
),
60+
]);
1561
}
1662
}

resources/views/livewire/notification-page.blade.php

Lines changed: 0 additions & 208 deletions
This file was deleted.

0 commit comments

Comments
 (0)