Improve transactional emails

This commit is contained in:
Miguel Nogueira 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\Notifications\ApplicationApproved;
use App\StaffProfile;
use Illuminate\Support\Facades\Log;
class PromoteUser
@ -46,15 +45,12 @@ class PromoteUser
*/
public function handle(ApplicationApprovedEvent $event)
{
Log::info('User '.$event->application->user->name . 'has just been promoted (application approved)');
$event->application->setStatus('APPROVED');
$event->application->response->vacancy->decrease();
$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));
}
}

View File

@ -24,6 +24,7 @@ namespace App\Notifications;
use App\Application;
use App\Facades\Options;
use App\Traits\Cancellable;
use App\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
@ -34,16 +35,27 @@ class ApplicationApproved extends Notification implements ShouldQueue
{
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.
*
* @return void
*/
public function __construct(Application $application)
public function __construct(User $user, Application $application)
{
$this->application = $application;
$this->user = $user;
}
public function channels()
@ -65,17 +77,17 @@ class ApplicationApproved extends Notification implements ShouldQueue
public function toMail($notifiable)
{
return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - '.$this->application->response->vacancy->vacancyName.' application approved')
->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('Your in-game rank should be updated network-wide in the next few minutes, allowing you to perform staff duties.')
->line('Please join a voice channel when possible for your training meeting, if this has been mentioned by your interviewer.')
->line('You should have received more information about your onboarding process by now.')
->line('<br />')
->line('Good luck and welcome aboard!')
->action('Sign in', url(route('login')))
->line('Thank you!');
->line('The team at ' . config('app.name'));
}
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)
{
return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - '.$this->application->response->vacancy->vacancyName.' application denied')
->line('Your most recent application has been denied.')
->line('Our review team denies applications for several reasons, including poor answers.')
->line('Please review your application and try again in 30 days.')
->subject(config('app.name').' - application 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, missing information, or lacking qualifications.')
->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])))
->line('Better luck next time!');
->line('The team at ' . config('app.name'));
}
public function toSlack($notifiable)

View File

@ -56,12 +56,13 @@ class ApplicationMoved extends Notification implements ShouldQueue
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 Updated')
->line('Your most recent application has been moved up a stage.')
->line('This means our team has reviewed it and an interview will be scheduled ASAP.')
->subject(config('app.name').' - application updated')
->line('Your application has been moved to the next step.')
->line('This means our team has reviewed it and an interview will be scheduled soon.')
->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.
return (new MailMessage)
->salutation("Hi " . $notifiable->name . ",")
->from(config('notification.sender.address'), config('notification.sender.name'))
->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 by a staff member.')
->line('Date & time of the old appointment: '.$this->appointmentDate)
->subject(config('app.name').' - interview cancelled')
->line('The interview that was previously scheduled with you has been cancelled.')
->line('Date and time of the old appointment: '.$this->appointmentDate)
->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('Your application will be automatically rejected within 7 days if an interview is not scheduled.')
->action('View ongoing applications', url(route('showUserApps')))
->line('Thank 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 likely be declined if you do not reschedule an interview.')
->action('View active applications', url(route('showUserApps')))
->line('The team at ' . config('app.name'));
}
/**

View File

@ -60,12 +60,14 @@ class AppointmentFinished extends Notification implements ShouldQueue
public function toMail($notifiable)
{
return (new MailMessage)
->salutation("Hi " . $notifiable->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('Please allow an additional day for your application to be fully processed.')
->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)
{
return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - Interview Scheduled')
->line('A voice interview has been scheduled for you @ '.$this->appointment->appointmentDate.'.')
->subject(config('app.name').' - Interview scheduled')
->line('An interview has been scheduled for you @ '.$this->appointment->appointmentDate.'.')
->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('Please join a public voice channel (or another platform if specified) at around this time.')
->line('This meeting will take place @ '.$this->appointment->appointmentLocation.'.')
->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)
{
return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - Account password 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.')
->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)
{
return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name'))
->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')))
->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)
{
return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - New application')
->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').'.')
->action('View Application', url(route('showUserApp', ['application' => $this->application->id])))
->line('Thank you!');
->salutation('The team at ' . config('app.name'));
}
public function toSlack($notifiable)

View File

@ -60,12 +60,13 @@ class NewComment extends Notification implements ShouldQueue
public function toMail($notifiable)
{
return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->from(config('notification.sender.address'), config('notification.sender.name'))
->subject(config('app.name').' - New comment')
->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.')
->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',
])) {
return (new MailMessage)
->salutation('Hi ' . $notifiable->name . ',')
->line('We\'ve received a new contact form submission in the StaffManagement app center.')
->line('This is what they sent: ')
->line('')
@ -74,7 +75,7 @@ class NewContact extends Notification
->line('')
->line('This message was received from '.$this->message->get('ip').' and submitted by '.$this->message->get('email').'.')
->action('Sign in', url(route('login')))
->line('Thank you!');
->salutation('The team at ' . config('app.name'));
}
throw new \InvalidArgumentException('Invalid arguments supplied to NewContact!');

View File

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

View File

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