- Introduce `CheerfulNotification` utility class to standardize cheerful and expressive notifications across the application. - Refactor custom "Cheerful" actions (Create, Edit, Delete, etc.) and `DefaultBulkActions` to utilize the new utility class. - Update all `ToggleColumn` status updates in Master Data modules to use `CheerfulNotification::statusUpdated()`. - Replace inline `Notification::make()` calls in custom actions (Reply, Crawl News, Cooperation actions) and Resource Pages with `CheerfulNotification` methods. - Address various lint errors by standardizing the use of the `Auth` facade and improving type hinting for the authenticated `User` model.
71 lines
2.6 KiB
PHP
71 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Manage\Cooperations\Actions\Cooperation;
|
|
|
|
use App\Enums\ApprovalStatus;
|
|
use App\Filament\Support\CheerfulNotification;
|
|
use App\Models\Cooperation;
|
|
use App\Models\User;
|
|
use App\Notifications\BroadcastNotification;
|
|
use Filament\Actions\Action;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class RejectAction extends Action
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->label('Tolak')
|
|
->icon(Heroicon::XMark)
|
|
->color('danger')
|
|
->action(function (Cooperation $record): void {
|
|
$cooperationMedia = $record->cooperationMedia()
|
|
->whereHas('partnerMedia', function ($query) {
|
|
$query->whereHas('company', function ($subQuery) {
|
|
$subQuery->where('user_id', Auth::id());
|
|
});
|
|
})
|
|
->first();
|
|
|
|
if ($cooperationMedia) {
|
|
$cooperationMedia->update(['status' => ApprovalStatus::REJECTED]);
|
|
|
|
CheerfulNotification::info(
|
|
'Berhasil Ditolak 🙏',
|
|
'Terima kasih atas konfirmasinya. Pesan penolakan telah diteruskan ke Admin. 😊'
|
|
)->send();
|
|
|
|
// Notify Admins
|
|
User::superAdmin()
|
|
->get()
|
|
->each(function ($admin) use ($record, $cooperationMedia): void {
|
|
$admin->notify(new BroadcastNotification([
|
|
'title' => 'Yah, Tawaran Ditolak 😔🤝',
|
|
'body' => "Media {$cooperationMedia->partnerMedia->name} baru saja menolak penawaran kerja sama \"{$record->title}\". Mungkin di lain waktu ya! 🙏",
|
|
]));
|
|
});
|
|
}
|
|
})
|
|
->visible(function (Cooperation $record): bool {
|
|
/** @var \App\Models\User $user */
|
|
$user = Auth::user();
|
|
|
|
if (! $user || ! $user->hasRole('Perusahaan')) {
|
|
return false;
|
|
}
|
|
|
|
$cooperationMedia = $record->cooperationMedia()
|
|
->whereHas('partnerMedia', function ($query) {
|
|
$query->whereHas('company', function ($subQuery) {
|
|
$subQuery->where('user_id', Auth::id());
|
|
});
|
|
})
|
|
->first();
|
|
|
|
return $cooperationMedia && $cooperationMedia->status === ApprovalStatus::PENDING;
|
|
});
|
|
}
|
|
}
|