Skip to content

Commit

Permalink
Preview with code preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Sep 6, 2024
1 parent 9d6a4ce commit 7db6c9d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
7 changes: 7 additions & 0 deletions resources/views/mails/html.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="prose prose-sm sm:prose lg:prose-lg xl:prose-2xl">
<pre>
<code lang="html">
{{ $html }}
</code>
</pre>
</div>
40 changes: 22 additions & 18 deletions src/Resources/MailResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,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)),
]),
]),
Tab::make(__('Statistics'))
Expand Down Expand Up @@ -149,8 +149,8 @@ public static function infolist(Infolist $infolist): Infolist
TextEntry::make('type')
->label(__('Type'))
->badge()
->url(fn (MailEvent $record) => route('filament.' . filament()->getCurrentPanel()?->getId() . '.resources.mails.events.view', $record))
->color(fn (WebhookEventType $state): string => match ($state) {
->url(fn(MailEvent $record) => route('filament.' . filament()->getCurrentPanel()?->getId() . '.resources.mails.events.view', $record))
->color(fn(WebhookEventType $state): string => match ($state) {
WebhookEventType::DELIVERY => 'success',
WebhookEventType::CLICK => 'clicked',
WebhookEventType::OPEN => 'success',
Expand All @@ -162,7 +162,7 @@ public static function infolist(Infolist $infolist): Infolist
return ucfirst($state->value);
}),
TextEntry::make('occurred_at')
->url(fn (MailEvent $record) => route('filament.' . filament()->getCurrentPanel()?->getId() . '.resources.mails.events.view', $record))
->url(fn(MailEvent $record) => route('filament.' . filament()->getCurrentPanel()?->getId() . '.resources.mails.events.view', $record))
->since()
->dateTimeTooltip('d-m-Y H:i')
->label(__('Occurred At')),
Expand All @@ -187,7 +187,7 @@ public static function infolist(Infolist $infolist): Infolist
TextEntry::make('html')
->hiddenLabel()
->label(__('HTML Content'))
->formatStateUsing(fn (string $state, Mail $record): View => view(
->formatStateUsing(fn(string $state, Mail $record): View => view(
'filament-mails::mails.preview',
['html' => $state, 'mail' => $record],
)),
Expand All @@ -196,6 +196,10 @@ public static function infolist(Infolist $infolist): Infolist
->schema([
TextEntry::make('html')
->hiddenLabel()
->formatStateUsing(fn(string $state, Mail $record): View => view(
'filament-mails::mails.html',
['html' => $state, 'mail' => $record],
))
->copyable()
->copyMessage('Copied!')
->copyMessageDuration(1500)
Expand Down Expand Up @@ -233,7 +237,7 @@ public static function infolist(Infolist $infolist): Infolist
->label(__('Mime Type')),
ViewEntry::make('uuid')
->label(__('Download'))
->getStateUsing(fn ($record) => $record)
->getStateUsing(fn($record) => $record)
->view('filament-mails::mails.download'),
]),
]),
Expand All @@ -252,7 +256,7 @@ public static function table(Table $table): Table
->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',
Expand All @@ -271,26 +275,26 @@ public static function table(Table $table): Table
Tables\Columns\IconColumn::make('attachments')
->label('')
->alignLeft()
->getStateUsing(fn (Mail $record) => $record->attachments->count() > 0)
->icon(fn (string $state): string => $state ? 'heroicon-o-paper-clip' : ''),
->getStateUsing(fn(Mail $record) => $record->attachments->count() > 0)
->icon(fn(string $state): string => $state ? 'heroicon-o-paper-clip' : ''),
Tables\Columns\TextColumn::make('to')
->label(__('Recipient'))
->formatStateUsing(fn ($state) => self::formatEmailAddressForTable($state))
->formatStateUsing(fn($state) => self::formatEmailAddressForTable($state))
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('opens')
->label(__('Opens'))
->tooltip(fn (Mail $record) => __('Last opened at :date', ['date' => $record->last_opened_at?->format('d-m-Y H:i')]))
->tooltip(fn(Mail $record) => __('Last opened at :date', ['date' => $record->last_opened_at?->format('d-m-Y H:i')]))
->sortable(),
Tables\Columns\TextColumn::make('clicks')
->label(__('Clicks'))
->tooltip(fn (Mail $record) => __('Last clicked at :date', ['date' => $record->last_clicked_at?->format('d-m-Y H:i')]))
->tooltip(fn(Mail $record) => __('Last clicked at :date', ['date' => $record->last_clicked_at?->format('d-m-Y H:i')]))
->sortable(),
Tables\Columns\TextColumn::make('sent_at')
->label(__('Sent At'))
->dateTime('d-m-Y H:i')
->since()
->tooltip(fn (Mail $record) => $record->sent_at?->format('d-m-Y H:i'))
->tooltip(fn(Mail $record) => $record->sent_at?->format('d-m-Y H:i'))
->sortable()
->searchable(),
])
Expand Down Expand Up @@ -408,4 +412,4 @@ private static function formatEmailAddressForTable($state): string

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

0 comments on commit 7db6c9d

Please sign in to comment.