refactor: enhance user creation form with cheerful notification and improved structure
This commit is contained in:
parent
10d80e8f8c
commit
f2295282e4
@ -3,12 +3,15 @@
|
|||||||
namespace App\Filament\Resources\Master\Users\Schemas;
|
namespace App\Filament\Resources\Master\Users\Schemas;
|
||||||
|
|
||||||
use App\Enums\RoleEnum;
|
use App\Enums\RoleEnum;
|
||||||
|
use App\Filament\Support\CheerfulNotification;
|
||||||
use Filament\Forms\Components\Hidden;
|
use Filament\Forms\Components\Hidden;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Schemas\Components\Grid;
|
use Filament\Schemas\Components\Grid;
|
||||||
|
use Filament\Schemas\Components\Section;
|
||||||
use Filament\Schemas\Schema;
|
use Filament\Schemas\Schema;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Support\HtmlString;
|
||||||
|
|
||||||
class UserForm
|
class UserForm
|
||||||
{
|
{
|
||||||
@ -16,50 +19,58 @@ public static function configure(Schema $schema): Schema
|
|||||||
{
|
{
|
||||||
return $schema
|
return $schema
|
||||||
->components([
|
->components([
|
||||||
TextInput::make('name')
|
Section::make()
|
||||||
->label('Nama Lengkap')
|
->description(function (string $operation) {
|
||||||
->placeholder('John Doe')
|
return $operation === 'create'
|
||||||
->autocomplete(false)
|
? new HtmlString(CheerfulNotification::getByKey('user.create_form_desc'))
|
||||||
->autofocus()
|
: null;
|
||||||
->required()
|
})
|
||||||
->maxLength(100),
|
|
||||||
|
|
||||||
Grid::make(1)
|
|
||||||
->schema([
|
->schema([
|
||||||
TextInput::make('email')
|
TextInput::make('name')
|
||||||
->label('Alamat Surel')
|
->label('Nama Lengkap')
|
||||||
->placeholder('johndoe@example.com')
|
->placeholder('John Doe')
|
||||||
->autocomplete(false)
|
->autocomplete(false)
|
||||||
|
->autofocus()
|
||||||
->required()
|
->required()
|
||||||
->maxLength(254)
|
->maxLength(100),
|
||||||
->email()
|
|
||||||
->unique(ignoreRecord: true)
|
|
||||||
->prefixIcon('heroicon-o-envelope'),
|
|
||||||
|
|
||||||
TextInput::make('username')
|
Grid::make(1)
|
||||||
->label('Nama Pengguna')
|
->schema([
|
||||||
->placeholder('johndoe')
|
TextInput::make('email')
|
||||||
->autocomplete(false)
|
->label('Alamat Surel')
|
||||||
->required()
|
->placeholder('johndoe@example.com')
|
||||||
->minLength(5)
|
->autocomplete(false)
|
||||||
->maxLength(20)
|
->required()
|
||||||
->regex('/^[a-zA-Z0-9_.-]+$/')
|
->maxLength(254)
|
||||||
->unique(ignoreRecord: true)
|
->email()
|
||||||
->prefixIcon('heroicon-o-at-symbol'),
|
->unique(ignoreRecord: true)
|
||||||
|
->prefixIcon('heroicon-o-envelope'),
|
||||||
|
|
||||||
Select::make('roles')
|
TextInput::make('username')
|
||||||
->label('Peran')
|
->label('Nama Pengguna')
|
||||||
->required()
|
->placeholder('johndoe')
|
||||||
->relationship('roles', 'name', function (Builder $query): Builder {
|
->autocomplete(false)
|
||||||
return $query->whereNotIn('name', [RoleEnum::DEVELOPER, RoleEnum::PERUSAHAAN]);
|
->required()
|
||||||
})
|
->minLength(5)
|
||||||
->multiple()
|
->maxLength(20)
|
||||||
->preload()
|
->regex('/^[a-zA-Z0-9_.-]+$/')
|
||||||
->searchable(),
|
->unique(ignoreRecord: true)
|
||||||
|
->prefixIcon('heroicon-o-at-symbol'),
|
||||||
|
|
||||||
Hidden::make('password')
|
Select::make('roles')
|
||||||
->default(fn (): string => config('auth.password_default'))
|
->label('Peran')
|
||||||
->visibleOn('create'),
|
->required()
|
||||||
|
->relationship('roles', 'name', function (Builder $query): Builder {
|
||||||
|
return $query->whereNotIn('name', [RoleEnum::DEVELOPER, RoleEnum::PERUSAHAAN]);
|
||||||
|
})
|
||||||
|
->multiple()
|
||||||
|
->preload()
|
||||||
|
->searchable(),
|
||||||
|
|
||||||
|
Hidden::make('password')
|
||||||
|
->default(fn (): string => config('auth.password_default'))
|
||||||
|
->visibleOn('create'),
|
||||||
|
]),
|
||||||
]),
|
]),
|
||||||
])
|
])
|
||||||
->columns(1);
|
->columns(1);
|
||||||
|
|||||||
@ -889,6 +889,10 @@
|
|||||||
'cheerful' => 'Yuk, buat akun baru biar makin lengkap penggunanya! 💪😊',
|
'cheerful' => 'Yuk, buat akun baru biar makin lengkap penggunanya! 💪😊',
|
||||||
'formal' => 'Silakan masukkan detail akun pengguna baru di bawah ini.',
|
'formal' => 'Silakan masukkan detail akun pengguna baru di bawah ini.',
|
||||||
],
|
],
|
||||||
|
'create_form_desc' => [
|
||||||
|
'cheerful' => 'Pake alamat surel dan nama pengguna ini buat masuk ya. Oh iya, kata sandi awalnya <code class="text-sm bg-gray-100 text-red-400 px-1.5 py-0.5 rounded font-mono">'.config('auth.password_default').'</code> 🥳',
|
||||||
|
'formal' => 'Gunakan alamat surel dan nama pengguna ini untuk masuk. Kata sandi awalnya adalah <code class="text-sm bg-gray-100 text-red-400 px-1.5 py-0.5 rounded font-mono">'.config('auth.password_default').'</code>.',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'theme' => [
|
'theme' => [
|
||||||
'create_title' => [
|
'create_title' => [
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user