8f324b7b8e
- Onboarding + Settings: Forms\Components\Select for currency (MDL/EUR/USD/RON/UAH/RUB) instead of TextInput - TenantPanel: brandName/brandLogo/favicon as closures resolving from tenant. Logo now visible on login page, topbar, sidebar (Filament v5 brandLogo handles all 3 spots automatically) - Favicon falls back to logo if favicon not separately uploaded - Removed manual SIDEBAR_LOGO_BEFORE injection (replaced by brandLogo) - Removed manual <link rel=icon> in HEAD_END (replaced by ->favicon)
205 lines
9.9 KiB
PHP
205 lines
9.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Tenant\Pages;
|
|
|
|
use App\Tenancy\TenantManager;
|
|
use Filament\Forms;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
use Filament\Schemas;
|
|
use Filament\Schemas\Schema;
|
|
|
|
class Settings extends Page
|
|
{
|
|
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-cog-6-tooth';
|
|
|
|
protected static ?string $navigationLabel = 'Setări';
|
|
|
|
protected static string|\UnitEnum|null $navigationGroup = 'Admin';
|
|
|
|
protected static ?int $navigationSort = 90;
|
|
|
|
protected static ?string $title = 'Setări companie';
|
|
|
|
protected string $view = 'filament.tenant.pages.settings';
|
|
|
|
public ?array $data = [];
|
|
|
|
public function mount(): void
|
|
{
|
|
$company = app(TenantManager::class)->current();
|
|
if (! $company) {
|
|
return;
|
|
}
|
|
$settings = (array) ($company->settings ?? []);
|
|
|
|
// Filament v5: fill via $this->form->fill() (initializes the schema state).
|
|
$notify = (array) ($settings['notify'] ?? []);
|
|
$this->form->fill([
|
|
'display_name' => $company->display_name ?? $company->name,
|
|
'city' => $company->city,
|
|
'phone' => $company->phone,
|
|
'email' => $company->email,
|
|
'currency' => $settings['currency'] ?? 'MDL',
|
|
'language' => $settings['language'] ?? 'ro',
|
|
'theme_color' => $settings['theme_color'] ?? '#3B82F6',
|
|
'labor_rate' => $settings['labor_rate'] ?? 400,
|
|
'services' => isset($settings['services']) ? implode(', ', (array) $settings['services']) : '',
|
|
'cars' => isset($settings['cars']) ? implode(', ', (array) $settings['cars']) : '',
|
|
'notify_wo_ready' => $notify['wo_ready'] ?? true,
|
|
'notify_payment' => $notify['payment'] ?? true,
|
|
'notify_appointment' => $notify['appointment'] ?? true,
|
|
'notify_reminder' => $notify['reminder'] ?? true,
|
|
'ai_default_provider' => $settings['ai']['default_provider'] ?? 'claude',
|
|
'ai_claude_key' => $settings['ai']['claude_key'] ?? null,
|
|
'ai_gpt_key' => $settings['ai']['gpt_key'] ?? null,
|
|
'ai_gemini_key' => $settings['ai']['gemini_key'] ?? null,
|
|
]);
|
|
}
|
|
|
|
public function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
Schemas\Components\Section::make('Brand & contact')
|
|
->columns(2)
|
|
->schema([
|
|
Forms\Components\TextInput::make('display_name')->label('Denumire afișată')->maxLength(120),
|
|
Forms\Components\TextInput::make('city')->label('Oraș')->maxLength(60),
|
|
Forms\Components\TextInput::make('phone')->label('Telefon')->tel()->maxLength(40),
|
|
Forms\Components\TextInput::make('email')->email()->maxLength(120),
|
|
]),
|
|
Schemas\Components\Section::make('Localizare & monedă')
|
|
->columns(3)
|
|
->schema([
|
|
Forms\Components\Select::make('language')
|
|
->label('Limbă default')
|
|
->options(['ro' => 'Română', 'ru' => 'Русский', 'en' => 'English'])
|
|
->required(),
|
|
Forms\Components\Select::make('currency')
|
|
->label('Monedă')
|
|
->options([
|
|
'MDL' => 'MDL — Leu moldovenesc',
|
|
'EUR' => 'EUR — Euro',
|
|
'USD' => 'USD — US Dollar',
|
|
'RON' => 'RON — Leu românesc',
|
|
'UAH' => 'UAH — Hryvnia',
|
|
'RUB' => 'RUB — Rublă',
|
|
])
|
|
->required()
|
|
->searchable(),
|
|
Forms\Components\ColorPicker::make('theme_color')->label('Culoare brand'),
|
|
]),
|
|
Schemas\Components\Section::make('Servicii & tarif')
|
|
->columns(2)
|
|
->schema([
|
|
Forms\Components\TextInput::make('labor_rate')->label('Tarif normo-oră')->numeric()->required(),
|
|
]),
|
|
Schemas\Components\Section::make('Liste configurabile')
|
|
->columns(1)
|
|
->schema([
|
|
Forms\Components\Textarea::make('services')
|
|
->label('Servicii oferite (separate prin virgulă)')
|
|
->rows(2),
|
|
Forms\Components\Textarea::make('cars')
|
|
->label('Mărci auto suportate (separate prin virgulă)')
|
|
->rows(2),
|
|
]),
|
|
Schemas\Components\Section::make('Logo & favicon')
|
|
->columns(2)
|
|
->schema([
|
|
Forms\Components\FileUpload::make('logo')
|
|
->label('Logo')
|
|
->image()
|
|
->imageEditor()
|
|
->disk('public')
|
|
->directory('tmp-uploads')
|
|
->visibility('public')
|
|
->maxSize(2048)
|
|
->helperText('PNG/SVG, max 2 MB. Apare în sidebar.'),
|
|
Forms\Components\FileUpload::make('favicon')
|
|
->label('Favicon')
|
|
->image()
|
|
->disk('public')
|
|
->directory('tmp-uploads')
|
|
->visibility('public')
|
|
->maxSize(512)
|
|
->helperText('PNG/ICO, max 512 KB.'),
|
|
]),
|
|
Schemas\Components\Section::make('Notificări email')
|
|
->description('Activează / dezactivează emailurile auto către clienți.')
|
|
->columns(2)
|
|
->schema([
|
|
Forms\Components\Toggle::make('notify_wo_ready')->label('Mașina e gata de ridicat')->default(true),
|
|
Forms\Components\Toggle::make('notify_payment')->label('Confirmare plată primită')->default(true),
|
|
Forms\Components\Toggle::make('notify_appointment')->label('Programare confirmată')->default(true),
|
|
Forms\Components\Toggle::make('notify_reminder')->label('Reminder ITP / revizie')->default(true),
|
|
]),
|
|
Schemas\Components\Section::make('Asistent AI')
|
|
->description('Adaugă chei API ca să activezi asistentul. Cheile rămân la voi — nu sunt partajate.')
|
|
->columns(2)
|
|
->schema([
|
|
Forms\Components\Select::make('ai_default_provider')
|
|
->label('Provider implicit')
|
|
->options(['claude' => 'Claude (Anthropic)', 'gpt' => 'ChatGPT (OpenAI)', 'gemini' => 'Gemini (Google)'])
|
|
->default('claude'),
|
|
Forms\Components\TextInput::make('ai_claude_key')->label('Claude API Key')->password()->revealable()->placeholder('sk-ant-...'),
|
|
Forms\Components\TextInput::make('ai_gpt_key')->label('OpenAI API Key')->password()->revealable()->placeholder('sk-proj-...'),
|
|
Forms\Components\TextInput::make('ai_gemini_key')->label('Gemini API Key')->password()->revealable(),
|
|
]),
|
|
])
|
|
->statePath('data');
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
$data = $this->form->getState();
|
|
$company = app(TenantManager::class)->current();
|
|
if (! $company) {
|
|
Notification::make()->title('Tenant not resolved')->danger()->send();
|
|
return;
|
|
}
|
|
|
|
$company->update([
|
|
'display_name' => $data['display_name'] ?? null,
|
|
'city' => $data['city'] ?? null,
|
|
'phone' => $data['phone'] ?? null,
|
|
'email' => $data['email'] ?? null,
|
|
'settings' => array_merge((array) $company->settings, [
|
|
'language' => $data['language'] ?? 'ro',
|
|
'currency' => $data['currency'] ?? 'MDL',
|
|
'theme_color' => $data['theme_color'] ?? '#3B82F6',
|
|
'labor_rate' => (float) ($data['labor_rate'] ?? 400),
|
|
'services' => array_values(array_filter(array_map('trim', explode(',', (string) ($data['services'] ?? ''))))),
|
|
'cars' => array_values(array_filter(array_map('trim', explode(',', (string) ($data['cars'] ?? ''))))),
|
|
'notify' => [
|
|
'wo_ready' => (bool) ($data['notify_wo_ready'] ?? true),
|
|
'payment' => (bool) ($data['notify_payment'] ?? true),
|
|
'appointment' => (bool) ($data['notify_appointment'] ?? true),
|
|
'reminder' => (bool) ($data['notify_reminder'] ?? true),
|
|
],
|
|
'ai' => [
|
|
'default_provider' => $data['ai_default_provider'] ?? 'claude',
|
|
'claude_key' => $data['ai_claude_key'] ?? null,
|
|
'gpt_key' => $data['ai_gpt_key'] ?? null,
|
|
'gemini_key' => $data['ai_gemini_key'] ?? null,
|
|
],
|
|
]),
|
|
]);
|
|
|
|
// Logo + favicon → Spatie Media Library
|
|
foreach (['logo', 'favicon'] as $col) {
|
|
$path = $data[$col] ?? null;
|
|
if (! $path) continue;
|
|
$abs = \Illuminate\Support\Facades\Storage::disk('public')->path($path);
|
|
if (file_exists($abs)) {
|
|
$company->clearMediaCollection($col);
|
|
$company->addMedia($abs)->preservingOriginal()->toMediaCollection($col);
|
|
@unlink($abs);
|
|
}
|
|
}
|
|
|
|
Notification::make()->title('Setări salvate')->success()->send();
|
|
}
|
|
}
|