Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T24 verifying emails #30

Merged
merged 7 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
module WorkshopParticipantNotifier
module ParticipantNotifier
extend ActiveSupport::Concern

included do
after_action :workshop_participant_registration_notification,
only: [:create]
after_action :schedule_workshop_reminder_notification, only: [:create]
after_action :workshop_application_status_notification, only: [:update]
after_action :application_received_notification, only: [:apply]
after_action :registration_received_notification, only: [:create]
after_action :schedule_reminder_notifications, only: [:create]
after_action :application_status_notification,
only: [:update_application_status]
end

private

def workshop_participant_registration_notification
def registration_received_notification
if @workshop_participant.persisted?
WorkshopRegistrationEmailJob.perform_async(
RegistrationReceivedEmailJob.perform_async(
{
workshop_id: @workshop_participant.workshop.id,
participant_id: @workshop_participant.participant.id
Expand All @@ -21,23 +22,32 @@ def workshop_participant_registration_notification
end
end

def workshop_application_status_notification
def application_received_notification
ApplicationReceivedEmailJob.perform_async(
{
workshop_id: @workshop_participant.workshop.id,
participant_id: @workshop_participant.participant.id
}.stringify_keys
)
end

def application_status_notification
if workshop_participant_params[:application_status] == 'accepted'
WorkshopAcceptedEmailJob.perform_async(
ApplicationAcceptedEmailJob.perform_async(
{
workshop_id: @workshop_participant.workshop.id,
participant_id: @workshop_participant.participant.id
}.stringify_keys
)
elsif workshop_participant_params[:application_status] == 'rejected'
WorkshopRejectedEmailJob.perform_async(
ApplicationRejectedEmailJob.perform_async(
{
workshop_id: @workshop_participant.workshop.id,
participant_id: @workshop_participant.participant.id
}.stringify_keys
)
elsif workshop_participant_params[:application_status] == 'waitlisted'
WorkshopWaitlistedEmailJob.perform_async(
ApplicationWaitlistedEmailJob.perform_async(
{
workshop_id: @workshop_participant.workshop.id,
participant_id: @workshop_participant.participant.id
Expand All @@ -46,10 +56,10 @@ def workshop_application_status_notification
end
end

def schedule_workshop_reminder_notification
def schedule_reminder_notifications
if @workshop_participant.persisted?
if reminder_option_params[:reminder_options].include? 'One week before'
WorkshopReminderEmailJob.perform_at(
ReminderEmailOneWeekJob.perform_at(
(@workshop_participant.workshop.start_time - 1.weeks).round,
{
workshop_id: @workshop_participant.workshop.id,
Expand All @@ -59,7 +69,7 @@ def schedule_workshop_reminder_notification
end

if reminder_option_params[:reminder_options].include? 'One day before'
WorkshopReminderEmailJob.perform_at(
ReminderEmailOneDayJob.perform_at(
(@workshop_participant.workshop.start_time - 1.days).round,
{
workshop_id: @workshop_participant.workshop.id,
Expand All @@ -69,7 +79,7 @@ def schedule_workshop_reminder_notification
end

if reminder_option_params[:reminder_options].include? 'One hour before'
WorkshopReminderEmailJob.perform_at(
ReminderEmailOneHourJob.perform_at(
(@workshop_participant.workshop.start_time - 1.hours).round,
{
workshop_id: @workshop_participant.workshop.id,
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/facilitators_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ def edit

# POST /facilitators
def create
require 'pry'
binding.pry
@facilitator = Facilitator.new(facilitator_params)

respond_to do |format|
Expand Down
30 changes: 24 additions & 6 deletions app/controllers/workshop_participants_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
class WorkshopParticipantsController < ApplicationController
include WorkshopParticipantNotifier

before_action :set_workshop_participant, only: %i[show edit update destroy]
include ParticipantNotifier

before_action :set_workshop_participant,
only: %i[
show
edit
update_application_status
update_attendance_status
destroy
]
# before_action :require_login,
# only: %i[index show new edit create update destroy]

Expand Down Expand Up @@ -86,13 +93,24 @@ def create # this is used for registering, not applying
end
end

def update_application_status
respond_to do |format|
if @workshop_participant.update(workshop_participant_params)
format.turbo_stream {}
format.html { render workshop_path(@workshop_participant.workshop_id) }
else
format.html { render :edit, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /workshop_participants/1
def update
def update_attendance_status
respond_to do |format|
if @workshop_participant.update(workshop_participant_params)
format.turbo_stream do
render "workshop_participant_attendance_form_#{@workshop_participant.id}",
partial: 'workshop_participants/attendance_form'
render "workshop_participant_attendance_status_form_#{@workshop_participant.id}",
partial: 'workshop_participants/attendance_status_form'
end
format.html { render workshop_path(@workshop_participant.workshop_id) }
else
Expand Down
56 changes: 47 additions & 9 deletions app/mailers/participant_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,51 +1,89 @@
class ParticipantMailer < ApplicationMailer
include WorkshopsHelper
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.participant_mailer.workshop_registration_email.subject
#
def workshop_registration_email(workshop_id, participant_id)
def registration_received_email(workshop_id, participant_id)
@workshop = Workshop.find(workshop_id)
@participant = Participant.find(participant_id)
@message = "Thank you for registering for #{@workshop.title}!"

mail(to: @participant.email, subject: "Registered for #{@workshop.title}")
end

def workshop_reminder_email(workshop_id, participant_id)
def application_received_email(workshop_id, participant_id)
@workshop = Workshop.find(workshop_id)
@participant = Participant.find(participant_id)
@message = "Application received for #{@workshop.title}"

mail(
to: @participant.email,
subject: "Application for #{@workshop.title} received!"
)
end

def reminder_email_one_week(workshop_id, participant_id)
@workshop = Workshop.find(workshop_id)
@participant = Participant.find(participant_id)
@message =
"Reminder that #{@workshop.title} is today at #{human_readable_time(@workshop.start_time)}"
"Reminder that #{@workshop.title} is in one week on #{human_readable_date(@workshop.start_time)} at #{human_readable_time(@workshop.start_time)}"

mail(
to: @participant.email,
subject:
"Reminder: #{@workshop.title} at #{human_readable_time(@workshop.start_time)}"
"Reminder: #{@workshop.title} next week on #{human_readable_date(@workshop.start_time)} at #{human_readable_time(@workshop.start_time)}"
)
end

def workshop_waitlisted_email(workshop_id, participant_id)
def reminder_email_one_day(workshop_id, participant_id)
@workshop = Workshop.find(workshop_id)
@participant = Participant.find(participant_id)
@message = "You have been waitlisted for #{@workshop.title}"
@message =
"Reminder that #{@workshop.title} is tomorrow at #{human_readable_time(@workshop.start_time)}"

mail(to: @participant.email, subject: "Waitlisted: #{@workshop.title}")
mail(
to: @participant.email,
subject:
"Reminder: #{@workshop.title} tomorrow at #{human_readable_time(@workshop.start_time)}"
)
end

def reminder_email_one_hour(workshop_id, participant_id)
@workshop = Workshop.find(workshop_id)
@participant = Participant.find(participant_id)
@message =
"Reminder that #{@workshop.title} is in one hour at #{human_readable_time(@workshop.start_time)}"

mail(
to: @participant.email,
subject:
"Reminder: #{@workshop.title} today at #{human_readable_time(@workshop.start_time)}"
)
end

def workshop_accepted_email(workshop_id, participant_id)
def application_accepted_email(workshop_id, participant_id)
@workshop = Workshop.find(workshop_id)
@participant = Participant.find(participant_id)
@message = "You have been accepted for #{@workshop.title}"

mail(to: @participant.email, subject: "Accepted: #{@workshop.title}")
end

def workshop_rejected_email(workshop_id, participant_id)
def application_rejected_email(workshop_id, participant_id)
@workshop = Workshop.find(workshop_id)
@participant = Participant.find(participant_id)
@message = "You have been rejected for #{@workshop.title}"

mail(to: @participant.email, subject: "Rejected: #{@workshop.title}")
end

def application_waitlisted_email(workshop_id, participant_id)
@workshop = Workshop.find(workshop_id)
@participant = Participant.find(participant_id)
@message = "You have been waitlisted for #{@workshop.title}"

mail(to: @participant.email, subject: "Waitlisted: #{@workshop.title}")
end
end
18 changes: 0 additions & 18 deletions app/mailers/workshop_participant_mailer.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class WorkshopWaitlistedEmailJob
class ApplicationAcceptedEmailJob
include Sidekiq::Job
# sidekiq_options queue: :mailer

def perform(*args)
ParticipantMailer.workshop_waitlisted_email(
ParticipantMailer.application_accepted_email(
args[0]['workshop_id'],
args[0]['participant_id']
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class WorkshopRegistrationEmailJob
class ApplicationReceivedEmailJob
include Sidekiq::Job

def perform(*args)
ParticipantMailer.workshop_registration_email(
ParticipantMailer.application_received_email(
args[0]['workshop_id'],
args[0]['participant_id']
)
Expand Down
11 changes: 11 additions & 0 deletions app/sidekiq/application_rejected_email_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ApplicationRejectedEmailJob
include Sidekiq::Job
# sidekiq_options queue: :mailer

def perform(*args)
ParticipantMailer.application_rejected_email(
args[0]['workshop_id'],
args[0]['participant_id']
)
end
end
11 changes: 11 additions & 0 deletions app/sidekiq/application_waitlisted_email_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ApplicationWaitlistedEmailJob
include Sidekiq::Job
# sidekiq_options queue: :mailer

def perform(*args)
ParticipantMailer.application_waitlisted_email(
args[0]['workshop_id'],
args[0]['participant_id']
)
end
end
10 changes: 10 additions & 0 deletions app/sidekiq/registration_received_email_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class RegistrationReceivedEmailJob
include Sidekiq::Job

def perform(*args)
ParticipantMailer.registration_received_email(
args[0]['workshop_id'],
args[0]['participant_id']
)
end
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class WorkshopRejectedEmailJob
class ReminderEmailOneDayJob
include Sidekiq::Job
# sidekiq_options queue: :mailer

def perform(*args)
ParticipantMailer.workshop_rejected_email(
ParticipantMailer.reminder_email_one_day(
args[0]['workshop_id'],
args[0]['participant_id']
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class WorkshopReminderEmailJob
class ReminderEmailOneHourJob
include Sidekiq::Job
# sidekiq_options queue: :mailer

def perform(*args)
ParticipantMailer.workshop_reminder_email(
ParticipantMailer.reminder_email_one_hour(
args[0]['workshop_id'],
args[0]['participant_id']
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class WorkshopAcceptedEmailJob
class ReminderEmailOneWeekJob
include Sidekiq::Job
# sidekiq_options queue: :mailer

def perform(*args)
ParticipantMailer.workshop_accepted_email(
ParticipantMailer.reminder_email_one_week(
args[0]['workshop_id'],
args[0]['participant_id']
)
Expand Down
8 changes: 8 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
</head>

<body>
<% if current_facilitator.present? %>
<p>
Signed in as <%= current_facilitator.name %> - <%= button_to "Sign out", destroy_facilitator_session_path, method: :delete %>
</p>
<% else %>
<%= link_to "Facilitator sign in", new_facilitator_session_path %>
<% end %>

<%= yield %>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1> Application Accepted </h1>

<p>
<%= @message %>
</p>

<%= link_to 'Show Workshop', workshop_url(@workshop, host: 'localhost:3000')%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Accepted Application Email

<%= @message %>

<%= workshop_url(@workshop, host: 'localhost:3000')%>
Loading
Loading