Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Aug 30, 2024
1 parent 4096a4d commit f6da0a4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 24 deletions.
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Filament Mails can collect everything you might want to track about the mails th

Email as a protocol is very error prone. Succesfull email delivery is not guaranteed in any way, so it is best to monitor your email sending realtime. Using external services like Postmark, Mailgun or Resend email gets better by offering things like logging and delivery feedback, but it still needs your attention and can fail silently but horendously. Therefore we created Laravel Mails that fills in all the gaps.

The package is built on top of [Laravel Mails](https://github.com/vormkracht10/laravel-mails).

![Filament Mails](./docs/list.png)

## Installation

You can install the package via composer:
Expand Down Expand Up @@ -46,19 +50,35 @@ Optionally, you can publish the views using
php artisan vendor:publish --tag="filament-mails-views"
```

This is the contents of the published config file:
Then add the plugin to your `PanelProvider`

```php
return [
];
use Vormkracht10\FilamentMails\FilamentMails;

public function panel(Panel $panel): Panel
{
return $panel
->plugin(FilamentMailsPlugin::make());
}
```

### Features and screenshots

#### List with all sent emails and statistics

![Filament Mails](./docs/list.png)

#### Preview email

![Filament Mails](./docs/view.png)

#### View relevant information

![Filament Mails](./docs/slideover.png)

## Usage

```php
$filamentMails = new Vormkracht10\FilamentMails();
echo $filamentMails->echoPhrase('Hello, Vormkracht10!');
```
..

## Testing

Expand Down
47 changes: 30 additions & 17 deletions src/Resources/MailResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace Vormkracht10\FilamentMails\Resources;

use Filament\Tables;
use Filament\Tables\Table;
use Filament\Infolists\Infolist;
use Filament\Resources\Resource;
use Filament\Infolists\Components\Grid;
use Filament\Infolists\Components\Section;
use Filament\Infolists\Components\Tabs;
use Filament\Infolists\Components\Section;
use Filament\Infolists\Components\Tabs\Tab;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Infolist;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Vormkracht10\FilamentMails\Models\Mail;
use Filament\Infolists\Components\TextEntry;
use Vormkracht10\FilamentMails\Resources\MailResource\Pages\ListMails;

class MailResource extends Resource
Expand Down Expand Up @@ -68,22 +68,22 @@ public static function infolist(Infolist $infolist): Infolist
->label(__('Subject')),
TextEntry::make('from')
->label(__('From'))
->formatStateUsing(fn ($state) => self::formatEmailAddress($state)),
->formatStateUsing(fn($state) => self::formatEmailAddress($state)),
TextEntry::make('to')
->label(__('Recipient'))
->formatStateUsing(fn ($state) => self::formatEmailAddress($state)),
->formatStateUsing(fn($state) => self::formatEmailAddress($state)),
TextEntry::make('cc')
->label(__('CC'))
->default('-')
->formatStateUsing(fn ($state) => self::formatEmailAddress($state)),
->formatStateUsing(fn($state) => self::formatEmailAddress($state)),
TextEntry::make('bcc')
->label(__('BCC'))
->default('-')
->formatStateUsing(fn ($state) => self::formatEmailAddress($state)),
->formatStateUsing(fn($state) => self::formatEmailAddress($state)),
TextEntry::make('reply_to')
->default('-')
->label(__('Reply To'))
->formatStateUsing(fn ($state) => self::formatEmailAddress($state)),
->formatStateUsing(fn($state) => self::formatEmailAddress($state)),
]),
]),
Section::make('Content')
Expand Down Expand Up @@ -167,19 +167,17 @@ public static function infolist(Infolist $infolist): Infolist
public static function table(Table $table): Table
{
return $table
// ->recordAction('view')
// ->recordUrl(null)
->defaultSort('created_at', 'desc')
->columns([
Tables\Columns\TextColumn::make('status')
->label(__('Status'))
->sortable()
->badge()
->color(fn (string $state): string => match ($state) {
->color(fn(string $state): string => match ($state) {
'Hard Bounced' => 'danger',
'Soft Bounced' => 'warning',
'Complained' => 'danger',
'Clicked' => 'success',
'Clicked' => 'clicked',
'Opened' => 'success',
'Delivered' => 'success',
'Sent' => 'info',
Expand All @@ -194,7 +192,7 @@ public static function table(Table $table): Table
->searchable(),
Tables\Columns\TextColumn::make('to')
->label(__('Recipient'))
->formatStateUsing(fn ($state) => self::formatEmailAddress($state))
->formatStateUsing(fn($state) => self::formatEmailAddressForTable($state))
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('sent_at')
Expand All @@ -204,7 +202,7 @@ public static function table(Table $table): Table
->searchable(),
])
->filters([
//
//
])
->actions([
Tables\Actions\ViewAction::make()
Expand Down Expand Up @@ -243,4 +241,19 @@ private static function formatEmailAddress($state): string
return $name === null ? $email : "$name <$email>";
}, array_keys($data), $data));
}

private static function formatEmailAddressForTable($state): string
{
if (empty($state)) {
return '-';
}

$data = json_decode($state, true);

if (!is_array($data)) {
return (string) $state;
}

return implode(', ', array_keys($data));
}
}

0 comments on commit f6da0a4

Please sign in to comment.