diff --git a/db/seeds/dev/notifications.rb b/db/seeds/dev/notifications.rb index 46bca6e06..25c26a62b 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}
+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
#{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[: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 " \