simedkom/app/Filament/Resources/Monitoring/MediaMonitorings/Actions/CrawlNewsAction.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

65 lines
2.3 KiB
PHP

<?php
namespace App\Filament\Resources\Monitoring\MediaMonitorings\Actions;
use App\Filament\Support\CheerfulNotification;
use App\Models\Theme;
use App\Services\NewsCrawlerService;
use Filament\Actions\Action;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Support\Enums\Width;
use Filament\Support\Icons\Heroicon;
class CrawlNewsAction extends Action
{
protected function setUp(): void
{
parent::setUp();
$this->label('Crawl Berita')
->icon(Heroicon::MagnifyingGlass)
->color('info')
->schema([
TextInput::make('keyword')
->label('Kata Kunci')
->placeholder('Pendidikan, UMKM, Pariwisata')
->autocomplete(false)
->autofocus()
->required()
->helperText('Jika kata kunci nya lebih dari 1, pisahkan dengan koma.'),
Select::make('theme_id')
->label('Tema')
->required()
->options(Theme::active()->pluck('name', 'id'))
->searchable()
->multiple(),
TextInput::make('limit')
->label('Jumlah Berita')
->placeholder(10)
->numeric()
->required()
->default(10)
->autocomplete(false),
])
->action(function (array $data, NewsCrawlerService $service): void {
$count = $service->crawlFromGoogleNews($data['keyword'], $data['limit'], (array) ($data['theme_id'] ?? []));
if ($count > 0) {
CheerfulNotification::success(
'Crawl Berhasil! 🕸️🚀',
"Mantap! Ada {$count} berita baru nih tentang '{$data['keyword']}' di Purwakarta. Databasenya makin kaya! 😎"
)->send();
} else {
CheerfulNotification::info(
'Belum Ada Berita Baru 🔍',
"Hmm, sepertinya belum ada update berita baru untuk '{$data['keyword']}'. Coba lagi nanti ya! 😉"
)->send();
}
})
->modalWidth(Width::Large);
}
}