diff --git a/demo/.env b/demo/.env index cd34b102..7383d470 100644 --- a/demo/.env +++ b/demo/.env @@ -26,3 +26,7 @@ HUGGINGFACE_API_KEY= ###> symfony/ai-open-ai-platform ### OPENAI_API_KEY= ###< symfony/ai-open-ai-platform ### + +###> symfony/mailer ### +MAILER_DSN=null://null +###< symfony/mailer ### diff --git a/demo/assets/styles/recipe.css b/demo/assets/styles/recipe.css index dff3302a..9b985742 100644 --- a/demo/assets/styles/recipe.css +++ b/demo/assets/styles/recipe.css @@ -25,4 +25,42 @@ } } } + + .share-overlay { + position: fixed; + inset: 0; + display: none; + align-items: center; + justify-content: center; + padding: 24px; + background: rgba(20, 30, 20, 0.55); + z-index: 1055; + } + + .share-overlay.is-open { + display: flex; + } + + .share-panel { + position: relative; + width: min(520px, 92vw); + padding: 24px 24px 20px; + border-radius: 16px; + background: #ffffff; + box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); + } + + .share-close { + position: absolute; + top: 10px; + right: 12px; + width: 32px; + height: 32px; + border-radius: 16px; + text-align: center; + line-height: 32px; + text-decoration: none; + color: #2f3f2f; + background: #f0f4ef; + } } diff --git a/demo/compose.override.yaml b/demo/compose.override.yaml new file mode 100644 index 00000000..8f2bb3d4 --- /dev/null +++ b/demo/compose.override.yaml @@ -0,0 +1,12 @@ + +services: +###> symfony/mailer ### + mailer: + image: axllent/mailpit + ports: + - "1025" + - "8025" + environment: + MP_SMTP_AUTH_ACCEPT_ANY: 1 + MP_SMTP_AUTH_ALLOW_INSECURE: 1 +###< symfony/mailer ### diff --git a/demo/composer.json b/demo/composer.json index 6aae4d4c..6c200cb4 100644 --- a/demo/composer.json +++ b/demo/composer.json @@ -31,6 +31,7 @@ "symfony/form": "^8.0", "symfony/framework-bundle": "^8.0", "symfony/http-client": "^8.0", + "symfony/mailer": "^8.0", "symfony/mcp-bundle": "^0.5", "symfony/mime": "^8.0", "symfony/monolog-bundle": "^4.0", diff --git a/demo/config/packages/mailer.yaml b/demo/config/packages/mailer.yaml new file mode 100644 index 00000000..56a650d8 --- /dev/null +++ b/demo/config/packages/mailer.yaml @@ -0,0 +1,3 @@ +framework: + mailer: + dsn: '%env(MAILER_DSN)%' diff --git a/demo/src/Recipe/TwigComponent.php b/demo/src/Recipe/TwigComponent.php index 56a9cbe6..cbe77da4 100644 --- a/demo/src/Recipe/TwigComponent.php +++ b/demo/src/Recipe/TwigComponent.php @@ -12,6 +12,8 @@ namespace App\Recipe; use App\Recipe\Data\Recipe; +use Symfony\Component\Mailer\MailerInterface; +use Symfony\Component\Mime\Email; use Symfony\UX\LiveComponent\Attribute\AsLiveComponent; use Symfony\UX\LiveComponent\Attribute\LiveAction; use Symfony\UX\LiveComponent\Attribute\LiveProp; @@ -25,8 +27,15 @@ final class TwigComponent #[LiveProp(writable: true)] public ?string $message = null; + #[LiveProp(writable: true)] + public ?string $shareEmail = null; + + #[LiveProp] + public bool $shareOpen = false; + public function __construct( private readonly Chat $chat, + private readonly MailerInterface $mailer, ) { } @@ -56,4 +65,46 @@ final class TwigComponent { $this->chat->reset(); } + + #[LiveAction] + public function openShare(): void + { + $this->shareOpen = true; + } + + #[LiveAction] + public function closeShare(): void + { + $this->shareOpen = false; + } + + #[LiveAction] + public function share(): void + { + if (null === $this->shareEmail || '' === trim($this->shareEmail)) { + return; + } + + if (false === filter_var($this->shareEmail, \FILTER_VALIDATE_EMAIL)) { + return; + } + + $recipe = $this->getRecipe(); + if (null === $recipe) { + return; + } + + $body = $recipe->toString().\PHP_EOL.\PHP_EOL.'Generated by https://github.com/symfony/ai-demo'; + + $email = (new Email()) + ->from('noreply@symfony-ai.demo') + ->to($this->shareEmail) + ->subject(\sprintf('Recipe: %s', $recipe->name)) + ->text($body); + + $this->mailer->send($email); + + $this->shareOpen = false; + $this->shareEmail = null; + } } diff --git a/demo/symfony.lock b/demo/symfony.lock index 91683474..f4b8b050 100644 --- a/demo/symfony.lock +++ b/demo/symfony.lock @@ -215,6 +215,18 @@ "src/Kernel.php" ] }, + "symfony/mailer": { + "version": "8.0", + "recipe": { + "repo": "github.com/symfony/recipes", + "branch": "main", + "version": "4.3", + "ref": "09051cfde49476e3c12cd3a0e44289ace1c75a4f" + }, + "files": [ + "config/packages/mailer.yaml" + ] + }, "symfony/mcp-bundle": { "version": "dev-main" }, diff --git a/demo/templates/components/recipe.html.twig b/demo/templates/components/recipe.html.twig index 7817c734..a2f93db7 100644 --- a/demo/templates/components/recipe.html.twig +++ b/demo/templates/components/recipe.html.twig @@ -72,6 +72,13 @@ {% endfor %} +
+
Share this recipe
+ +
@@ -92,6 +99,27 @@ +
+
+ +

+ {{ ux_icon('mdi:email-send', { height: '22px', width: '22px', class: 'me-2' }) }} + Share this recipe +

+

Send the recipe to an email address.

+
+ + +
+
+