simedkom/app/Filament/Resources/Manage/Cooperations/Pages/CreateCooperation.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

85 lines
2.7 KiB
PHP

<?php
namespace App\Filament\Resources\Manage\Cooperations\Pages;
use App\Filament\Resources\Manage\Cooperations\CooperationResource;
use App\Filament\Support\CheerfulNotification;
use App\Notifications\BroadcastNotification;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Facades\Storage;
class CreateCooperation extends CreateRecord
{
protected static string $resource = CooperationResource::class;
protected static ?string $title = 'Tambah Kerja Sama';
protected function getHeaderActions(): array
{
return [
Action::make('back')
->label('Kembali')
->url(ListCooperations::getUrl())
->outlined()
->color('secondary'),
];
}
protected function getCreatedNotification(): ?Notification
{
return CheerfulNotification::create();
}
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
protected function afterCreate(): void
{
$record = $this->getRecord();
$data = $this->data;
if (empty($data['proposal_template'])) {
return;
}
$filePath = collect($data['proposal_template'])->first();
$fullPath = Storage::disk(config('filesystems.default'))->path($filePath);
if (! file_exists($fullPath)) {
return;
}
$record
->addMediaFromDisk($filePath, config('filesystems.default'))
->preservingOriginal()
->withCustomProperties([
'feature' => 'cooperations',
'date' => now()->toDateString(),
'doc_type' => 'proposal-template',
])
->toMediaCollection('cooperations');
// Notify selected partners
$record->load('partnerMedia.company.user');
$record->partnerMedia->each(function ($media) use ($record) {
$partnerUser = $media->company?->user;
if ($partnerUser) {
$partnerUser->notify(new BroadcastNotification([
'title' => 'Ada Penawaran Kerja Sama Baru! 🤝✨',
'body' => "Halo! Admin baru saja menawarkan kerja sama \"{$record->title}\" untuk media {$media->name}. Yuk, cek detailnya dan berikan tanggapanmu! 😊",
'action' => [
Action::make('view')
->label('Lihat')
->url(CooperationResource::getUrl('view', ['record' => $record->id])),
],
]));
}
});
}
}