- Refactor custom Filament actions into resource-specific subfolders (Cooperation, Proposal, Report).
- Standardize all action identifiers to snake_case for consistency.
- Move action identifiers directly into ::make('name') calls.
- Remove getDefaultName() from custom action classes to favor explicit naming.
- Update relation managers and resources to use the new namespaced action classes.
- Standardize closure syntax (fn) and string formatting across schemas and actions.
88 lines
3.2 KiB
PHP
88 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Manage\Cooperations\Actions\Cooperation;
|
|
|
|
use App\Enums\ApprovalStatus;
|
|
use App\Enums\CooperationStatus;
|
|
use App\Models\Cooperation;
|
|
use Filament\Actions\Action;
|
|
use Filament\Forms\Components\DatePicker;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Support\Enums\Width;
|
|
use Filament\Support\Icons\Heroicon;
|
|
|
|
class CreateTaskAssignmentAction extends Action
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->label('Buat Penugasan')
|
|
->icon(Heroicon::Plus)
|
|
->color('primary')
|
|
->schema([
|
|
DatePicker::make('start_date')
|
|
->label('Tanggal Mulai')
|
|
->placeholder(fn () => now()->translatedFormat('l, d F Y'))
|
|
->native(false)
|
|
->displayFormat('l, d F Y')
|
|
->locale('id')
|
|
->required(),
|
|
|
|
DatePicker::make('end_date')
|
|
->label('Tanggal Seleisa')
|
|
->placeholder(fn () => now()->addDays(30)->translatedFormat('l, d F Y'))
|
|
->native(false)
|
|
->displayFormat('l, d F Y')
|
|
->required()
|
|
->after('start_date'),
|
|
|
|
TextInput::make('report_amount')
|
|
->label('Jumlah Laporan')
|
|
->placeholder(10)
|
|
->numeric()
|
|
->minValue(1)
|
|
->required(),
|
|
Textarea::make('task_description')
|
|
->label('Deskripsi Tugas')
|
|
->required()
|
|
->rows(4)
|
|
->placeholder('...'),
|
|
])
|
|
->action(function (array $data, Cooperation $record) {
|
|
$taskAssignment = $record->taskAssignments()->create([
|
|
'start_date' => $data['start_date'],
|
|
'end_date' => $data['end_date'],
|
|
'task_description' => $data['task_description'],
|
|
'report_amount' => $data['report_amount'],
|
|
]);
|
|
|
|
$partnerMedias = $record->partnerMedia()
|
|
->wherePivot('status', ApprovalStatus::ACCEPTED)
|
|
->get();
|
|
|
|
foreach ($partnerMedias as $partnerMedia) {
|
|
$taskAssignment->mediaTaskAssignments()->create([
|
|
'partner_media_id' => $partnerMedia->id,
|
|
'status' => ApprovalStatus::PENDING,
|
|
]);
|
|
}
|
|
|
|
Notification::make()
|
|
->title('Penugasan berhasil dibuat')
|
|
->success()
|
|
->send();
|
|
})
|
|
->modalHeading('Buat Penugasan')
|
|
->modalSubmitActionLabel('Simpan')
|
|
->visible(
|
|
fn (Cooperation $record): bool => ! auth()->user()->hasRole('Perusahaan')
|
|
&& ! $record->taskAssignments()->exists()
|
|
&& $record->status === CooperationStatus::ASSIGNMENT
|
|
)
|
|
->modalWidth(Width::Large);
|
|
}
|
|
}
|