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

RJS/Fix examples for Notifications Pro #323

Merged
merged 4 commits into from
Jan 25, 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 content/plugins/ralphjsmit-activitylog-pro.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,28 @@ Timeline::make()
]),
```

If you are mixing timeline items for multiple Eloquent models and you need access to the current underlying Spatie Activitylog model, you can use the `$arguments['activity_id']` parameter:

```php
Timeline::make()
->itemActions('published', [
Forms\Components\Actions\Action::make('edit')
->fillForm(function (array $arguments) {
$activity = Activity::find($arguments['activity_id']);

// ...
})
->form([
Forms\Components\TextInput::make('title')
])
->action(function (array $arguments, array $data) {
$activity = Activity::find($arguments['activity_id']);

// ...
})
]),
```

##### Define icons, colors & actions globally

If you want to **globally provide icons, colors and actions**, you can make use of the Filament `configureUsing()` method. When working globally with timelines, it is generally very handy to scope the configuration to specific models:
Expand Down
19 changes: 13 additions & 6 deletions content/plugins/ralphjsmit-notifications-pro.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,17 @@ However, if the `StoresNotificationInDatabase` doesn't work for you, you can alw
```php
class TestNotification extends Notification implements AsFilamentNotification
{
use StoresNotificationInDatabase;

public function __construct(
public User $user,
public string $message,
public string $customMessage,
) {}

public static function toFilamentNotification(): FilamentNotification
{
return FilamentNotification::make()
->message(fn (self $notification) => $notification->customMessage)
->form([
\Filament\Forms\Components\TextInput::make('message')
->label('Message')
Expand All @@ -394,11 +397,11 @@ class TestNotification extends Notification implements AsFilamentNotification
->label('User'),
])
->constructUsing(function(array $data) {
['message' => $message, 'user_id_or_something' => $userId] = $data;
['custom_message' => $message, 'user_id_or_something' => $userId] = $data;

return new static(
user: User::find($userId),
message: $message
customMessage: $message
);
});
}
Expand All @@ -407,14 +410,18 @@ class TestNotification extends Notification implements AsFilamentNotification
{
return [
'user_id_or_something' => $this->user->id,
'message' => $this->message,
'custom_message' => $this->message,
// Some internal properties are required to store in the database. They will be provided by this method.
...$this->getInternalToArray(),
];
}

public function via($notifiable): array
{
return ['database', 'mail'];
}

// Implement a `toMail()` method to match the methods in `via()`...
}
```

Expand Down Expand Up @@ -482,7 +489,7 @@ return FilamentNotification::make()
->actions([
Action::make('View')
->url("https://github.com", true)
->icon('heroicon-o-arrows-expand'),
->icon('heroicon-o-arrows-pointing-out'),
]);
```

Expand Down Expand Up @@ -548,7 +555,7 @@ class TestWorkflowFailedNotification extends Notification implements AsFilamentN
->actions([
Action::make('View')
->url("https://github.com", true)
->icon('heroicon-o-arrows-expand'),
->icon('heroicon-o-arrows-pointing-out'),
]);
}

Expand Down