- 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.
130 lines
4.7 KiB
PHP
130 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Manage\Cooperations\RelationManagers;
|
|
|
|
use App\Enums\ApprovalStatus;
|
|
use App\Filament\Resources\Manage\Cooperations\Actions\Proposal\AcceptAction;
|
|
use App\Filament\Resources\Manage\Cooperations\Actions\Proposal\RejectAction;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Infolists\Components\TextEntry;
|
|
use Filament\Resources\RelationManagers\RelationManager;
|
|
use Filament\Schemas\Components\Grid;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry;
|
|
|
|
class CooperationProposalRelationManager extends RelationManager
|
|
{
|
|
protected static string $relationship = 'proposals';
|
|
|
|
protected static ?string $title = 'Proposal';
|
|
|
|
public static function getBadge(Model $ownerRecord, string $pageClass): ?string
|
|
{
|
|
return $ownerRecord->proposals()->count();
|
|
}
|
|
|
|
public function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->recordTitleAttribute('description')
|
|
->columns([
|
|
TextColumn::make('partnerMedia.name')
|
|
->label('Media')
|
|
->searchable()
|
|
->visible(! auth()->user()->hasRole('Perusahaan')),
|
|
|
|
TextColumn::make('e_catalog')
|
|
->label('E-Catalog')
|
|
->url(fn ($record) => $record->e_catalog)
|
|
->openUrlInNewTab()
|
|
->color('primary'),
|
|
|
|
TextColumn::make('description')
|
|
->label('Deskripsi'),
|
|
|
|
TextColumn::make('status')
|
|
->label('Status')
|
|
->badge(),
|
|
|
|
TextColumn::make('submitted_at')
|
|
->label('Diajukan')
|
|
->dateTime('l, d F Y H:i:s')
|
|
->sortable(),
|
|
|
|
TextColumn::make('responded_at')
|
|
->label('Ditanggapi')
|
|
->dateTime('l, d F Y H:i:s')
|
|
->sortable(),
|
|
|
|
TextColumn::make('rejectionReasons.reason')
|
|
->label('Alasan Penolakan')
|
|
->searchable(),
|
|
])
|
|
->filters([])
|
|
->headerActions([])
|
|
->recordActions([
|
|
ViewAction::make(),
|
|
AcceptAction::make('accept'),
|
|
RejectAction::make('reject'),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public function infolist(Schema $infolist): Schema
|
|
{
|
|
return $infolist
|
|
->components([
|
|
Grid::make(2)
|
|
->schema([
|
|
TextEntry::make('partnerMedia.name')
|
|
->label('Media')
|
|
->visible(! auth()->user()->hasRole('Perusahaan')),
|
|
|
|
TextEntry::make('status')
|
|
->label('Status')
|
|
->badge(),
|
|
|
|
TextEntry::make('submitted_at')
|
|
->label('Diajukan')
|
|
->dateTime('l, d F Y H:i:s'),
|
|
|
|
TextEntry::make('responded_at')
|
|
->label('Ditanggapi')
|
|
->dateTime('l, d F Y H:i:s'),
|
|
]),
|
|
|
|
TextEntry::make('e_catalog')
|
|
->label('E-Catalog')
|
|
->url(fn ($record) => $record->e_catalog)
|
|
->openUrlInNewTab()
|
|
->color('primary')
|
|
->visible(fn ($record) => $record->e_catalog),
|
|
|
|
TextEntry::make('description')
|
|
->label('Deskripsi')
|
|
->columnSpanFull(),
|
|
|
|
PdfViewerEntry::make('proposal_attachment')
|
|
->label('Lampiran Proposal')
|
|
->getStateUsing(fn ($record) => optional($record->getMedia('cooperations')->where('custom_properties.doc_type', 'proposal-attachment')->sortByDesc('created_at')->first())->getPathRelativeToRoot())
|
|
->disk(config('filesystems.default')),
|
|
|
|
TextEntry::make('rejectionReasons.reason')
|
|
->label('Alasan Penolakan')
|
|
->listWithLineBreaks()
|
|
->visible(fn ($record) => $record->status === ApprovalStatus::REJECTED && $record->rejectionReasons->isNotEmpty())
|
|
->columnSpanFull(),
|
|
])
|
|
->columns(1);
|
|
}
|
|
}
|