- 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.
78 lines
3.2 KiB
PHP
78 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Manage\Cooperations\Actions\Cooperation;
|
|
|
|
use App\Enums\ApprovalStatus;
|
|
use App\Filament\Resources\Manage\Cooperations\CooperationResource;
|
|
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\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class AcceptAction extends Action
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->label('Terima')
|
|
->icon(Heroicon::OutlinedCheck)
|
|
->color('success')
|
|
->action(function (Cooperation $record): void {
|
|
$cooperationMedia = $record->cooperationMedia()
|
|
->whereHas('partnerMedia', function (Builder $query): void {
|
|
$query->whereHas('company', function (Builder $subQuery): void {
|
|
$subQuery->where('user_id', Auth::id());
|
|
});
|
|
})
|
|
->first();
|
|
|
|
if ($cooperationMedia) {
|
|
$cooperationMedia->update(['status' => ApprovalStatus::ACCEPTED]);
|
|
|
|
CheerfulNotification::success(
|
|
'Berhasil Diterima! ✅✨',
|
|
'Mantap! Anda telah menerima penawaran kerja sama ini. Silakan lanjut ke tahap pengajuan proposal ya! 💪'
|
|
)->send();
|
|
|
|
// Notify Admins
|
|
User::superAdmin()
|
|
->get()
|
|
->each(function ($admin) use ($record, $cooperationMedia): void {
|
|
$admin->notify(new BroadcastNotification([
|
|
'title' => 'Kabar Baik! Tawaran Diterima ✨🤝',
|
|
'body' => "Media {$cooperationMedia->partnerMedia->name} baru saja menerima penawaran kerja sama \"{$record->title}\". Siap-siap cek proposal mereka ya! 😊",
|
|
'action' => [
|
|
Action::make('view')
|
|
->label('Lihat')
|
|
->url(CooperationResource::getUrl('view', ['record' => $record->id])),
|
|
],
|
|
]));
|
|
});
|
|
}
|
|
})
|
|
->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 (Builder $query): void {
|
|
$query->whereHas('company', function (Builder $subQuery): void {
|
|
$subQuery->where('user_id', Auth::id());
|
|
});
|
|
})
|
|
->first();
|
|
|
|
return $cooperationMedia && $cooperationMedia->status === ApprovalStatus::PENDING;
|
|
});
|
|
}
|
|
}
|