simedkom/app/Filament/Resources/Manage/Cooperations/Pages/CreateCooperation.php
Yoga Pangestu ab318a030b feat(notification): enhance user notifications for cooperation and verification processes
- Added detailed notifications for users and admins upon acceptance, rejection, and submission of proposals, verifications, and reports.
- Improved user experience with personalized messages and actionable links in notifications.
- Refactored notification logic across various actions to ensure consistent messaging and clarity.
- Introduced new notification titles and bodies to better reflect the status of actions taken.
2026-01-13 15:53:07 +07:00

78 lines
2.4 KiB
PHP

<?php
namespace App\Filament\Resources\Manage\Cooperations\Pages;
use App\Filament\Resources\Manage\Cooperations\CooperationResource;
use App\Notifications\BroadcastNotification;
use Filament\Actions\Action;
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 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])),
],
]));
}
});
}
}