All checks were successful
deploy / deploy (push) Successful in 1m10s
- Add ReviewNotifier for verification emails - Add review token generation and verification - Add request_review_verification function - Update reviews_section component with write-a-review form - Create ReviewForm LiveView for submitting/editing reviews - Add /reviews/new and /reviews/:id/edit routes - Add review buttons to order detail page - Update block_types to load real review data - Tests for token and verification functions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
65 lines
1.5 KiB
Elixir
65 lines
1.5 KiB
Elixir
defmodule Berrypod.Reviews.ReviewNotifier do
|
|
@moduledoc """
|
|
Sends transactional emails for the review system.
|
|
|
|
Verification emails for review submission, and review request emails
|
|
after order delivery.
|
|
"""
|
|
|
|
import Swoosh.Email
|
|
|
|
alias Berrypod.Mailer
|
|
|
|
require Logger
|
|
|
|
@doc """
|
|
Sends a verification email with a link to leave a review.
|
|
|
|
The link contains a signed token encoding the email and product_id.
|
|
"""
|
|
def deliver_review_verification(email, product_title, link) do
|
|
subject = "Leave a review for #{product_title}"
|
|
|
|
body = """
|
|
==============================
|
|
|
|
Thanks for your purchase!
|
|
|
|
Click here to leave a review for #{product_title}:
|
|
|
|
#{link}
|
|
|
|
This link expires in 1 hour.
|
|
|
|
If you didn't request this, you can ignore this email.
|
|
|
|
==============================
|
|
"""
|
|
|
|
deliver(email, subject, body)
|
|
end
|
|
|
|
# --- Private ---
|
|
|
|
defp deliver(recipient, subject, body) do
|
|
shop_name = Berrypod.Settings.get_setting("shop_name", "Berrypod")
|
|
from_address = Berrypod.Settings.get_setting("email_from_address", "contact@example.com")
|
|
|
|
email =
|
|
new()
|
|
|> to(recipient)
|
|
|> from({shop_name, from_address})
|
|
|> subject(subject)
|
|
|> text_body(body)
|
|
|
|
case Mailer.deliver(email) do
|
|
{:ok, _metadata} = result ->
|
|
result
|
|
|
|
{:error, reason} = error ->
|
|
Logger.warning("Failed to send review email to #{recipient}: #{inspect(reason)}")
|
|
error
|
|
end
|
|
end
|
|
end
|