Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug if users did'nt extend HasRoles trait #12

Merged
merged 10 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@

All notable changes to `filament-dashboard-notification` will be documented in this file.

## 3.1.5 - 2024-02-19

### What's Changed

* Filament Plugin review by @saade in https://github.com/rupadana/filament-announce/pull/10
* User ID mismatch issue by @Rizayev in https://github.com/rupadana/filament-announce/pull/11

### New Contributors

* @saade made their first contribution in https://github.com/rupadana/filament-announce/pull/10
* @Rizayev made their first contribution in https://github.com/rupadana/filament-announce/pull/11

**Full Changelog**: https://github.com/rupadana/filament-announce/compare/3.1.4...3.1.5

## 3.1.4 - 2024-01-29

### What's Changed

* required if color is custom by @rupadana in https://github.com/rupadana/filament-announce/pull/9

**Full Changelog**: https://github.com/rupadana/filament-announce/compare/3.1.3...3.1.4

## 3.1.3 - 2024-01-28

### What's Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@



The easiest way to shout announcements in filament!
The easiest way to shout announcements in Filament!

![](https://res.cloudinary.com/rupadana/image/upload/v1706100163/Screenshot_2024-01-24_at_20.14.43_focxhf.png)

Expand Down
68 changes: 40 additions & 28 deletions src/Resources/AnnouncementResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use App\Models\User;
use Filament\Forms\Components\ColorPicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
Expand All @@ -29,34 +31,40 @@ public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->minLength(5)
->required(),
TextInput::make('title')
->minLength(5)
->required(),
Textarea::make('body')
->minLength(20)
->required(),
IconPicker::make('icon'),
Select::make('color')
->options([
...collect(FilamentColor::getColors())->map(fn ($value, $key) => ucfirst($key))->toArray(),
'custom' => 'Custom',
])
->live(),
ColorPicker::make('custom_color')
->hidden(fn (Get $get) => $get('color') != 'custom')
->requiredIf('color', 'custom')
->rgb(),
Section::make()
->schema([
TextInput::make('name')
->minLength(5)
->required(),
TextInput::make('title')
->minLength(5)
->required(),
Textarea::make('body')
->minLength(20)
->required(),
IconPicker::make('icon'),
Select::make('color')
->options([
...collect(FilamentColor::getColors())->map(fn ($value, $key) => ucfirst($key))->toArray(),
'custom' => 'Custom',
])
->live(),
ColorPicker::make('custom_color')
->hidden(fn (Get $get) => $get('color') != 'custom')
->requiredIf('color', 'custom')
->rgb(),

Select::make('users')
->options([
'all' => 'all',
...User::all()->pluck('name', 'id'),
])
->multiple()
->required(),
Select::make('users')
->options(User::pluck('name', 'id')->toArray())
->hidden(fn (Get $get) => $get('all') == true)
->multiple()
->required(),
])->columns(2),

Toggle::make('all')
->live()
->label('All users')
->default(false),
]);
}

Expand Down Expand Up @@ -95,6 +103,10 @@ public static function getNavigationGroup(): ?string

public static function canAccess(): bool
{
return auth()->user()->hasRole(config('filament-announce.can_access.role') ?? []);
if (method_exists(auth()->user(), 'hasRole')) {
return auth()->user()->hasRole(config('filament-announce.can_access.role') ?? []);
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ public function afterCreate()
$icon = $record->icon;
$title = $record->title;
$body = $record->body;
$isForAll = $record->all;

$isNotifyToAll = in_array('all', $record->users);

$users = $isNotifyToAll ? User::all() : User::query()->whereIn('id', $record->users)->get();
$users = $isForAll ? User::all() : User::query()->whereIn('id', $record->users)->get();

$announce = Announce::make();

Expand Down