feat: Implement a custom Filament profile page for user details and password management, and integrate it into the dashboard panel.
This commit is contained in:
parent
c221864616
commit
af7bf05b91
121
app/Filament/Pages/Auth/Profile.php
Normal file
121
app/Filament/Pages/Auth/Profile.php
Normal file
@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages\Auth;
|
||||
|
||||
use App\Filament\Support\CheerfulNotification;
|
||||
use Filament\Auth\Pages\EditProfile;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules\Password;
|
||||
|
||||
class Profile extends EditProfile
|
||||
{
|
||||
public function getMaxContentWidth(): Width
|
||||
{
|
||||
return Width::FourExtraLarge;
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make('Informasi Profil 👤')
|
||||
->description('Kelola detail profil Anda seperti nama, alamat surel, dan nama pengguna.')
|
||||
->icon('heroicon-m-user-circle')
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('Nama Lengkap')
|
||||
->placeholder('Masukkan nama lengkap Anda')
|
||||
->required()
|
||||
->maxLength(100)
|
||||
->prefixIcon('heroicon-m-user'),
|
||||
|
||||
Grid::make(2)
|
||||
->schema([
|
||||
TextInput::make('email')
|
||||
->label('Alamat Surel')
|
||||
->placeholder('contoh@email.com')
|
||||
->autocomplete(false)
|
||||
->required()
|
||||
->maxLength(254)
|
||||
->unique(ignoreRecord: true)
|
||||
->email()
|
||||
->prefixIcon('heroicon-m-envelope')
|
||||
->live(),
|
||||
|
||||
TextInput::make('username')
|
||||
->label('Nama Pengguna')
|
||||
->placeholder('nama_pengguna')
|
||||
->autocomplete(false)
|
||||
->required()
|
||||
->minLength(5)
|
||||
->maxLength(20)
|
||||
->regex('/^[a-zA-Z0-9_.-]+$/')
|
||||
->unique(ignoreRecord: true)
|
||||
->prefixIcon('heroicon-m-at-symbol'),
|
||||
]),
|
||||
]),
|
||||
|
||||
Section::make('Keamanan Akun 🔒')
|
||||
->description('Pastikan akun Anda menggunakan kata sandi yang panjang dan aman.')
|
||||
->icon('heroicon-m-finger-print')
|
||||
->schema([
|
||||
Grid::make(2)
|
||||
->schema([
|
||||
TextInput::make('password')
|
||||
->label(__('filament-panels::auth/pages/register.form.password.label'))
|
||||
->placeholder('********')
|
||||
->password()
|
||||
->revealable(filament()->arePasswordsRevealable())
|
||||
->required(fn (Get $get) => filled($get('password')) || filled($get('passwordConfirmation')))
|
||||
->rule(Password::default())
|
||||
->showAllValidationMessages()
|
||||
->dehydrated(fn ($state) => filled($state))
|
||||
->dehydrateStateUsing(fn ($state) => Hash::make($state))
|
||||
->same('passwordConfirmation')
|
||||
->validationAttribute(__('filament-panels::auth/pages/register.form.password.validation_attribute'))
|
||||
->prefixIcon('heroicon-m-lock-closed'),
|
||||
|
||||
TextInput::make('passwordConfirmation')
|
||||
->label(__('filament-panels::auth/pages/register.form.password_confirmation.label'))
|
||||
->placeholder('********')
|
||||
->password()
|
||||
->revealable(filament()->arePasswordsRevealable())
|
||||
->required(fn (Get $get) => filled($get('password')) || filled($get('passwordConfirmation')))
|
||||
->dehydrated(false)
|
||||
->prefixIcon('heroicon-m-shield-check'),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
{
|
||||
$passwordChanged = filled($data['password'] ?? null);
|
||||
|
||||
$record->update($data);
|
||||
|
||||
CheerfulNotification::success(
|
||||
'Profil Berhasil Diperbarui ✅',
|
||||
'Data profil Anda telah berhasil disimpan dan diperbarui di dalam sistem.'
|
||||
)->send();
|
||||
|
||||
if ($passwordChanged) {
|
||||
auth()->logout();
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
protected function getSavedNotification(): ?Notification
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@
|
||||
use AchyutN\FilamentLogViewer\FilamentLogViewer;
|
||||
use App\Filament\Pages\Auth\EmailVerification;
|
||||
use App\Filament\Pages\Auth\Login;
|
||||
use App\Filament\Pages\Auth\Profile;
|
||||
use App\Filament\Pages\Auth\Registration;
|
||||
use App\Filament\Pages\Dashboard;
|
||||
use App\Settings\GeneralSettings;
|
||||
@ -56,6 +57,7 @@ public function panel(Panel $panel): Panel
|
||||
->brandLogo(fn () => Storage::disk('public')->url($generalSettings->site_logo))
|
||||
->favicon(fn () => Storage::disk('public')->url($generalSettings->site_icon))
|
||||
->login(Login::class)
|
||||
->profile(Profile::class)
|
||||
->registration(Registration::class)
|
||||
->emailVerification(EmailVerification::class)
|
||||
->colors([
|
||||
|
||||
Loading…
Reference in New Issue
Block a user