- Added comprehensive parameter and return type hinting to closures across various Filament resources, actions, and relation managers to improve type safety and static analysis. - Fixed logic in ReportRelationManager where report count was incorrectly compared, preventing the 'Buat Laporan' button from showing correctly. - Corrected namespaces for RepeatableEntry and TextEntry in ViewCooperation (changed from Filament\Schemas to Filament\Infolists). - Fixed component rendering in JournalistResource form by ensuring sections are correctly returned in the mapping. - Added @var docblocks to resolve lint errors related to auth()->user() and verified query builder return types. - Standardized file retrieval logic in PartnerResource and improved overall code reliability."
148 lines
4.7 KiB
PHP
148 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Enums\VerificationStatus;
|
|
use App\Models\Company;
|
|
use App\Models\VerificationRequest;
|
|
use App\Services\VerificationService;
|
|
use BackedEnum;
|
|
use BezhanSalleh\FilamentShield\Traits\HasPageShield;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\Concerns\InteractsWithActions;
|
|
use Filament\Actions\Contracts\HasActions;
|
|
use Filament\Forms\Concerns\InteractsWithForms;
|
|
use Filament\Forms\Contracts\HasForms;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use UnitEnum;
|
|
|
|
class Verification extends Page implements HasActions, HasForms
|
|
{
|
|
use HasPageShield, InteractsWithActions, InteractsWithForms;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::CheckBadge;
|
|
|
|
protected static ?string $title = 'Verifikasi';
|
|
|
|
protected static ?string $navigationLabel = 'Verifikasi';
|
|
|
|
protected static ?int $navigationSort = 6;
|
|
|
|
protected static string|UnitEnum|null $navigationGroup = 'Kelola';
|
|
|
|
protected static ?string $slug = 'manage/verification';
|
|
|
|
protected string $view = 'filament.pages.verification';
|
|
|
|
public ?Company $company = null;
|
|
|
|
public ?VerificationRequest $verificationRequest = null;
|
|
|
|
protected VerificationService $verificationService;
|
|
|
|
public function boot(): void
|
|
{
|
|
$this->verificationService = app(VerificationService::class);
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->company = auth()->user()->company;
|
|
|
|
// Load unified verification request
|
|
if ($this->company) {
|
|
$this->verificationRequest = $this->company->verificationRequest()
|
|
->with(['reviews.reviewer'])
|
|
->latest()
|
|
->first();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get unified verification progress
|
|
*/
|
|
public function getVerificationProgress(): array
|
|
{
|
|
$progress = $this->verificationService->getVerificationProgress(
|
|
$this->company,
|
|
$this->verificationRequest
|
|
);
|
|
|
|
// Add additional data for view
|
|
$progress['missingDataButtons'] = $this->verificationService->getMissingDataButtons($this->company);
|
|
$progress['alert'] = $this->verificationService->getAlertData($this->verificationRequest);
|
|
$progress['lastSubmittedAt'] = $this->verificationRequest?->updated_at?->format('d M Y, H:i');
|
|
|
|
return $progress;
|
|
}
|
|
|
|
/**
|
|
* Submit unified verification action
|
|
*/
|
|
public function submitVerificationAction(): Action
|
|
{
|
|
$progress = $this->getVerificationProgress();
|
|
|
|
return Action::make('submit_verification')
|
|
->label(fn (): string => $this->verificationRequest && $this->verificationRequest->status === VerificationStatus::NEED_REVISION
|
|
? 'Kirim Ulang'
|
|
: 'Ajukan Verifikasi')
|
|
->icon('heroicon-o-paper-airplane')
|
|
->color('primary')
|
|
->requiresConfirmation()
|
|
->modalHeading('Ajukan Verifikasi Lengkap')
|
|
->modalDescription(function () use ($progress): string {
|
|
if (! $progress['isDataComplete']) {
|
|
return 'Data belum lengkap. Silakan lengkapi terlebih dahulu: '.implode(', ', $progress['missingData']);
|
|
}
|
|
|
|
return 'Apakah Anda yakin ingin mengajukan verifikasi untuk Perusahaan, Media, dan Jurnalis? Pastikan semua data sudah benar dan lengkap.';
|
|
})
|
|
->modalSubmitActionLabel('Ya, Ajukan')
|
|
->visible(fn (): bool => $progress['canSubmit'])
|
|
->disabled(fn (): bool => ! $progress['isDataComplete'])
|
|
->action(function (): void {
|
|
$this->submitVerification();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Handle unified verification submission
|
|
*/
|
|
protected function submitVerification(): void
|
|
{
|
|
$progress = $this->getVerificationProgress();
|
|
|
|
// Validate data completeness
|
|
if (! $progress['isDataComplete']) {
|
|
Notification::make()
|
|
->title('Data Belum Lengkap')
|
|
->body('Silakan lengkapi data terlebih dahulu: '.implode(', ', $progress['missingData']))
|
|
->danger()
|
|
->send();
|
|
|
|
return;
|
|
}
|
|
|
|
$this->verificationRequest = $this->verificationService->submitVerification(
|
|
$this->company,
|
|
$this->verificationRequest
|
|
);
|
|
|
|
Notification::make()
|
|
->title('Berhasil!')
|
|
->body('Verifikasi lengkap (Perusahaan, Media, dan Jurnalis) berhasil diajukan untuk diverifikasi.')
|
|
->success()
|
|
->send();
|
|
}
|
|
|
|
public function getViewData(): array
|
|
{
|
|
return [
|
|
'verificationProgress' => $this->getVerificationProgress(),
|
|
];
|
|
}
|
|
}
|