Improve transactional emails

This commit is contained in:
2022-02-10 15:45:22 +00:00
parent 127c972304
commit 5e2eabac0c
16 changed files with 134 additions and 45 deletions

View File

@@ -23,7 +23,6 @@ namespace App\Listeners;
use App\Events\ApplicationApprovedEvent; use App\Events\ApplicationApprovedEvent;
use App\Notifications\ApplicationApproved; use App\Notifications\ApplicationApproved;
use App\StaffProfile;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
class PromoteUser class PromoteUser
@@ -46,15 +45,12 @@ class PromoteUser
*/ */
public function handle(ApplicationApprovedEvent $event) public function handle(ApplicationApprovedEvent $event)
{ {
Log::info('User '.$event->application->user->name . 'has just been promoted (application approved)');
$event->application->setStatus('APPROVED'); $event->application->setStatus('APPROVED');
$event->application->response->vacancy->decrease(); $event->application->response->vacancy->decrease();
$event->application->user->assignRole('reviewer'); $event->application->user->assignRole('reviewer');
Log::info('User '.$event->application->user->name.' has just been promoted!', [
'newRank' => $event->application->response->vacancy->permissionGroupName,
]);
$event->application->user->notify(new ApplicationApproved($event->application)); $event->application->user->notify(new ApplicationApproved($event->application));
} }
} }

View File

@@ -24,6 +24,7 @@ namespace App\Notifications;
use App\Application; use App\Application;
use App\Facades\Options; use App\Facades\Options;
use App\Traits\Cancellable; use App\Traits\Cancellable;
use App\User;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\MailMessage;
@@ -34,16 +35,27 @@ class ApplicationApproved extends Notification implements ShouldQueue
{ {
use Queueable, Cancellable; use Queueable, Cancellable;
public $application;
/**
* @var Application The application we're notifying about
*/
public Application $application;
/**
* @var User The candidate
*/
public User $user;
/** /**
* Create a new notification instance. * Create a new notification instance.
* *
* @return void * @return void
*/ */
public function __construct(Application $application) public function __construct(User $user, Application $application)
{ {
$this->application = $application; $this->application = $application;
$this->user = $user;
} }
public function channels() public function channels()
@@ -65,17 +77,17 @@ class ApplicationApproved extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - '.$this->application->response->vacancy->vacancyName.' application approved') ->subject(config('app.name').' - '.$this->application->response->vacancy->vacancyName.' application approved')
->line('<br />') ->line('<br />')
->line('Congratulations! Our Staff team has reviewed your application today, and your application has been approved.') ->line('Congratulations! Your most recent application has been approved by the reviewing team.')
->line('You have just received the Reviewer role, which allows you to view and vote on other applications.') ->line('You have just received the Reviewer role, which allows you to view and vote on other applications.')
->line('Your in-game rank should be updated network-wide in the next few minutes, allowing you to perform staff duties.') ->line('You should have received more information about your onboarding process by now.')
->line('Please join a voice channel when possible for your training meeting, if this has been mentioned by your interviewer.')
->line('<br />') ->line('<br />')
->line('Good luck and welcome aboard!') ->line('Good luck and welcome aboard!')
->action('Sign in', url(route('login'))) ->action('Sign in', url(route('login')))
->line('Thank you!'); ->line('The team at ' . config('app.name'));
} }
public function toSlack($notifiable) public function toSlack($notifiable)

View File

@@ -0,0 +1,68 @@
<?php
namespace App\Notifications;
use App\Application;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class ApplicationConfirmed extends Notification
{
use Queueable;
protected $application;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Application $application)
{
$this->application = $application;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->salutation('Hi' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name') . ' - application confirmed')
->line('We\'re writing you to let you know that your recent application with us has been received, and will be processed in 24/48 hours.')
->line('You will receive regular notifications about your application\'s status.')
->action('View active applications', url(route('showUserApps')))
->line('The team at ' . config('app.name'));
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}

View File

@@ -64,13 +64,14 @@ class ApplicationDenied extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - '.$this->application->response->vacancy->vacancyName.' application denied') ->subject(config('app.name').' - application denied')
->line('Your most recent application has been denied.') ->line('We\'re sorry to inform you that your application with us has been reviewed and declined.')
->line('Our review team denies applications for several reasons, including poor answers.') ->line('Our review team denies applications for several reasons, including poor answers, missing information, or lacking qualifications.')
->line('Please review your application and try again in 30 days.') ->line('Please review your application and try again later. You can view your account\'s eligibility status in your dashboard.')
->action('Review application', url(route('showUserApp', ['application' => $this->application->id]))) ->action('Review application', url(route('showUserApp', ['application' => $this->application->id])))
->line('Better luck next time!'); ->line('The team at ' . config('app.name'));
} }
public function toSlack($notifiable) public function toSlack($notifiable)

View File

@@ -56,12 +56,13 @@ class ApplicationMoved extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - Application Updated') ->subject(config('app.name').' - application updated')
->line('Your most recent application has been moved up a stage.') ->line('Your application has been moved to the next step.')
->line('This means our team has reviewed it and an interview will be scheduled ASAP.') ->line('This means our team has reviewed it and an interview will be scheduled soon.')
->action('Sign in', url(route('login'))) ->action('Sign in', url(route('login')))
->line('Thank you!'); ->line('The team at ' . config('app.name'));
} }
/** /**

View File

@@ -51,16 +51,16 @@ class AppointmentCancelled extends Notification
// TODO: Switch to HTML & Blade. // TODO: Switch to HTML & Blade.
return (new MailMessage) return (new MailMessage)
->salutation("Hi " . $notifiable->name . ",")
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - Interview Cancelled') ->subject(config('app.name').' - interview cancelled')
->greeting("Hi " . explode(' ', $this->application->user->name, 2)[0] . ",") ->line('The interview that was previously scheduled with you has been cancelled.')
->line('The interview that was previously scheduled with you has been cancelled by a staff member.') ->line('Date and time of the old appointment: '.$this->appointmentDate)
->line('Date & time of the old appointment: '.$this->appointmentDate)
->line('Your appointment was cancelled for the following reason: ' . $this->reason) ->line('Your appointment was cancelled for the following reason: ' . $this->reason)
->line('A staff member may contact you to reschedule within a new timeframe - you may also let us know of a date and time that suits you.') ->line('A team member may contact you to reschedule within a new timeframe - you may also let us know of a date and time that suits you.')
->line('Your application will be automatically rejected within 7 days if an interview is not scheduled.') ->line('Your application will likely be declined if you do not reschedule an interview.')
->action('View ongoing applications', url(route('showUserApps'))) ->action('View active applications', url(route('showUserApps')))
->line('Thank you!'); ->line('The team at ' . config('app.name'));
} }
/** /**

View File

@@ -60,12 +60,14 @@ class AppointmentFinished extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->salutation("Hi " . $notifiable->name . ",")
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - Appointment completed') ->subject(config('app.name').' - appointment completed')
->line('Your appointment has been marked as completed!') ->line('Your appointment has been marked as completed!')
->line('Please allow an additional day for your application to be fully processed.') ->line('Please allow an additional day for your application to be fully processed.')
->action('View applications', url(route('showUserApps'))) ->action('View applications', url(route('showUserApps')))
->line('Thank you!'); ->line('The team at ' . config('app.name'));
} }
/** /**

View File

@@ -63,14 +63,14 @@ class AppointmentScheduled extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - Interview Scheduled') ->subject(config('app.name').' - Interview scheduled')
->line('A voice interview has been scheduled for you @ '.$this->appointment->appointmentDate.'.') ->line('An interview has been scheduled for you @ '.$this->appointment->appointmentDate.'.')
->line('With the following details: '.$this->appointment->appointmentDescription) ->line('With the following details: '.$this->appointment->appointmentDescription)
->line('This meeting will take place @ '.$this->appointment->appointmentLocation.'. You will receive an email soon with details on how to join this meeting.') ->line('This meeting will take place @ '.$this->appointment->appointmentLocation.'.')
->line('Please join a public voice channel (or another platform if specified) at around this time.')
->action('Sign in', url(route('login'))) ->action('Sign in', url(route('login')))
->line('Thank you!'); ->line('The team at ' . config('app.name'));
} }
/** /**

View File

@@ -60,12 +60,13 @@ class ChangedPassword extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - Account password changed') ->subject(config('app.name').' - Account password changed')
->line('The password for the account registered to this email address has just been changed.') ->line('The password for the account registered to this email address has just been changed.')
->line('If this was not you, please contact an administrator immediately.') ->line('If this was not you, please contact an administrator immediately.')
->action('Sign in', url(route('login'))) ->action('Sign in', url(route('login')))
->line('Thank you!'); ->line('The team at ' . config('app.name'));
} }
/** /**

View File

@@ -60,11 +60,13 @@ class EmailChanged extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - Email address changed') ->subject(config('app.name').' - Email address changed')
->line('The email address for your account has just been updated, either by you or an administrator.') ->line('The email address for your account has just been updated.')
->line('If this was not you, please change your password immediately. We recommend you also activate multi-factor authentication.')
->action('Sign in', url(route('login'))) ->action('Sign in', url(route('login')))
->line('Thank you!'); ->line('The team at ' . config('app.name'));
} }
/** /**

View File

@@ -73,12 +73,13 @@ class NewApplicant extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - New application') ->subject(config('app.name').' - New application')
->line('Someone has just applied for a position. Check it out!') ->line('Someone has just applied for a position. Check it out!')
->line('You are receiving this because you\'re a staff member at '.config('app.name').'.') ->line('You are receiving this because you\'re a staff member at '.config('app.name').'.')
->action('View Application', url(route('showUserApp', ['application' => $this->application->id]))) ->action('View Application', url(route('showUserApp', ['application' => $this->application->id])))
->line('Thank you!'); ->salutation('The team at ' . config('app.name'));
} }
public function toSlack($notifiable) public function toSlack($notifiable)

View File

@@ -60,12 +60,13 @@ class NewComment extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - New comment') ->subject(config('app.name').' - New comment')
->line('Someone has just posted a new comment on an application you follow.') ->line('Someone has just posted a new comment on an application you follow.')
->line('You\'re receiving this email because you\'ve voted/commented on this application.') ->line('You\'re receiving this email because you\'ve voted/commented on this application.')
->action('Check it out', url(route('showUserApp', ['application' => $this->application->id]))) ->action('Check it out', url(route('showUserApp', ['application' => $this->application->id])))
->line('Thank you!'); ->salutation('The team at ' . config('app.name'));
} }
/** /**

View File

@@ -67,6 +67,7 @@ class NewContact extends Notification
'email', 'email',
])) { ])) {
return (new MailMessage) return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->line('We\'ve received a new contact form submission in the StaffManagement app center.') ->line('We\'ve received a new contact form submission in the StaffManagement app center.')
->line('This is what they sent: ') ->line('This is what they sent: ')
->line('') ->line('')
@@ -74,7 +75,7 @@ class NewContact extends Notification
->line('') ->line('')
->line('This message was received from '.$this->message->get('ip').' and submitted by '.$this->message->get('email').'.') ->line('This message was received from '.$this->message->get('ip').' and submitted by '.$this->message->get('email').'.')
->action('Sign in', url(route('login'))) ->action('Sign in', url(route('login')))
->line('Thank you!'); ->salutation('The team at ' . config('app.name'));
} }
throw new \InvalidArgumentException('Invalid arguments supplied to NewContact!'); throw new \InvalidArgumentException('Invalid arguments supplied to NewContact!');

View File

@@ -66,12 +66,13 @@ class NewUser extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - New user') ->subject(config('app.name').' - New user')
->line($this->user->name.' has just registered to our site.') ->line($this->user->name.' has just registered to our site.')
->line('You are receiving this email because you opted to receive new user notifications.') ->line('You are receiving this email because you opted to receive new user notifications.')
->action('View profile', url(route('showSingleProfile', ['user' => $this->user->id]))) ->action('View profile', url(route('showSingleProfile', ['user' => $this->user->id])))
->line('Thank you!'); ->salutation('The team at ' . config('app.name'));
} }
public function toSlack($notifiable) public function toSlack($notifiable)

View File

@@ -67,12 +67,13 @@ class UserBanned extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->line('Hello, ') ->line('Hello, ')
->line('Moderators have just banned user '.$this->user->name.' for '.$this->ban->reason) ->line('Moderators have just banned user '.$this->user->name.' for '.$this->ban->reason)
->line('This ban will remain in effect until '.$this->ban->bannedUntil.'.') ->line('This ban will remain in effect until '.$this->ban->bannedUntil.'.')
->action('View profile', url(route('showSingleProfile', ['user' => $this->user->id]))) ->action('View profile', url(route('showSingleProfile', ['user' => $this->user->id])))
->line('Thank you!'); ->salutation('The team at ' . config('app.name'));
} }
/** /**

View File

@@ -60,12 +60,13 @@ class VacancyClosed extends Notification implements ShouldQueue
public function toMail($notifiable) public function toMail($notifiable)
{ {
return (new MailMessage) return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name')) ->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - Vacancy Closed') ->subject(config('app.name').' - Vacancy Closed')
->line('The vacancy '.$this->vacancy->vacancyName.', with '.$this->vacancy->vacancyCount.' remaining slots, has just been closed.') ->line('The vacancy '.$this->vacancy->vacancyName.', with '.$this->vacancy->vacancyCount.' remaining slots, has just been closed.')
->line('Please be aware that this position may be deleted/reopened any time.') ->line('Please be aware that this position may be deleted/reopened any time.')
->action('View positions', url(route('showPositions'))) ->action('View positions', url(route('showPositions')))
->line('Thank you!'); ->salutation('The team at ' . config('app.name'));
} }
/** /**