Add all files
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace Paymenter\Extensions\Others\ComplianceTools\Admin\Pages;
|
||||
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Group;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Paymenter\Extensions\Others\ComplianceTools\Services\SupportPinService;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Admin\Resources\UserResource;
|
||||
|
||||
class ValidateSupportPin extends Page implements HasForms
|
||||
{
|
||||
use InteractsWithForms;
|
||||
|
||||
public ?string $pin = null; // <-- add this
|
||||
|
||||
public ?array $validated = null;
|
||||
public ?string $errorMessage = null;
|
||||
|
||||
protected static ?string $title = 'Validate Support PIN';
|
||||
protected static ?string $navigationIcon = 'ri-customer-service-2-line';
|
||||
protected static ?string $activeNavigationIcon = 'ri-customer-service-2-fill';
|
||||
protected static ?string $navigationGroup = 'Compliance';
|
||||
protected static ?string $slug = 'compliance/validate-pin';
|
||||
protected static ?string $navigationLabel = 'Validate Support PIN';
|
||||
protected static string $view = 'compliance-tools::admin.validate-support-pin';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->form->fill([
|
||||
'pin' => '',
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getFormSchema(): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('pin')
|
||||
->label('Support PIN')
|
||||
->required()
|
||||
->minLength(4)
|
||||
->maxLength(16)
|
||||
->placeholder('Enter PIN shared by client')
|
||||
->autocomplete('off'),
|
||||
];
|
||||
}
|
||||
|
||||
public function validatePin(SupportPinService $service): void
|
||||
{
|
||||
$pin = $this->pin; // <-- access the bound property
|
||||
$this->validated = null;
|
||||
$this->errorMessage = null;
|
||||
|
||||
$record = $service->validate($pin);
|
||||
|
||||
if (!$record) {
|
||||
$this->errorMessage = 'No active PIN matched the value provided.';
|
||||
Notification::make()
|
||||
->title('Support PIN not found or expired')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->validated = [
|
||||
'user_name' => $record->user?->name,
|
||||
'user_email' => $record->user?->email,
|
||||
'expires_at' => $record->expires_at?->toDayDateTimeString(),
|
||||
'last_validated_at' => $record->last_validated_at?->toDayDateTimeString(),
|
||||
'user_id' => $record->user?->getKey(),
|
||||
'user_url' => $record->user ? UserResource::getUrl('edit', ['record' => $record->user]) : null,
|
||||
];
|
||||
|
||||
Notification::make()
|
||||
->title('Support PIN validated')
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
$user = Auth::user();
|
||||
return $user && $user->hasPermission('admin.compliance.validate_pin');
|
||||
}
|
||||
|
||||
// Required to avoid Filament 2 breadcrumb error
|
||||
public function getBreadcrumbs(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user