Skip to content

Commit

Permalink
Finish up simple mails
Browse files Browse the repository at this point in the history
  • Loading branch information
PencilAmazing committed Dec 27, 2024
1 parent e1001fe commit 7394793
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
10 changes: 9 additions & 1 deletion app/mailers/locker_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class LockerMailer < ApplicationMailer

before_action do
@locker_rental = params[:locker_rental]
@user = params[:user]
@user = @locker_rental.rented_by
end

def locker_assigned
Expand All @@ -22,4 +22,12 @@ def locker_checkout
"Your locker rental for #{@locker_rental.locker_type.short_form} is ready for checkout"
)
end

def locker_cancelled
mail(
to: @user.email,
subject:
"Your locker rental for #{@locker_rental.locker_type.short_form} has been cancelled"
)
end
end
6 changes: 3 additions & 3 deletions app/models/locker_rental.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def under_review?
def send_email_notification
case state.to_sym
when :await_payment
LockerMailer.with(locker_rental: self).locker_checkout.deliver_later
LockerMailer.with(locker_rental: self).locker_checkout.deliver_now
when :active
LockerMailer.with(locker_rental: self).locker_assigned.deliver_later
LockerMailer.with(locker_rental: self).locker_assigned.deliver_now
when :cancelled
raise "Send cancelled email"
LockerMailer.with(locker_rental: self).locker_cancelled.deliver_now
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/locker_mailer/locker_assigned.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% provide :why_received, 'You have received this email because you have requested a locker' %>
Hello <%= @user.username %>,
You have been assigned a locker. Your locker is <b><%= @locker_rental.full_locker_name %></b> and is valid until <b><%= @locker_rental.owned_until.to_date %></b>.
<%= @message %>
<br />
Your request has been completed, and you have been assigned a locker. Your locker is <b><%= @locker_rental.full_locker_name %></b> and is valid until <b><%= @locker_rental.owned_until.to_date %></b>.
4 changes: 4 additions & 0 deletions app/views/locker_mailer/locker_cancelled.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<% provide :why_received, 'You have received this email because you have a locker assigned to you' %>
Hello <%= @user.name %>,
<br />
Your locker rental has been cancelled. Please ensure it is empty before <b><%= @locker_rental.owned_until.to_date %></b>.
3 changes: 2 additions & 1 deletion app/views/locker_mailer/locker_checkout.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% provide :why_received, 'You have received this email because you have requested a locker' %>
Hello <%= @user.name %>,
Your locker request has been approved. To finalize, you need to checkout. Click <%= link_to 'here', new_locker_rental_path %> to pay or cancel your locker request.
<br />
Your locker request has been approved, and is pending payment to be assigned. Go to <%= link_to 'your locker request', @locker_rental %> to pay or cancel your request.

0 comments on commit 7394793

Please sign in to comment.