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
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="no-reply@blumilk.pl"
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
MAIL_FROM_NAME="${APP_NAME}"

ANALYTICS_URL="https://analytics.google.com/analytics/web/#/p000000000"
Expand Down
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) => $record->status === ContactFormStatus::Responded),
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
]),
])->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) => $record->status !== ContactFormStatus::Responded),
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
RespondToContactFormMessageAction::make("respond"),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

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

use Blumilk\Website\Enums\ContactFormStatus;
use Blumilk\Website\Mail\ContactFormResponded;
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) => $record->status !== ContactFormStatus::Responded)
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
->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 ($record, $data): void {
$details = [
"subject" => $data["responseTopic"],
"response" => $data["response"],
"messageDescription" => $record->message,
];
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved

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

$record->update([
"response" => $data["response"],
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved
"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");
}
}
28 changes: 28 additions & 0 deletions app/Mail/ContactFormResponded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Blumilk\Website\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class ContactFormResponded extends Mailable
{
use Queueable;
use SerializesModels;

public array $details;

public function __construct($details)
{
$this->details = $details;
}
kamilpiech97 marked this conversation as resolved.
Show resolved Hide resolved

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");
});
}
};
62 changes: 62 additions & 0 deletions resources/views/email.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<span>ul. Najświętszej Marii Panny 5f/5 59-220 Legnica</span><br>
<span>ul. Najświętszej Marii Panny 5F/5 59-220 Legnica</span><br>

I think that on contact page is the same little typo

<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>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Loading