Skip to content

Commit b5b7042

Browse files
committed
Adds notifications + additional configurations
1 parent c134ca1 commit b5b7042

File tree

7 files changed

+73
-28
lines changed

7 files changed

+73
-28
lines changed

config/filament-comments.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@
2626
*/
2727
'prune_after_days' => 30,
2828

29+
/*
30+
* The rich editor toolbar buttons that are available to users.
31+
*/
32+
'toolbar_buttons' => [
33+
'blockquote',
34+
'bold',
35+
'bulletList',
36+
'codeBlock',
37+
'italic',
38+
'link',
39+
'orderedList',
40+
'redo',
41+
'strike',
42+
'underline',
43+
'undo',
44+
],
45+
2946
/*
3047
* The attribute used to display the user's name.
3148
*/

resources/lang/en/filament-comments.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@
66
'comments.empty' => 'No comments yet.',
77
'comments.placeholder' => 'Add a comment...',
88

9+
'notifications.created' => 'Comment added.',
10+
'notifications.deleted' => 'Comment deleted.',
11+
912
'modal.heading' => 'Comments',
1013
];

resources/views/comments.blade.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<div class="flex flex-col h-full space-y-4">
2-
<div class="space-y-4">
3-
{{ $this->form }}
4-
5-
<x-filament::button
6-
wire:click="create"
7-
color="primary"
8-
>
9-
{{ __('filament-comments::filament-comments.comments.add') }}
10-
</x-filament::button>
11-
</div>
2+
@if (auth()->user()->can('create', \Parallax\FilamentComments\Models\FilamentComment::class))
3+
<div class="space-y-4">
4+
{{ $this->form }}
5+
6+
<x-filament::button
7+
wire:click="create"
8+
color="primary"
9+
>
10+
{{ __('filament-comments::filament-comments.comments.add') }}
11+
</x-filament::button>
12+
</div>
13+
@endif
1214

1315
@if (count($comments))
1416
<x-filament::grid class="gap-4">

src/Actions/CommentsAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ protected function setUp(): void
2929
->modalWidth(MaxWidth::Medium)
3030
->modalSubmitAction(false)
3131
->modalCancelAction(false)
32-
->visible(fn (): bool => auth()->user()->can('create', FilamentComment::class));
32+
->visible(fn (): bool => auth()->user()->can('viewAny', FilamentComment::class));
3333
}
3434
}

src/Infolists/Components/CommentsEntry.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
namespace Parallax\FilamentComments\Infolists\Components;
44

55
use Filament\Infolists\Components\Entry;
6+
use Parallax\FilamentComments\Models\FilamentComment;
67

78
class CommentsEntry extends Entry
89
{
910
protected string $view = 'filament-comments::component';
11+
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
16+
$this->visible(fn (): bool => auth()->user()->can('viewAny', FilamentComment::class));
17+
}
1018
}

src/Livewire/CommentsComponent.php

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Parallax\FilamentComments\Livewire;
44

5-
use App\Models\Comment;
65
use Filament\Forms;
76
use Filament\Forms\Concerns\InteractsWithForms;
87
use Filament\Forms\Contracts\HasForms;
98
use Filament\Forms\Form;
9+
use Filament\Notifications\Notification;
1010
use Illuminate\Contracts\View\View;
1111
use Illuminate\Database\Eloquent\Model;
1212
use Livewire\Component;
@@ -27,32 +27,28 @@ public function mount(): void
2727

2828
public function form(Form $form): Form
2929
{
30+
if (!auth()->user()->can('create', FilamentComment::class)) {
31+
return $form;
32+
}
33+
3034
return $form
3135
->schema([
3236
Forms\Components\RichEditor::make('comment')
3337
->hiddenLabel()
3438
->required()
3539
->placeholder(__('filament-comments::filament-comments.comments.placeholder'))
3640
->extraInputAttributes(['style' => 'min-height: 6rem'])
37-
->toolbarButtons([
38-
'blockquote',
39-
'bold',
40-
'bulletList',
41-
'codeBlock',
42-
'italic',
43-
'link',
44-
'orderedList',
45-
'redo',
46-
'strike',
47-
'underline',
48-
'undo',
49-
])
41+
->toolbarButtons(config('filament-comments.toolbar_buttons'))
5042
])
5143
->statePath('data');
5244
}
5345

5446
public function create(): void
5547
{
48+
if (!auth()->user()->can('create', FilamentComment::class)) {
49+
return;
50+
}
51+
5652
$this->form->validate();
5753

5854
$data = $this->form->getState();
@@ -63,12 +59,32 @@ public function create(): void
6359
'user_id' => auth()->id(),
6460
]);
6561

62+
Notification::make()
63+
->title(__('filament-comments::filament-comments.notifications.created'))
64+
->success()
65+
->send();
66+
6667
$this->form->fill();
6768
}
6869

6970
public function delete(int $id): void
7071
{
71-
FilamentComment::find($id)->delete();
72+
$comment = FilamentComment::find($id);
73+
74+
if (!$comment) {
75+
return;
76+
}
77+
78+
if (!auth()->user()->can('delete', $comment)) {
79+
return;
80+
}
81+
82+
$comment->delete();
83+
84+
Notification::make()
85+
->title(__('filament-comments::filament-comments.notifications.deleted'))
86+
->success()
87+
->send();
7288
}
7389

7490
public function render(): View

src/Tables/Actions/CommentsAction.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ protected function setUp(): void
2222
$this
2323
->icon('heroicon-s-chat-bubble-left-right')
2424
->label(__('filament-comments::filament-comments.comments'))
25-
->color('gray')
2625
->slideOver()
2726
->modalContentFooter(fn (Model $record): View => view('filament-comments::component', [
2827
'record' => $record,
@@ -31,6 +30,6 @@ protected function setUp(): void
3130
->modalWidth(MaxWidth::Medium)
3231
->modalSubmitAction(false)
3332
->modalCancelAction(false)
34-
->visible(fn (): bool => auth()->user()->can('create', FilamentComment::class));
33+
->visible(fn (): bool => auth()->user()->can('viewAny', FilamentComment::class));
3534
}
3635
}

0 commit comments

Comments
 (0)