Skip to content

Commit

Permalink
fix: improve sending recommendation (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhdramadhanarvin authored Jan 20, 2025
1 parent 9dbeedb commit 7ace1de
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/Console/Commands/ConvertStepsToCoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function handle()
], $step->id);
$this->coinRateRepository->update(['coin_balance' => $coinRate->coin_balance - $coinGet], 1);
$user->notify(new UserNotification(
NotificationEnum::COIN_CONVERT,
NotificationEnum::getValue('COIN_CONVERT'),
'Konversi otomatis ' . $stepCanConvert . ' langkah dengan ' .$coinGet .' koin'
));
}
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/SendRecommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function handle()

if ($achieveTarget) {
$user->notify(new UserNotification(
NotificationEnum::TARGET_NOT_ACHIEVED,
NotificationEnum::getValue('TARGET_NOT_ACHIEVED'),
'Target langkah hari ini belum tercapai, ikuti rekomendasi kami untuk kebugaran kamu (dari sistem)',
route('recommendation')
));
Expand Down
27 changes: 21 additions & 6 deletions app/Notifications/UserNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,25 @@
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Filament\Notifications\Actions\Action;
use Filament\Notifications\Notification as NotificationsFilament;

class UserNotification extends Notification
{
use Queueable;

protected $title;
protected $message;
protected $url;

/**
* Create a new notification instance.
*/
public function __construct(NotificationEnum $title, string $message)
public function __construct(string $title, string $message, string $url = "")
{
$this->title = $title;
$this->message = $message;
$this->url = $url;
}

/**
Expand Down Expand Up @@ -50,11 +54,22 @@ public function toMail(object $notifiable): MailMessage
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
public function toDatabase(object $notifiable): array
{
return [
'title' => $this->title,
'body' => $this->message
];
if ($this->url != '') {
return NotificationsFilament::make()
->title($this->title)
->body($this->message)
->actions([
Action::make('lihat')
->button()
->url($this->url),
])
->getDatabaseMessage();
}
return NotificationsFilament::make()
->title($this->title)
->body($this->message)
->getDatabaseMessage();
}
}

0 comments on commit 7ace1de

Please sign in to comment.