Certificate manager built on Laravel 13, Livewire 4, and Flux. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
91 lines
3.2 KiB
PHP
91 lines
3.2 KiB
PHP
<?php
|
|
|
|
use App\Ocr\OcrManager;
|
|
use Flux\Flux;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Validation\Rule;
|
|
use Livewire\Attributes\Title;
|
|
use Livewire\Component;
|
|
|
|
new #[Title('Certificate settings')] class extends Component {
|
|
public int $reminder_months_before = 1;
|
|
|
|
public string $ocr_provider = 'none';
|
|
|
|
public string $ocr_api_key = '';
|
|
|
|
public bool $hasApiKey = false;
|
|
|
|
public function mount(): void
|
|
{
|
|
$user = Auth::user();
|
|
|
|
$this->reminder_months_before = $user->reminder_months_before;
|
|
$this->ocr_provider = $user->ocr_provider;
|
|
$this->hasApiKey = filled($user->ocr_api_key);
|
|
}
|
|
|
|
public function updateSettings(): void
|
|
{
|
|
$validated = $this->validate([
|
|
'reminder_months_before' => ['required', 'integer', 'min:0', 'max:24'],
|
|
'ocr_provider' => ['required', Rule::in(OcrManager::availableProviders())],
|
|
'ocr_api_key' => ['nullable', 'string', 'max:255'],
|
|
]);
|
|
|
|
$user = Auth::user();
|
|
$user->reminder_months_before = $validated['reminder_months_before'];
|
|
$user->ocr_provider = $validated['ocr_provider'];
|
|
|
|
// Only overwrite the stored key when a new one is entered, so the
|
|
// masked field can be left blank to keep the existing key.
|
|
if (filled($validated['ocr_api_key'])) {
|
|
$user->ocr_api_key = $validated['ocr_api_key'];
|
|
} elseif ($validated['ocr_provider'] === 'none') {
|
|
$user->ocr_api_key = null;
|
|
}
|
|
|
|
$user->save();
|
|
|
|
$this->reset('ocr_api_key');
|
|
$this->hasApiKey = filled($user->ocr_api_key);
|
|
|
|
Flux::toast(variant: 'success', text: __('Certificate settings updated.'));
|
|
}
|
|
}; ?>
|
|
|
|
<section class="w-full">
|
|
@include('partials.settings-heading')
|
|
|
|
<x-pages::settings.layout :heading="__('Certificates')" :subheading="__('Configure expiry reminders and document scanning')">
|
|
<form wire:submit="updateSettings" class="my-6 w-full space-y-6">
|
|
<flux:input
|
|
type="number"
|
|
min="0"
|
|
max="24"
|
|
wire:model="reminder_months_before"
|
|
:label="__('Remind me this many months before expiry')"
|
|
/>
|
|
|
|
<flux:select wire:model.live="ocr_provider" :label="__('Document scanning (OCR)')">
|
|
<flux:select.option value="none">{{ __('None (manual entry)') }}</flux:select.option>
|
|
<flux:select.option value="klippa">{{ __('Klippa (EU / NL)') }}</flux:select.option>
|
|
<flux:select.option value="mistral">{{ __('Mistral Pixtral (EU / FR)') }}</flux:select.option>
|
|
</flux:select>
|
|
|
|
@if ($ocr_provider !== 'none')
|
|
<flux:input
|
|
type="password"
|
|
wire:model="ocr_api_key"
|
|
:label="__('API key')"
|
|
:placeholder="$hasApiKey ? __('Leave blank to keep the current key') : __('Enter your API key')"
|
|
viewable
|
|
/>
|
|
@endif
|
|
|
|
<div class="flex items-center gap-4">
|
|
<flux:button type="submit" variant="primary">{{ __('Save') }}</flux:button>
|
|
</div>
|
|
</form>
|
|
</x-pages::settings.layout>
|
|
</section>
|