Browse Source

container email

moell 9 months ago
parent
commit
43b9a855dc

+ 2 - 2
app/Http/Controllers/API/ContainerController.php

@@ -97,8 +97,6 @@ class ContainerController extends Controller
         $container->fill($formData);
         $container->save();
 
-        ActionRepository::createByContainer($container, ObjectAction::CREATED);
-
         $service->association($container->id);
 
         $files = File::query()->where('object_id', $container->id)
@@ -117,6 +115,8 @@ class ContainerController extends Controller
 
         ContainerContent::query()->create($contentFormData);
 
+        ActionRepository::createByContainer($container, ObjectAction::CREATED);
+
         return $this->created();
     }
 

+ 57 - 0
app/Mail/ContainerAction.php

@@ -0,0 +1,57 @@
+<?php
+
+namespace App\Mail;
+
+use App\Models\Container;
+use App\Models\Enums\ObjectAction;
+use App\Models\Task;
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Mail\Mailable;
+use Illuminate\Mail\Mailables\Content;
+use Illuminate\Mail\Mailables\Envelope;
+use Illuminate\Queue\SerializesModels;
+
+class ContainerAction extends Mailable
+{
+    use Queueable, SerializesModels;
+
+    /**
+     * Create a new message instance.
+     */
+    public function __construct(public Container $container, protected ObjectAction $objectAction, public array $actions = [])
+    {
+
+    }
+
+    /**
+     * Get the message envelope.
+     */
+    public function envelope(): Envelope
+    {
+        return new Envelope(
+            subject: $this->container->email_subject ?: $this->container->name,
+        );
+    }
+
+    /**
+     * Get the message content definition.
+     */
+    public function content(): Content
+    {
+        return new Content(
+            //view: 'view.name',
+            markdown: 'emails.actions.container',
+        );
+    }
+
+    /**
+     * Get the attachments for the message.
+     *
+     * @return array<int, \Illuminate\Mail\Mailables\Attachment>
+     */
+    public function attachments(): array
+    {
+        return [];
+    }
+}

+ 1 - 1
app/Mail/TaskAction.php

@@ -29,7 +29,7 @@ class TaskAction extends Mailable
     public function envelope(): Envelope
     {
         return new Envelope(
-            subject: $this->task->name,
+            subject: $this->task->email_subject ?: $this->task->name,
         );
     }
 

+ 4 - 0
app/Models/Enums/ObjectAction.php

@@ -95,6 +95,10 @@ enum ObjectAction: string
                 ObjectAction::DONE,
                 ObjectAction::CANCELED,
                 ObjectAction::EDITED,
+            ],
+            ActionObjectType::CONTAINER->value => [
+                ObjectAction::CREATED,
+                ObjectAction::EDITED,
             ]
         ];
     }

+ 8 - 0
app/Services/Notification/ActionEmail/ActionEmailService.php

@@ -2,9 +2,11 @@
 
 namespace App\Services\Notification\ActionEmail;
 
+use App\Mail\ContainerAction;
 use App\Mail\RequirementAction;
 use App\Mail\TaskAction;
 use App\Models\Action;
+use App\Models\Container;
 use App\Models\Enums\ActionObjectType;
 use App\Models\Enums\ObjectAction;
 use App\Models\Requirement;
@@ -45,9 +47,15 @@ class ActionEmailService
         match ($actionObjectType) {
             ActionObjectType::REQUIREMENT => $this->requirement($actionObjectModel),
             ActionObjectType::TASK => $this->task($actionObjectModel),
+            ActionObjectType::CONTAINER => $this->container($actionObjectModel),
         };
     }
 
+    protected function container(Container $container)
+    {
+        $this->dispatch($container->mailto, new ContainerAction($container, $this->objectAction, $this->actions));
+    }
+
     protected function requirement(Requirement $requirement)
     {
         $this->dispatch($requirement->mailto, new RequirementAction($requirement, $this->objectAction, $this->actions));

+ 14 - 0
resources/views/emails/actions/container.blade.php

@@ -0,0 +1,14 @@
+<x-mail::message>
+# Container Name: {{ $container->name }}
+
+<x-mail::panel>{{ sprintf("%s %s by %s", data_get($actions, '0.created_at'), data_get($actions, '0.action_label'), data_get($actions, '0.created_by.name')) }}</x-mail::panel>
+
+## Note
+
+{{ $container->content->description }}
+
+<x-email.history :actions="$actions"></x-email.history>
+
+Thanks,<br>
+{{ config('app.name') }}
+</x-mail::message>