Add frontend for application settings feature

This commit is contained in:
brufdev
2025-07-12 11:30:47 +01:00
parent 0befa9ebd6
commit f62cc1205e
6 changed files with 137 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace App\Livewire\Forms;
use App\Models\Setting;
use Livewire\Attributes\Validate;
use Livewire\Form;
final class SettingForm extends Form
{
#[Validate('boolean')]
public bool $registration;
#[Validate('boolean')]
public bool $auto_update_check;
public function setSetting(Setting $setting): void
{
$this->registration = $setting->registration;
$this->auto_update_check = $setting->auto_update_check;
}
public function update(): void
{
$this->validate();
$setting = app(Setting::class);
$setting->registration = $this->registration;
$setting->auto_update_check = $this->auto_update_check;
$setting->save();
}
}
+48
View File
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace App\Livewire\Modals;
use App\Livewire\Forms\SettingForm;
use App\Models\Setting;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\On;
use Livewire\Component;
final class Settings extends Component
{
use Modal;
public SettingForm $form;
public function mount(Setting $setting): void
{
$this->authorize('update', $setting);
$this->form->setSetting($setting);
}
#[On('open-modal')]
public function open(): void
{
$setting = app(Setting::class);
$this->authorize('update', $setting);
$this->openModal();
}
public function edit(): void
{
$setting = app(Setting::class);
$this->authorize('update', $setting);
$this->form->update();
$this->closeModal();
$this->dispatch('toast', message: __('Settings updated'), type: 'success');
}
public function render(): Factory|View
{
return view('livewire.modals.settings');
}
}
+18
View File
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace App\Policies;
use App\Models\User;
final readonly class SettingPolicy
{
/**
* Determine whether the user can update the model.
*/
public function update(User $user): bool
{
return $user->isAdmin();
}
}
@@ -0,0 +1,6 @@
<svg {{ $attributes }} fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path
d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z" />
<circle cx="12" cy="12" r="3" />
</svg>

After

Width:  |  Height:  |  Size: 816 B

@@ -69,6 +69,19 @@
<x-menu.itemDivider></x-menu.itemDivider>
@if (auth()->user()->isAdmin())
<x-menu.close>
<x-menu.item @click="$wire.dispatchTo('modals.settings', 'open-modal')">
<x-icons.cog6Tooth class="w-4 h-4" />
{{ __('Settings') }}
</x-menu.item>
<livewire:modals.settings />
</x-menu.close>
<x-menu.itemDivider></x-menu.itemDivider>
@endif
<x-modal>
<x-menu.close>
<x-menu.item @click="modalOpen = true">
@@ -0,0 +1,18 @@
<x-modal wire:model="show">
<x-modal.panel title="{{ __('Settings') }}">
<x-form wire:submit.prevent="edit" class="flex flex-col gap-6">
<x-form.checkboxToggle
name="form.registration"
label="{{ __('Registration') }}"
/>
<x-form.checkboxToggle
name="form.auto_update_check"
label="{{ __('Automatic update check') }}"
/>
<div class="flex justify-end">
<x-form.submit label="{{ __('Save') }}" />
</div>
</x-form>
</x-modal.panel>
</x-modal>