simedkom/app/Filament/Resources/Publication/Announcements/Pages/ManageAnnouncements.php
Yoga Pangestu 2983cd243f refactor: centralize cheerful notifications and cleanup auth calls
- 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.
2026-01-14 09:54:46 +07:00

56 lines
1.9 KiB
PHP

<?php
namespace App\Filament\Resources\Publication\Announcements\Pages;
use App\Enums\AnnouncementType;
use App\Filament\Actions\Cheerful\CreateAction;
use App\Filament\Resources\Publication\Announcements\AnnouncementResource;
use App\Models\Company;
use App\Models\PartnerMedia;
use App\Models\User;
use App\Notifications\BroadcastNotification;
use Filament\Resources\Pages\ManageRecords;
use Filament\Support\Enums\Width;
class ManageAnnouncements extends ManageRecords
{
protected static ?string $title = 'Pengumuman';
protected static string $resource = AnnouncementResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make()
->label('Tambah')
->modalHeading('Tambah Pengumuman')
->modalSubmitActionLabel('Simpan')
->modalCancelActionLabel('Batal')
->extraModalFooterActions(fn (CreateAction $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
->label('Simpan dan Tambah Lagi'),
])
->modalWidth(Width::TwoExtraLarge)
->after(function (array $data) {
if ($data['type'] === AnnouncementType::PUBLIC) {
return;
}
$payload = [
'title' => $data['title'],
'body' => $data['content'],
];
$userIds = Company::whereIn(
'id',
PartnerMedia::whereIn('id', $data['partnerMedia'])->pluck('company_id')
)->pluck('user_id');
User::whereIn('id', $userIds)->each(function ($user) use ($payload) {
$user->notify(new BroadcastNotification($payload));
});
}),
];
}
}