[fix] Mail Preview fixed.

This commit is contained in:
guillaume91 2024-06-14 12:37:46 +02:00
parent fdf04875e1
commit d308425616
2 changed files with 31 additions and 8 deletions

View file

@ -36,6 +36,7 @@ public function mount(Project $project)
public function showMailingDetailsModal(ProjectMailing $mailing)
{
$this->formData = $mailing->toArray();
$this->formData['attachments'] = $mailing->attachments->toArray();
@ -81,8 +82,23 @@ public function render()
]);
}
public function getMailPreview($mail)
public function getMailPreview($formData):? string
{
return new ReportMailer($mail);
if(array_key_exists('id',$formData)){
try {
return (new ReportMailer(ProjectMailing::find($formData['id'])))->render();
} catch (\ReflectionException $e) {
logger('No Idea what "ReflectionException" means... but got triggered.');
}
}
return null;
}
public function getPreviewRoute($formData):?string
{
if(array_key_exists('id',$formData)){
return route('mail',[$formData['id']]);
}
return null;
}
}

View file

@ -47,7 +47,7 @@ class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">@lang('Attachm
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ $mail->recipients()->count() }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ $mail->attachments()->pluck('name')->join( ', ') }}</td>
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-0">
<button type="button" wire:click="showMailingDetailsModal({{ $mail->id }})"
<button type="button" wire:click="showMailingDetailsModal({{ $mail->id }})" x-on:click="$dispatch('preview',{mail: {{$mail}}})"
class="text-indigo-600 hover:text-indigo-900">Show
</button>
</td>
@ -88,10 +88,17 @@ class="text-indigo-600 hover:text-indigo-900">Show
@endforeach
</div>
</div>
<div class="flex flex-col gap-2 mt-2">
<x-label class="inline-flex " value="{{__('Preview')}}"/>
<div class=" h-full w-full border-2 border-indigo-500 rounded-2xl overflow-scroll">
{!! $this->getMailPreview($mail)->render() !!}
<div class=" h-full w-full border-2 border-indigo-500 rounded-2xl overflow-scroll"
x-data="{ inner: '<span></span>'}"
x-on:preview.window="inner='hallo'"
>
{!! $this->getMailPreview($formData) !!}
</div>
</div>
@empty($formData['attachments'])
@ -101,9 +108,9 @@ class="text-indigo-600 hover:text-indigo-900">Show
value="{{ __('No attachments where send with this message.') }}"/>
</div>
@else
<div class="flex flex-wrap col-span-6 mt-4 ">
<div class="flex flex-wrap col-span-6 mt-4 gap-2">
@foreach($formData['attachments'] as $key => $attachment)
<div class="flex items-center gap-2 rounded-xl border p-2">
<div class="flex items-center gap-2 rounded-xl border p-2">
<i class="fa-solid fa-paperclip fa-lg"></i>
<span class="" for="recipients">{{ $attachment['name'] }}</span>
</div>
@ -120,7 +127,7 @@ class="text-indigo-600 hover:text-indigo-900">Show
</x-slot>
<x-slot name="actions">
<div class="flex gap-2">
<x-secondary-button type="button" @click="window.open('{{route('mail',[$mail->id])}}','_blank')">
<x-secondary-button type="button" @click="window.open('{{$this->getPreviewRoute($formData)}}','_blank')">
full page preview
</x-secondary-button>