122 lines
5.2 KiB
PHP
122 lines
5.2 KiB
PHP
<?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;
|
|
}
|
|
}
|