232 lines
8.4 KiB
PHP
232 lines
8.4 KiB
PHP
<?php
|
|
|
|
use App\Mail\TestEmail;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\Validation\Rules\Password;
|
|
use Livewire\Volt\Component;
|
|
|
|
new class extends Component {
|
|
public string $full_name = '';
|
|
public string $email = '';
|
|
public string $current_password = '';
|
|
public string $password = '';
|
|
public string $password_confirmation = '';
|
|
public string $preferred_language = 'ar';
|
|
|
|
public function mount(): void
|
|
{
|
|
$user = auth()->user();
|
|
$this->full_name = $user->full_name;
|
|
$this->email = $user->email;
|
|
$this->preferred_language = $user->preferred_language ?? 'ar';
|
|
}
|
|
|
|
public function updateProfile(): void
|
|
{
|
|
$validated = $this->validate([
|
|
'full_name' => ['required', 'string', 'max:255'],
|
|
'email' => ['required', 'email', 'max:255', Rule::unique(User::class)->ignore(auth()->id())],
|
|
'preferred_language' => ['required', 'in:ar,en'],
|
|
]);
|
|
|
|
auth()->user()->update([
|
|
'full_name' => $this->full_name,
|
|
'email' => $this->email,
|
|
'preferred_language' => $this->preferred_language,
|
|
]);
|
|
|
|
session()->flash('success', __('admin.profile_updated'));
|
|
$this->dispatch('profile-updated');
|
|
}
|
|
|
|
public function updatePassword(): void
|
|
{
|
|
$this->validate([
|
|
'current_password' => ['required', 'current_password'],
|
|
'password' => ['required', 'string', Password::defaults(), 'confirmed'],
|
|
]);
|
|
|
|
auth()->user()->update([
|
|
'password' => Hash::make($this->password),
|
|
]);
|
|
|
|
$this->reset(['current_password', 'password', 'password_confirmation']);
|
|
session()->flash('password_success', __('admin.password_updated'));
|
|
$this->dispatch('password-updated');
|
|
}
|
|
|
|
public function sendTestEmail(): void
|
|
{
|
|
try {
|
|
$locale = auth()->user()->preferred_language ?? 'en';
|
|
Mail::to(auth()->user())->send(new TestEmail($locale));
|
|
session()->flash('email_success', __('admin.test_email_sent'));
|
|
} catch (\Exception $e) {
|
|
session()->flash('email_error', __('admin.test_email_failed'));
|
|
}
|
|
}
|
|
}; ?>
|
|
|
|
<div>
|
|
<div class="mb-6">
|
|
<flux:heading size="xl">{{ __('admin.system_settings') }}</flux:heading>
|
|
<flux:text class="mt-1 text-zinc-500 dark:text-zinc-400">
|
|
{{ __('admin.system_settings_description') }}
|
|
</flux:text>
|
|
</div>
|
|
|
|
<div class="space-y-8">
|
|
{{-- Profile Settings --}}
|
|
<div class="rounded-lg border border-zinc-200 bg-white p-6 dark:border-zinc-700 dark:bg-zinc-800">
|
|
<flux:heading size="lg" class="mb-4">{{ __('admin.profile_settings') }}</flux:heading>
|
|
|
|
@if (session('success'))
|
|
<div class="mb-4">
|
|
<flux:callout variant="success" icon="check-circle">
|
|
{{ session('success') }}
|
|
</flux:callout>
|
|
</div>
|
|
@endif
|
|
|
|
<form wire:submit="updateProfile" class="space-y-4">
|
|
<flux:input
|
|
wire:model="full_name"
|
|
:label="__('admin.admin_name')"
|
|
type="text"
|
|
required
|
|
/>
|
|
|
|
<flux:input
|
|
wire:model="email"
|
|
:label="__('admin.email')"
|
|
type="email"
|
|
required
|
|
/>
|
|
|
|
<flux:select
|
|
wire:model="preferred_language"
|
|
:label="__('admin.preferred_language')"
|
|
>
|
|
<option value="ar">{{ __('admin.arabic') }}</option>
|
|
<option value="en">{{ __('admin.english') }}</option>
|
|
</flux:select>
|
|
|
|
<div class="flex items-center gap-4 pt-2">
|
|
<flux:button variant="primary" type="submit">
|
|
{{ __('admin.save_profile') }}
|
|
</flux:button>
|
|
<x-action-message on="profile-updated">
|
|
{{ __('Saved.') }}
|
|
</x-action-message>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
{{-- Password Settings --}}
|
|
<div class="rounded-lg border border-zinc-200 bg-white p-6 dark:border-zinc-700 dark:bg-zinc-800">
|
|
<flux:heading size="lg" class="mb-4">{{ __('admin.password_settings') }}</flux:heading>
|
|
|
|
@if (session('password_success'))
|
|
<div class="mb-4">
|
|
<flux:callout variant="success" icon="check-circle">
|
|
{{ session('password_success') }}
|
|
</flux:callout>
|
|
</div>
|
|
@endif
|
|
|
|
<form wire:submit="updatePassword" class="space-y-4">
|
|
<flux:input
|
|
wire:model="current_password"
|
|
:label="__('admin.current_password')"
|
|
type="password"
|
|
required
|
|
/>
|
|
|
|
<flux:input
|
|
wire:model="password"
|
|
:label="__('admin.new_password')"
|
|
type="password"
|
|
required
|
|
/>
|
|
|
|
<flux:input
|
|
wire:model="password_confirmation"
|
|
:label="__('admin.confirm_password')"
|
|
type="password"
|
|
required
|
|
/>
|
|
|
|
<div class="flex items-center gap-4 pt-2">
|
|
<flux:button variant="primary" type="submit">
|
|
{{ __('admin.update_password') }}
|
|
</flux:button>
|
|
<x-action-message on="password-updated">
|
|
{{ __('Saved.') }}
|
|
</x-action-message>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
{{-- Email Settings --}}
|
|
<div class="rounded-lg border border-zinc-200 bg-white p-6 dark:border-zinc-700 dark:bg-zinc-800">
|
|
<flux:heading size="lg" class="mb-4">{{ __('admin.email_settings') }}</flux:heading>
|
|
|
|
@if (session('email_success'))
|
|
<div class="mb-4">
|
|
<flux:callout variant="success" icon="check-circle">
|
|
{{ session('email_success') }}
|
|
</flux:callout>
|
|
</div>
|
|
@endif
|
|
|
|
@if (session('email_error'))
|
|
<div class="mb-4">
|
|
<flux:callout variant="danger" icon="exclamation-triangle">
|
|
{{ session('email_error') }}
|
|
</flux:callout>
|
|
</div>
|
|
@endif
|
|
|
|
<div class="space-y-4">
|
|
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
|
<div>
|
|
<flux:text class="text-sm font-medium text-zinc-600 dark:text-zinc-400">
|
|
{{ __('admin.sender_name') }}
|
|
</flux:text>
|
|
<flux:text class="mt-1 font-medium text-zinc-900 dark:text-zinc-100">
|
|
{{ config('mail.from.name') }}
|
|
</flux:text>
|
|
</div>
|
|
<div>
|
|
<flux:text class="text-sm font-medium text-zinc-600 dark:text-zinc-400">
|
|
{{ __('admin.sender_email') }}
|
|
</flux:text>
|
|
<flux:text class="mt-1 font-medium text-zinc-900 dark:text-zinc-100">
|
|
{{ config('mail.from.address') }}
|
|
</flux:text>
|
|
</div>
|
|
</div>
|
|
|
|
<flux:separator />
|
|
|
|
<div>
|
|
<flux:text class="mb-3 text-sm text-zinc-600 dark:text-zinc-400">
|
|
{{ __('admin.test_email_description') }}
|
|
</flux:text>
|
|
<flux:button wire:click="sendTestEmail" wire:loading.attr="disabled">
|
|
<span wire:loading.remove wire:target="sendTestEmail">
|
|
{{ __('admin.send_test_email') }}
|
|
</span>
|
|
<span wire:loading wire:target="sendTestEmail">
|
|
{{ __('admin.sending') }}
|
|
</span>
|
|
</flux:button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|