[done] mail template done. Not checked if the mail is sent.

This commit is contained in:
guillaume91 2024-06-13 16:29:54 +02:00
parent 44d5c17e8a
commit 88060f6fc3
10 changed files with 272 additions and 63 deletions

View file

@ -27,7 +27,7 @@ class BuildReports extends Command
public function handle()
{
// TODO schedule all the project if mail
Project::all()->each(function (Project $project) {
Project::where(['mail_scheduled' => true])->each(function (Project $project) {
$project->schedule();
});
}

View file

@ -2,6 +2,7 @@
namespace App\Livewire\Projects\Tabs;
use App\Mail\ReportMailer;
use App\Models\Project;
use App\Models\ProjectMailing;
use Livewire\Component;
@ -79,4 +80,9 @@ public function render()
'mailings' => $mailings,
]);
}
public function getMailPreview($mail)
{
return new ReportMailer($mail);
}
}

View file

@ -50,8 +50,9 @@ public function content(): Content
markdown: 'emails.scheduled-report',
with: [
'mailingContent' => $this->mailing->message,
'logoPath'=> Storage::disk('app')->path('images/smartcane.png'),
'logoPath'=> Storage::disk('local')->path('images/smartcane.png'),
'subject' => $this->mailing->subject,
'mailing' => $this->mailing,
],
//htmlString: $this->mailing->message
);

View file

@ -258,10 +258,7 @@ public function startDownload(Carbon $date)
public function schedule()
{
// if ($this->shouldSchedule()) {
$this->scheduleReport();
// }
}
public function shouldSchedule(): bool
@ -304,7 +301,7 @@ public function scheduleReport($year = null, $week = null)
Bus::chain([
Bus::batch($this->getFileDownloadsFor($year, $week)),
Bus::batch($this->getMosaicsFor($year, $week)),
Bus::batch([$this->getReportFor($year, $week, true)]),
Bus::batch([$this->getReportFor($year, $week,true)]),
])
->dispatch();
return "done";

View file

@ -20,6 +20,7 @@
"plesk/ext-laravel-integration": "^7.0"
},
"require-dev": {
"barryvdh/laravel-debugbar": "*",
"fakerphp/faker": "^1.23",
"laravel/pint": "^1.13",
"laravel/sail": "^1.26",

View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "02a769bc324ca6d387d9e85c61229c6b",
"content-hash": "3780ed65b4c427fb760c558bbcc7441e",
"packages": [
{
"name": "bacon/bacon-qr-code",
@ -8069,6 +8069,90 @@
}
],
"packages-dev": [
{
"name": "barryvdh/laravel-debugbar",
"version": "v3.13.5",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-debugbar.git",
"reference": "92d86be45ee54edff735e46856f64f14b6a8bb07"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/92d86be45ee54edff735e46856f64f14b6a8bb07",
"reference": "92d86be45ee54edff735e46856f64f14b6a8bb07",
"shasum": ""
},
"require": {
"illuminate/routing": "^9|^10|^11",
"illuminate/session": "^9|^10|^11",
"illuminate/support": "^9|^10|^11",
"maximebf/debugbar": "~1.22.0",
"php": "^8.0",
"symfony/finder": "^6|^7"
},
"require-dev": {
"mockery/mockery": "^1.3.3",
"orchestra/testbench-dusk": "^5|^6|^7|^8|^9",
"phpunit/phpunit": "^9.6|^10.5",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.13-dev"
},
"laravel": {
"providers": [
"Barryvdh\\Debugbar\\ServiceProvider"
],
"aliases": {
"Debugbar": "Barryvdh\\Debugbar\\Facades\\Debugbar"
}
}
},
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Barryvdh\\Debugbar\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "PHP Debugbar integration for Laravel",
"keywords": [
"debug",
"debugbar",
"laravel",
"profiler",
"webprofiler"
],
"support": {
"issues": "https://github.com/barryvdh/laravel-debugbar/issues",
"source": "https://github.com/barryvdh/laravel-debugbar/tree/v3.13.5"
},
"funding": [
{
"url": "https://fruitcake.nl",
"type": "custom"
},
{
"url": "https://github.com/barryvdh",
"type": "github"
}
],
"time": "2024-04-12T11:20:37+00:00"
},
{
"name": "fakerphp/faker",
"version": "v1.23.1",
@ -8383,6 +8467,74 @@
},
"time": "2024-03-20T20:09:31+00:00"
},
{
"name": "maximebf/debugbar",
"version": "v1.22.3",
"source": {
"type": "git",
"url": "https://github.com/maximebf/php-debugbar.git",
"reference": "7aa9a27a0b1158ed5ad4e7175e8d3aee9a818b96"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/7aa9a27a0b1158ed5ad4e7175e8d3aee9a818b96",
"reference": "7aa9a27a0b1158ed5ad4e7175e8d3aee9a818b96",
"shasum": ""
},
"require": {
"php": "^7.2|^8",
"psr/log": "^1|^2|^3",
"symfony/var-dumper": "^4|^5|^6|^7"
},
"require-dev": {
"dbrekelmans/bdi": "^1",
"phpunit/phpunit": "^8|^9",
"symfony/panther": "^1|^2.1",
"twig/twig": "^1.38|^2.7|^3.0"
},
"suggest": {
"kriswallsmith/assetic": "The best way to manage assets",
"monolog/monolog": "Log using Monolog",
"predis/predis": "Redis storage"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.22-dev"
}
},
"autoload": {
"psr-4": {
"DebugBar\\": "src/DebugBar/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Maxime Bouroumeau-Fuseau",
"email": "maxime.bouroumeau@gmail.com",
"homepage": "http://maximebf.com"
},
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "Debug bar in the browser for php application",
"homepage": "https://github.com/maximebf/php-debugbar",
"keywords": [
"debug",
"debugbar"
],
"support": {
"issues": "https://github.com/maximebf/php-debugbar/issues",
"source": "https://github.com/maximebf/php-debugbar/tree/v1.22.3"
},
"time": "2024-04-03T19:39:26+00:00"
},
{
"name": "mockery/mockery",
"version": "1.6.11",

View file

@ -3,8 +3,6 @@
<div {{ $attributes->merge(['class' => '']) }}>
<div class="mt-5 px-6">
<h2>{{ $title }}</h2>
<span name="description">{{ $description }}</span>
</div>
<div class="mt-5 md:mt-0 md:col-span-1">
@ -13,6 +11,7 @@
<div class="flex flex-col">
{{ $form }}
</div>
<span name="description">{{ $description }}</span>
</div>
@if (isset($actions))
@ -20,6 +19,7 @@
{{ $actions }}
</div>
@endif
</form>
</div>
</div>

View file

@ -1,16 +1,68 @@
<x-mail::message>
<x-mail::layout>
{{-- Header --}}
<x-slot:header>
<x-mail::header :url="config('app.url')">
<span>
<img src="{{$message->embed($logoPath)}}" alt="Smartcane Logo">
</span>
</x-mail::header>
</x-slot:header>
{{-- Body --}}
# <h1 style="text-align: center">Report</h1>
# ![]({{$message->embed($logoPath)}}) Smartcane - +31 6 2037 6734
## Subject: {{$subject}}
## Report update for {{$subject}}
*This report is automatically generated. Do not reply.*
**Body:**
{{$mailingContent}}
{{$mailingContent}}
Thanks.
Thanks,<br>
## Contact
{{config('app.name')}}
<table>
<tbody>
<tr>
<td>
<p style="text-align:center;">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" style="width: 20px;height: 20px;"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path fill="#475060" d="M16 64C16 28.7 44.7 0 80 0H304c35.3 0 64 28.7 64 64V448c0 35.3-28.7 64-64 64H80c-35.3 0-64-28.7-64-64V64zM224 448a32 32 0 1 0 -64 0 32 32 0 1 0 64 0zM304 64H80V384H304V64z"/></svg>
</p>
</td>
<td>
<p style="text-align:justify-all;"><a href="tel:0031620376734">+31 6 2037 6734</a></p>
</td>
</tr>
<tr>
<td>
<p style="text-align:center;">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" style="width: 20px;height: 20px;"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path fill="#475060" d="M256 64C150 64 64 150 64 256s86 192 192 192c17.7 0 32 14.3 32 32s-14.3 32-32 32C114.6 512 0 397.4 0 256S114.6 0 256 0S512 114.6 512 256v32c0 53-43 96-96 96c-29.3 0-55.6-13.2-73.2-33.9C320 371.1 289.5 384 256 384c-70.7 0-128-57.3-128-128s57.3-128 128-128c27.9 0 53.7 8.9 74.7 24.1c5.7-5 13.1-8.1 21.3-8.1c17.7 0 32 14.3 32 32v80 32c0 17.7 14.3 32 32 32s32-14.3 32-32V256c0-106-86-192-192-192zm64 192a64 64 0 1 0 -128 0 64 64 0 1 0 128 0z"/></svg>
</p>
</td>
<td>
<p style="text-align:justify-all;"><a href="mailto:info@smartcane.org">info@smartcane.org</a></p>
</td>
</tr>
<tr>
<td>
<p style="text-align:center;">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512" style="width: 20px;height: 20px;"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path fill="#475060" d="M48 0C21.5 0 0 21.5 0 48V464c0 26.5 21.5 48 48 48h96V432c0-26.5 21.5-48 48-48s48 21.5 48 48v80h96c26.5 0 48-21.5 48-48V48c0-26.5-21.5-48-48-48H48zM64 240c0-8.8 7.2-16 16-16h32c8.8 0 16 7.2 16 16v32c0 8.8-7.2 16-16 16H80c-8.8 0-16-7.2-16-16V240zm112-16h32c8.8 0 16 7.2 16 16v32c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V240c0-8.8 7.2-16 16-16zm80 16c0-8.8 7.2-16 16-16h32c8.8 0 16 7.2 16 16v32c0 8.8-7.2 16-16 16H272c-8.8 0-16-7.2-16-16V240zM80 96h32c8.8 0 16 7.2 16 16v32c0 8.8-7.2 16-16 16H80c-8.8 0-16-7.2-16-16V112c0-8.8 7.2-16 16-16zm80 16c0-8.8 7.2-16 16-16h32c8.8 0 16 7.2 16 16v32c0 8.8-7.2 16-16 16H176c-8.8 0-16-7.2-16-16V112zM272 96h32c8.8 0 16 7.2 16 16v32c0 8.8-7.2 16-16 16H272c-8.8 0-16-7.2-16-16V112c0-8.8 7.2-16 16-16z"/></svg>
</p>
</td>
<td>
<p style="text-align:justify-all;"><a href="https://smartcane.org">Bevrijdingsstraat 38, 6703AA, Wageningen, The Netherlands</a></p>
</td>
</tr>
</tbody>
</table>
</x-mail::message>
{{-- Footer --}}
<x-slot:footer>
<x-mail::footer>
<p style="text-align:center;">SmartCane is an innovative spinoff from the Resilience Network, which includes SmartFarming BV and IRIPO Lda.</p>
<p>
© {{ date('Y') }} {{ config('app.name') }}. {{ __('All rights reserved.') }}
</p>
</x-mail::footer>
</x-slot:footer>
</x-mail::layout>

View file

@ -3,13 +3,14 @@
<div class="sm:flex sm:flex-col sm:items-center">
<div class="w-full flex justify-between my-4">
<h1 class="text-base font-semibold leading-6 text-gray-900">{{ __('Mailing') }}</h1>
<livewire:components.pending-message :project="$project" type="mailings"></livewire:components.pending-message>
<livewire:components.pending-message :project="$project"
type="mailings"></livewire:components.pending-message>
</div>
<div class="mt-4 sm:mt-0 sm:flex sm:justify-between w-full">
<x-search></x-search>
</div>
</div>
<div class="mt-8 ">
<div class="mt-8">
<div class="">
<div class="inline-block min-w-full py-2 align-middle mb-10">
<div class="">
@ -39,7 +40,9 @@ class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">@lang('Attachm
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6 lg:pl-8">{{ $mail->id }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ $mail->subject }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
<livewire:components.badge :status="$mail->status" :id="$mail->id" type="mailing" wire:key="{{$mail->id}}"></livewire:components.badge>
<livewire:components.badge :status="$mail->status" :id="$mail->id"
type="mailing"
wire:key="{{$mail->id}}"></livewire:components.badge>
</td>
<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>
@ -67,41 +70,29 @@ class="text-indigo-600 hover:text-indigo-900">Show
<x-modal wire:model="mailingDetailsModal">
<x-form-modal submit="saveProject">
<x-slot name="title">
<div class="text-xl font-semibold justify-center text-center text-black">
{{ __('Mailing') }}
</x-slot>
<x-slot name="description">
<x-label for="created_at" value="{{ __('Created') }}"/>
<x-label id="created_at"
value="{{ \Carbon\Carbon::parse($formData['created_at'])->format('Y-m-d H:i') }}"/>
</div>
</x-slot>
<x-slot name="form">
<div class="col-span-6">
<div class="col-span-6 py-2">
<x-label for="recipients" value="{{ __('Recipients') }}"/>
<div class="flex flex-wrap gap-2 pt-2">
@foreach($formData['recipients'] as $key => $recipient)
<div class="col-span-6 sm:col-span-4">
<x-label class="inline-block" for="recipients"
value="{{ $recipient['name'] }}"/>
<x-label class="inline-block" for="recipients"
value="<{{ $recipient['email'] }}>"/>
<div class="flex bg-gray-100 text-gray-700 text-xs p-2 rounded-lg items-center gap-2">
<i class="fa-regular fa-address-card fa-lg"></i>
<div><span class="inline-block" for="recipients">[{{ $recipient['name'] }}]</span>
<span class="inline-block" for="recipients">{{ $recipient['email'] }}</span></div>
</div>
@endforeach
</div>
<div class="col-span-6">
<x-label for="subject" value="{{ __('Subject') }}"/>
<x-input id="subject" type="text" class="mt-1 block w-full" disabled
wire:model="formData.subject"/>
</div>
<div class="col-span-6">
<x-label for="message" value="{{ __('Message') }}"/>
<textarea
id="message"
type="text"
class="mt-1 block w-full"
wire:model="formData.message"
disabled
></textarea>
<div class="flex flex-col gap-2 mt-2">
<x-label class="inline-flex " value="{{__('Preview')}}"/>
<div class="col-span-6 border-2 border-indigo-500 rounded-2xl overflow-hidden">
{!! $this->getMailPreview($mail)->render() !!}
</div>
</div>
@empty($formData['attachments'])
<div class="col-span-6">
@ -110,14 +101,23 @@ class="mt-1 block w-full"
value="{{ __('No attachments where send with this message.') }}"/>
</div>
@else
<div class="flex flex-wrap col-span-6 mt-4 ">
@foreach($formData['attachments'] as $key => $attachment)
<div class="col-span-6">
<x-label class="inline-block" for="recipients"
value="{{ $attachment['name'] }}"/>
<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>
@endforeach
</div>
@endempty
</x-slot>
<x-slot name="description">
<div class="flex gap-2 justify-end">
<x-label for="created_at" value="{{ __('Created at') }}"/>
<x-label id="created_at"
value="{{ \Carbon\Carbon::parse($formData['created_at'])->format('Y-m-d H:i') }}"/>
</div>
</x-slot>
<x-slot name="actions">
<x-secondary-button class="mr-3"
type="button"

View file

@ -16,11 +16,11 @@
Route::get('/', function () {
return view('welcome');
});
if (env('APP_ENV') === 'local') {
Route::get('/mailable', function () {
return new App\Mail\ReportGenerated(App\Models\ProjectMailing::find(1));
});
}
Route::get('/mailable/{id}', function ($id) {
if($project_mailing = App\Models\ProjectMailing::find($id)) return new App\Mail\ReportMailer($project_mailing);
return abort(404);
})->name('mail');
Route::middleware([
'auth:sanctum',
config('jetstream.auth_session'),