From cb47b8fda3c31eeb861df441bc52ab47260a5710 Mon Sep 17 00:00:00 2001 From: maebeale Date: Mon, 22 Jun 2026 11:57:20 -0400 Subject: [PATCH] Give every seeded notification an email body Seeded contact-us and FYI notifications set a subject but never email_body_html/text, so the admin "Email Preview" pane rendered "No email body captured." Render realistic HTML + text bodies for each, and backfill any pre-existing body-less seed records on re-run. Co-Authored-By: Claude Opus 4.8 --- db/seeds/dev/notifications.rb | 103 ++++++++++++++++++++++++++++++---- 1 file changed, 91 insertions(+), 12 deletions(-) diff --git a/db/seeds/dev/notifications.rb b/db/seeds/dev/notifications.rb index 46bca6e065..25c26a62bc 100644 --- a/db/seeds/dev/notifications.rb +++ b/db/seeds/dev/notifications.rb @@ -2,13 +2,38 @@ # as part of `rake db:seed:dev`. Seeds contact-us and a few FYI notifications. puts "Creating Notifications…" + +# Shared HTML wrapper so every seeded body renders like a real (mailer-rendered) +# email in the admin "Email Preview" pane (notifications/show), rather than the +# "No email body captured." placeholder you get when email_body_* is blank. +quoted_block = ->(subject, message) do + <<~HTML.strip +
+

Subject: #{subject}

+

#{message}

+
+ HTML +end + contact_us_samples = [ - { from: "jordan.hayes@example.com", subject: "Question about facilitating Comfort Journals" }, - { from: "priya.patel@example.com", subject: "Interested in starting a chapter" }, - { from: "sam.wong@example.com", subject: "Press inquiry — Survivor Voices article" }, - { from: "lee.morgan@example.com", subject: "Donation receipt request" }, - { from: "chris.alvarez@example.com", subject: "Workshop materials availability" }, - { from: "robin.singh@example.com", subject: "Volunteer opportunities" } + { first_name: "Jordan", last_name: "Hayes", from: "jordan.hayes@example.com", + subject: "Question about facilitating Comfort Journals", + message: "I recently completed the facilitator training and would love guidance on running my first Comfort Journals workshop. Are there sample session plans you can share?" }, + { first_name: "Priya", last_name: "Patel", from: "priya.patel@example.com", + subject: "Interested in starting a chapter", + message: "Our community shelter would like to bring AWBW programming to our residents. What does starting a local chapter involve?" }, + { first_name: "Sam", last_name: "Wong", from: "sam.wong@example.com", + subject: "Press inquiry — Survivor Voices article", + message: "I'm writing a feature on trauma-informed art programs and would like to interview someone from your team. What's the best way to coordinate?" }, + { first_name: "Lee", last_name: "Morgan", from: "lee.morgan@example.com", + subject: "Donation receipt request", + message: "I made a donation last month but never received a receipt for my records. Could you resend it to this address?" }, + { first_name: "Chris", last_name: "Alvarez", from: "chris.alvarez@example.com", + subject: "Workshop materials availability", + message: "Do you ship the workshop supply kits internationally, or are they only available within the US?" }, + { first_name: "Robin", last_name: "Singh", from: "robin.singh@example.com", + subject: "Volunteer opportunities", + message: "I have a background in counseling and would like to volunteer. Where can I learn about current openings?" } ] reply_to_email = ENV.fetch("REPLY_TO_EMAIL", "programs@awbw.org") @@ -17,7 +42,28 @@ contact_us_samples.each_with_index do |sample, i| delivered_at = (contact_us_samples.size - i).days.ago - Notification.find_or_create_by!( + confirmation_html = <<~HTML.strip +

We received your message

+

Hello #{sample[:first_name]},

+

Thank you for reaching out. A member of our team will review your inquiry and get back to you as soon as possible.

+ #{quoted_block.call(sample[:subject], sample[:message])} +

In community,
AWBW Programs

+ HTML + confirmation_text = <<~TEXT.strip + We received your message + + Hello #{sample[:first_name]}, + + Thank you for reaching out. A member of our team will review your inquiry and get back to you as soon as possible. + + Subject: #{sample[:subject]} + #{sample[:message]} + + In community, + AWBW Programs + TEXT + + confirmation = Notification.find_or_create_by!( recipient_email: sample[:from], email_subject: "We received your message", kind: "contact_us" @@ -26,9 +72,30 @@ n.recipient_role = "person" n.notification_type = 0 n.delivered_at = delivered_at + n.email_body_html = confirmation_html + n.email_body_text = confirmation_text end + # Backfill bodies on records seeded before email_body_* was added here + confirmation.update!(email_body_html: confirmation_html, email_body_text: confirmation_text) if confirmation.email_body_html.blank? + + fyi_html = <<~HTML.strip +

New contact form submission

+

#{sample[:first_name]} #{sample[:last_name]} has submitted a message through the contact form.

+

Email: #{sample[:from]}

+ #{quoted_block.call(sample[:subject], sample[:message])} + HTML + fyi_text = <<~TEXT.strip + New contact form submission + + #{sample[:first_name]} #{sample[:last_name]} has submitted a message through the contact form. - Notification.find_or_create_by!( + Email: #{sample[:from]} + + Subject: #{sample[:subject]} + #{sample[:message]} + TEXT + + fyi = Notification.find_or_create_by!( recipient_email: reply_to_email, email_subject: "[FYI] New contact form submission from #{sample[:from]}: #{sample[:subject]}", kind: "contact_us_fyi" @@ -39,16 +106,25 @@ n.delivered_at = delivered_at # Mark older submissions as already responded so the green checks are visible n.responded = i < (contact_us_samples.size / 2) + n.email_body_html = fyi_html + n.email_body_text = fyi_text end + fyi.update!(email_body_html: fyi_html, email_body_text: fyi_text) if fyi.email_body_html.blank? end # A few non-contact-us notifications so the em-dash rendering is visible too [ - { kind: "event_registration_confirmation_fyi", subject: "[FYI] New event registration" }, - { kind: "idea_submitted_fyi", subject: "[FYI] New story idea submission by a contributor" }, - { kind: "workshop_log_submitted_fyi", subject: "New WorkshopLog submission" } + { kind: "event_registration_confirmation_fyi", subject: "[FYI] New event registration", + body: "A new event registration has been submitted through the portal. Review the registrant's details and form answers in the events dashboard." }, + { kind: "idea_submitted_fyi", subject: "[FYI] New story idea submission by a contributor", + body: "A contributor has submitted a new story idea. Review the submission and any attached quotes or images in the admin area." }, + { kind: "workshop_log_submitted_fyi", subject: "New WorkshopLog submission", + body: "A facilitator has logged a completed workshop. Review the session details and participant counts in the reporting dashboard." } ].each_with_index do |attrs, i| - Notification.find_or_create_by!( + body_html = "

#{attrs[:subject]}

\n

#{attrs[:body]}

" + body_text = "#{attrs[:subject]}\n\n#{attrs[:body]}" + + notification = Notification.find_or_create_by!( recipient_email: reply_to_email, email_subject: attrs[:subject], kind: attrs[:kind] @@ -57,7 +133,10 @@ n.recipient_role = "admin" n.notification_type = 0 n.delivered_at = (i + 1).days.ago + n.email_body_html = body_html + n.email_body_text = body_text end + notification.update!(email_body_html: body_html, email_body_text: body_text) if notification.email_body_html.blank? end puts " Created #{Notification.where(kind: %w[contact_us contact_us_fyi]).count} contact_us notifications " \