diff --git a/app/Filament/Pages/Profile.php b/app/Filament/Pages/Profile.php new file mode 100644 index 0000000..ccd3889 --- /dev/null +++ b/app/Filament/Pages/Profile.php @@ -0,0 +1,112 @@ +components([ + Section::make('Akun') + ->schema([ + TextInput::make('name') + ->label('Nama') + ->placeholder('John Doe') + ->autocomplete(false) + ->autofocus() + ->required() + ->maxLength(100), + + TextInput::make('email') + ->label('Alamat Surel') + ->placeholder('johndoe@puskesmas.com') + ->autocomplete(false) + ->required() + ->maxLength(254) + ->unique(ignoreRecord: true) + ->email() + ->live(), + + TextInput::make('username') + ->label('Nama Pengguna') + ->placeholder('johndoe') + ->autocomplete(false) + ->required() + ->minLength(5) + ->maxLength(20) + ->regex('/^[a-zA-Z0-9_.-]+$/') + ->unique(ignoreRecord: true), + ]), + + Section::make('Kata Sandi') + ->schema([ + TextInput::make('new_password') + ->label(__('filament-panels::auth/pages/edit-profile.form.password.label')) + ->validationAttribute(__('filament-panels::auth/pages/edit-profile.form.password.validation_attribute')) + ->password() + ->revealable(filament()->arePasswordsRevealable()) + ->rule(Password::default()) + ->showAllValidationMessages() + ->autocomplete('new-password') + ->dehydrated(fn ($state): bool => filled($state)) + ->dehydrateStateUsing(fn ($state): string => Hash::make($state)) + ->live(debounce: 500) + ->same('passwordConfirmation') + ->placeholder('********'), + + TextInput::make('passwordConfirmation') + ->label(__('filament-panels::auth/pages/edit-profile.form.password_confirmation.label')) + ->validationAttribute(__('filament-panels::auth/pages/edit-profile.form.password_confirmation.validation_attribute')) + ->password() + ->autocomplete('new-password') + ->revealable(filament()->arePasswordsRevealable()) + ->required() + ->visible(fn (Get $get): bool => filled($get('new_password'))) + ->dehydrated(false) + ->placeholder('********'), + + TextInput::make('currentPassword') + ->label(__('filament-panels::auth/pages/edit-profile.form.current_password.label')) + ->validationAttribute(__('filament-panels::auth/pages/edit-profile.form.current_password.validation_attribute')) + ->belowContent(__('filament-panels::auth/pages/edit-profile.form.current_password.below_content')) + ->password() + ->autocomplete('current-password') + ->currentPassword(guard: Filament::getAuthGuard()) + ->revealable(filament()->arePasswordsRevealable()) + ->required() + ->visible(fn (Get $get): bool => filled($get('new_password')) || ($get('email') !== $this->getUser()->getAttributeValue('email'))) + ->dehydrated(false) + ->placeholder('********'), + ]), + ]); + } + + protected function handleRecordUpdate(Model $record, array $data): Model + { + $shouldLogout = false; + if (isset($data['new_password'])) { + $data['password'] = $data['new_password']; + unset($data['new_password']); + $shouldLogout = true; + } + + $record->update($data); + + if ($shouldLogout) { + auth()->logout(); + } + + return $record; + } +} diff --git a/app/Providers/Filament/AdminPanelProvider.php b/app/Providers/Filament/AdminPanelProvider.php index b60f62b..febdf8a 100644 --- a/app/Providers/Filament/AdminPanelProvider.php +++ b/app/Providers/Filament/AdminPanelProvider.php @@ -3,6 +3,7 @@ namespace App\Providers\Filament; use App\Filament\Pages\Auth\Login; +use App\Filament\Pages\Profile; use BezhanSalleh\FilamentShield\FilamentShieldPlugin; use DiogoGPinto\AuthUIEnhancer\AuthUIEnhancerPlugin; use Filament\Http\Middleware\Authenticate; @@ -31,6 +32,7 @@ public function panel(Panel $panel): Panel ->path('admin') ->viteTheme('resources/css/filament/admin/theme.css') ->login(Login::class) + ->profile(Profile::class) ->colors([ 'primary' => Color::Violet, ])