Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#277 - reply to messages #288

Merged
merged 11 commits into from
Jul 8, 2024
25 changes: 25 additions & 0 deletions app/DTOs/ContactFormResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Blumilk\Website\DTOs;

use Blumilk\Website\Models\ContactForm;

class ContactFormResponse
{
public function __construct(
public string $subject,
public string $response,
public string $messageDescription,
) {}

public static function fromArray(ContactForm $record, array $data): self
{
return new self(
subject: $data["responseTopic"],
response: $data["response"],
messageDescription: $record->message,
);
}
}
10 changes: 9 additions & 1 deletion app/Filament/Resources/ContactFormResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Blumilk\Website\Enums\ContactFormStatus;
use Blumilk\Website\Enums\DateFormats;
use Blumilk\Website\Filament\Resources\ContactFormResource\Actions\RespondToContactFormMessageAction;
use Blumilk\Website\Filament\Resources\ContactFormResource\Pages;
use Blumilk\Website\Models\ContactForm;
use Exception;
Expand Down Expand Up @@ -50,6 +51,12 @@ public static function form(Form $form): Form
->rows(4)
->label("Wiadomość")
->disabled(),
Forms\Components\RichEditor::make("response")
->label("Odpowiedź")
->disableToolbarButtons(["attachFiles"])
->maxLength(65000)
->disabled()
->visible(fn($record): bool => $record->status === ContactFormStatus::Responded),
]),
])->from("lg"),
])->columns(1);
Expand Down Expand Up @@ -105,7 +112,8 @@ public static function table(Table $table): Table
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
Tables\Actions\DeleteAction::make()->visible(fn($record): bool => $record->status !== ContactFormStatus::Responded),
RespondToContactFormMessageAction::make("respond"),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace Blumilk\Website\Filament\Resources\ContactFormResource\Actions;

use Blumilk\Website\DTOs\ContactFormResponse;
use Blumilk\Website\Enums\ContactFormStatus;
use Blumilk\Website\Mail\ContactFormResponded;
use Blumilk\Website\Models\ContactForm;
use Filament\Forms;
use Filament\Notifications\Notification;
use Filament\Tables\Actions\Action;
use Illuminate\Support\Facades\Mail;

class RespondToContactFormMessageAction extends Action
{
protected function setUp(): void
{
parent::setUp();

$this->label("Odpowiedz")
->icon("heroicon-m-envelope")
->color("success")
->visible(fn($record): bool => $record->status !== ContactFormStatus::Responded)
->form([
Forms\Components\Section::make([
Forms\Components\TextInput::make("email")
->label("E-mail")
->disabled()
->default(fn($record) => $record->email),
Forms\Components\TextInput::make("topic")
->label("Temat")
->disabled()
->default(fn($record) => $record->topic),
Forms\Components\Textarea::make("message")
->label("Wiadomość")
->default(fn($record) => $record->message)
->disabled(),
]),
Forms\Components\TextInput::make("responseTopic")
->label("Tytuł odpowiedzi")
->default(fn($record) => "Re: " . $record->topic),
Forms\Components\RichEditor::make("response")
->label("Odpowiedź")
->disableToolbarButtons(["attachFiles", "codeBlock", "blockquote"])
->maxLength(65000)
->required(),
])
->action(function (ContactForm $record, array $data): void {
$details = ContactFormResponse::fromArray($record, $data);

Mail::to($record->email)->send(new ContactFormResponded($details));

$record->update([
"response" => $details->response,
"status" => ContactFormStatus::Responded,
]);

Notification::make()
->title("Sukces")
->body("E-mail został pomyślnie wysłany.")
->success()
->send();
})
->modalHeading("Wyślij odpowiedź na e-mail")
->modalButton("Wyślij e-mail");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Blumilk\Website\Filament\Resources\ContactFormResource\Pages;

use Blumilk\Website\Enums\ContactFormStatus;
use Blumilk\Website\Filament\Resources\BaseResource\Pages\BaseEditRecord;
use Blumilk\Website\Filament\Resources\ContactFormResource;
use Filament\Actions;
Expand All @@ -15,7 +16,7 @@ class EditActivity extends BaseEditRecord
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Actions\DeleteAction::make()->visible(fn($record): bool => $record->status !== ContactFormStatus::Responded),
];
}
}
26 changes: 26 additions & 0 deletions app/Mail/ContactFormResponded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Blumilk\Website\Mail;

use Blumilk\Website\DTOs\ContactFormResponse;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class ContactFormResponded extends Mailable
{
use Queueable;
use SerializesModels;

public function __construct(
public ContactFormResponse $details,
) {}

public function build(): self
{
return $this->subject($this->details->subject)
->view("email");
}
}
1 change: 1 addition & 0 deletions app/Models/ContactForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ContactForm extends Model
"topic",
"message",
"status",
"response",
];
protected $casts = [
"status" => ContactFormStatus::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
public function up(): void
{
Schema::table("contact_forms", function (Blueprint $table): void {
$table->text("response")->nullable();
});
}

public function down(): void
{
Schema::table("contact_forms", function (Blueprint $table): void {
$table->dropColumn("response");
});
}
};
27 changes: 0 additions & 27 deletions lang/en/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,33 +213,6 @@
"part_3" => "and thereby consent to the processing of my personal data by the Administrator.",
],
],
"contact" => [
"title_1" => "Write",
"title_2" => "to us!",
"company" => "Blumilk Sp. z o.o.",
"subtitle" => "Are you interested enough to want to discuss your project with us, exchange ideas, become our business partner, or work with us? We would love to talk with you!",
"form" => [
"email" => "Email",
"title" => "Topic",
"message" => "Message",
],
"location" => [
"address" => "ul. Najświętszej Marii Panny 5f/5",
"PostalCode" => "59-220 Legnica",
],
"phone" => "+48 780 142 367",
"email" => "office@blumilk.pl",
"info" => [
"NIP" => "6912551135",
"KRS" => "0000866755",
"REGON" => "38737620",
],
"policy" => [
"part_1" => "I accept the terms and conditions and",
"part_2" => "privacy policy",
"part_3" => "and thereby consent to the processing of my personal data by the Administrator.",
],
],
"policy" => [
"title_1" => "Privacy",
"title_2" => "policy",
Expand Down
27 changes: 0 additions & 27 deletions lang/pl/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,33 +213,6 @@
"part_3" => "i tym samym wyrażam zgodę na przetwarzanie przez Administratora moich danych osobowych.",
],
],
"contact" => [
"title_1" => "Napisz",
"title_2" => "do nas!",
"company" => "Blumilk Sp. z o.o.",
"subtitle" => "Zainteresowaliśmy Cię na tyle, że chcesz z nami omówić swój projekt, wymienić myśli, zostać naszym partnerem biznesowym, lub z nami pracować? Chętnie z Tobą porozmawiamy!",
"form" => [
"email" => "E-mail",
"title" => "Temat",
"message" => "Wiadomość",
],
"location" => [
"address" => "ul. Najświętszej Marii Panny 5f/5",
"PostalCode" => "59-220 Legnica",
],
"phone" => "+48 780 142 367",
"email" => "office@blumilk.pl",
"info" => [
"NIP" => "6912551135",
"KRS" => "0000866755",
"REGON" => "38737620",
],
"policy" => [
"part_1" => "Akceptuję regulamin oraz",
"part_2" => "politykę prywatności",
"part_3" => "i tym samym wyrażam zgodę na przetwarzanie przez Administratora moich danych osobowych.",
],
],
"policy" => [
"title_1" => "Polityka",
"title_2" => "prywatności",
Expand Down
Binary file added public/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions resources/views/email.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!doctype html>
<html lang="pl">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Odpowiedź na formularz kontaktowy</title>
</head>
<body style="font-family: Helvetica, sans-serif; -webkit-font-smoothing: antialiased; font-size: 16px; line-height: 1.3; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; background-color: #F6F7FD; margin: 0; padding: 0;">
<table role="presentation" style="border-collapse: separate; width: 100%;" class="body">
<tr>
<td>&nbsp;</td>
<td style="margin: 0 auto !important; max-width: 600px; padding: 24px 0 0;width: 600px;" class="container">
<div style="box-sizing: border-box; display: block; margin: 0 auto; max-width: 600px; padding: 0;" class="content">
<h2 style="margin: 0; text-align: center;">Odpowiedź z formularza kontaktowego</h2>
<table role="presentation" style="color: #000000; width: 100%;" class="main">
<tr>
<td style="box-sizing: border-box; padding: 24px;" class="wrapper">
<div style="text-align: right;">
<h3>Twoja wiadomość</h3>
<div style="background: #ffffff; border-radius: 16px; width: 100%; padding: 4px 12px 4px 4px;">
<p>{!! $details->messageDescription !!}</p>
</div>
</div>
<h3 style="padding-top: 8px">Odpowiedź</h3>
<div style="background: #ffffff; border-radius: 16px; width: 100%; padding: 4px 4px 4px 12px;">
{!! $details->response !!}
</div>
</td>
</tr>
</table>
<div style="clear: both; padding-top: 24px; padding-bottom: 24px; text-align: left; width: 100%;" class="footer">
<table role="presentation" style="margin: 0; text-align: left; width: 100%;">
<tr>
<td style="font-size: 16px; text-align: left;" class="content-block">
<div style="display: flex; align-items: center;">
<img src="https://www.blumilk.pl/logo.png" class="logo" style="height: 80px; margin: auto 8px auto 16px;" alt="Blumilk Logo">
<div>
<span>Blumilk sp. z o.o.</span><br>
<span style="color: #000000; text-decoration: none;">office@blumilk.pl</span><br>
<span>+48 780 142 367</span><br>
<span>ul. Najświętszej Marii Panny 5F/5 59-220 Legnica</span><br>
<span>
<a href="https://clutch.co/profile/blumilk-0" style="color: #000000; text-decoration: underline;">Clutch</a> |
<a href="https://github.com/blumilksoftware" style="color: #000000; text-decoration: underline;">Github</a> |
<a href="https://linkedin.com/company/blumilksoftware" style="color: #000000; text-decoration: underline;">LinkedIn</a> |
<a href="https://www.facebook.com/blumilksoftware/" style="color: #000000; text-decoration: underline;">Facebook</a> |
<a href="https://www.youtube.com/@blumilksoftware" style="color: #000000; text-decoration: underline;">YouTube</a>
</span>
</div>
</div>
</td>
</tr>
</table>
</div>
</div>
</td>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>
Loading