api/app/Filament/Resources/Users/Schemas/UserForm.php

140 lines
5.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Filament\Resources\Users\Schemas;
use App\Enums\PacePreference;
use App\Enums\PhysicalActivityLevel;
use App\Enums\UserSex;
use App\Enums\WeightGoal;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Illuminate\Validation\Rules\Password;
class UserForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
Section::make('Compte')
->columns(2)
->schema([
TextInput::make('name')
->label('Nom')
->required()
->maxLength(255),
TextInput::make('email')
->label('Adresse email')
->email()
->required()
->unique(ignoreRecord: true)
->maxLength(255),
FileUpload::make('avatar_url')
->label('Avatar')
->image()
->disk('public')
->directory('avatars')
->visibility('public')
->maxSize(2048),
TextInput::make('password')
->label('Mot de passe')
->password()
->revealable()
->rule(Password::default())
->required(fn (string $operation): bool => $operation === 'create')
->formatStateUsing(fn (): ?string => null)
->dehydrated(fn ($state): bool => filled($state))
->autocomplete('new-password'),
DateTimePicker::make('email_verified_at')
->label('Email vérifié le'),
DateTimePicker::make('account_verified_at')
->label('Compte vérifié le'),
]),
Section::make('Profil')
->columns(2)
->schema([
Textarea::make('bio')
->label('Bio')
->rows(4)
->columnSpanFull(),
TextInput::make('height')
->label('Taille')
->integer()
->minValue(0)
->maxValue(300)
->suffix('cm'),
DatePicker::make('date_of_birth')
->label('Date de naissance')
->minDate('1900-01-01')
->maxDate(now()->subDay()),
Select::make('sex')
->label('Sexe')
->options(UserSex::class)
->default(UserSex::UNKNOWN->value)
->required(),
]),
Section::make('Objectifs nutritionnels')
->columns(4)
->schema([
TextInput::make('daily_calorie_goal')
->label('Calories')
->integer()
->minValue(0)
->maxValue(100000)
->suffix('kcal')
->default(2000)
->required(),
TextInput::make('daily_protein_goal')
->label('Protéines')
->numeric()
->minValue(0)
->maxValue(10000)
->suffix('g')
->default(120)
->required(),
TextInput::make('daily_carbs_goal')
->label('Glucides')
->numeric()
->minValue(0)
->maxValue(10000)
->suffix('g')
->default(250)
->required(),
TextInput::make('daily_fats_goal')
->label('Lipides')
->numeric()
->minValue(0)
->maxValue(10000)
->suffix('g')
->default(70)
->required(),
]),
Section::make('Activité')
->columns(3)
->schema([
Select::make('physical_activity_level')
->label('Niveau dactivité')
->options(PhysicalActivityLevel::class)
->default(PhysicalActivityLevel::SEDENTARY->value)
->required(),
Select::make('weight_goal')
->label('Objectif de poids')
->options(WeightGoal::class)
->default(WeightGoal::LOSE_WEIGHT->value)
->required(),
Select::make('pace_preference')
->label('Rythme')
->options(PacePreference::class)
->default(PacePreference::SLOW->value)
->required(),
]),
]);
}
}