Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
jringeisen committed Feb 11, 2024
2 parents be5ba09 + 28d31dc commit 216eced
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 16 deletions.
39 changes: 39 additions & 0 deletions app/Notifications/FeedbackCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Notifications;

use App\Models\Feedback;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Slack\BlockKit\Blocks\SectionBlock;
use Illuminate\Notifications\Slack\SlackMessage;

class FeedbackCreated extends Notification
{
use Queueable;

public function __construct(
public Feedback $feedback
) {
}

public function via(): array
{
return ['slack'];
}

public function toSlack(): SlackMessage
{
return (new SlackMessage)
->headerBlock('Feedback Received')
->sectionBlock(function (SectionBlock $block) {
$block->text('User: '.$this->feedback->user->name.' '.$this->feedback->user->email);
})
->sectionBlock(function (SectionBlock $block) {
$block->text('Title: '.$this->feedback->title);
})
->sectionBlock(function (SectionBlock $block) {
$block->text('Description: '.$this->feedback->description);
});
}
}
16 changes: 0 additions & 16 deletions app/Notifications/NewUserRegistered.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Slack\SlackMessage;

Expand All @@ -22,21 +21,6 @@ public function via(object $notifiable): array
return ['slack'];
}

public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}

public function toArray(object $notifiable): array
{
return [
//
];
}

public function toSlack(object $notifiable): SlackMessage
{
if ($this->user->isParent()) {
Expand Down
19 changes: 19 additions & 0 deletions app/Observers/FeedbackObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Observers;

use App\Models\Feedback;
use App\Notifications\FeedbackCreated;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Notification;

class FeedbackObserver
{
public function created(Feedback $feedback): void
{
if (App::isProduction()) {
Notification::route('slack', '#user-feedback')
->notify(new FeedbackCreated($feedback));
}
}
}
3 changes: 3 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace App\Providers;

use App\Models\Feedback;
use App\Models\NewsletterList;
use App\Models\PromptQuestion;
use App\Models\User;
use App\Observers\FeedbackObserver;
use App\Observers\NewsletterListObserver;
use App\Observers\PromptQuestionObserver;
use App\Observers\UserObserver;
Expand Down Expand Up @@ -33,6 +35,7 @@ public function boot(): void
PromptQuestion::observe(PromptQuestionObserver::class);
NewsletterList::observe(NewsletterListObserver::class);
User::observe(UserObserver::class);
Feedback::observe(FeedbackObserver::class);
}

/**
Expand Down

0 comments on commit 216eced

Please sign in to comment.