Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 91 additions & 12 deletions db/seeds/dev/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
<div style="background-color:#f3f4f6;border-radius:6px;padding:12px;margin:16px 0;text-align:left;">
<p><strong>Subject:</strong> #{subject}</p>
<p>#{message}</p>
</div>
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")
Expand All @@ -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
<h1>We received your message</h1>
<p>Hello #{sample[:first_name]},</p>
<p>Thank you for reaching out. A member of our team will review your inquiry and get back to you as soon as possible.</p>
#{quoted_block.call(sample[:subject], sample[:message])}
<p>In community,<br>AWBW Programs</p>
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"
Expand All @@ -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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

πŸ€– From Claude: The block in find_or_create_by! only runs on create, so records seeded before bodies were added here would stay body-less on re-run. This backfill makes re-seeding idempotently repair them.


fyi_html = <<~HTML.strip
<h1>New contact form submission</h1>
<p><strong>#{sample[:first_name]} #{sample[:last_name]}</strong> has submitted a message through the contact form.</p>
<p><strong>Email:</strong> #{sample[:from]}</p>
#{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"
Expand All @@ -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 = "<h1>#{attrs[:subject]}</h1>\n<p>#{attrs[:body]}</p>"
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]
Expand All @@ -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 " \
Expand Down