simedkom/app/Filament/Resources/Manage/Cooperations/Pages/EditCooperation.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.2 KiB
PHP

<?php
namespace App\Filament\Resources\Manage\Cooperations\Pages;
use App\Filament\Resources\Manage\Cooperations\CooperationResource;
use App\Filament\Support\CheerfulNotification;
use App\Models\Cooperation;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Facades\Storage;
class EditCooperation extends EditRecord
{
protected static string $resource = CooperationResource::class;
public function mount(int|string $record): void
{
parent::mount($record);
$media = Cooperation::find($record)
->getMedia('cooperations')
->where('custom_properties.doc_type', 'proposal-template')
->sortByDesc('created_at')
->first();
if (! $media) {
return;
}
$this->data['proposal_template'] = [
$media->uuid => $media->getPathRelativeToRoot(),
];
}
protected function getHeaderActions(): array
{
return [
Action::make('back')
->label('Kembali')
->url(ListCooperations::getUrl())
->outlined()
->color('secondary'),
];
}
protected function getSavedNotification(): ?Notification
{
return CheerfulNotification::update();
}
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
protected function afterSave(): 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',
'doc_type' => 'proposal-template',
'date' => now()->toDateString(),
])
->toMediaCollection('cooperations');
}
}