diff --git a/app/Enums/ApprovalStatus.php b/app/Enums/ApprovalStatus.php index 904d73e..1eb59fc 100644 --- a/app/Enums/ApprovalStatus.php +++ b/app/Enums/ApprovalStatus.php @@ -4,13 +4,15 @@ declare(strict_types=1); namespace App\Enums; -enum ApprovalStatus: string +use Filament\Support\Contracts\HasLabel; + +enum ApprovalStatus: string implements HasLabel { case Pending = 'pending'; case Approved = 'approved'; case Rejected = 'rejected'; - public function label(): string + public function getLabel(): string { return match ($this) { self::Pending => __('enums.approval_status.pending'), @@ -19,6 +21,11 @@ enum ApprovalStatus: string }; } + public function label(): string + { + return $this->getLabel(); + } + public function color(): string { return match ($this) { diff --git a/app/Enums/BonusType.php b/app/Enums/BonusType.php index 153516a..757f34b 100644 --- a/app/Enums/BonusType.php +++ b/app/Enums/BonusType.php @@ -4,14 +4,16 @@ declare(strict_types=1); namespace App\Enums; -enum BonusType: string +use Filament\Support\Contracts\HasLabel; + +enum BonusType: string implements HasLabel { case Performance = 'performance'; case Holiday = 'holiday'; case Retention = 'retention'; case Other = 'other'; - public function label(): string + public function getLabel(): string { return match ($this) { self::Performance => __('enums.bonus_type.performance'), @@ -21,6 +23,11 @@ enum BonusType: string }; } + public function label(): string + { + return $this->getLabel(); + } + public function color(): string { return match ($this) { diff --git a/app/Enums/DisciplinarySeverity.php b/app/Enums/DisciplinarySeverity.php index 17bb2e7..58a680a 100644 --- a/app/Enums/DisciplinarySeverity.php +++ b/app/Enums/DisciplinarySeverity.php @@ -4,13 +4,15 @@ declare(strict_types=1); namespace App\Enums; -enum DisciplinarySeverity: string +use Filament\Support\Contracts\HasLabel; + +enum DisciplinarySeverity: string implements HasLabel { case Low = 'low'; case Medium = 'medium'; case High = 'high'; - public function label(): string + public function getLabel(): string { return match ($this) { self::Low => __('enums.disciplinary_severity.low'), @@ -19,6 +21,11 @@ enum DisciplinarySeverity: string }; } + public function label(): string + { + return $this->getLabel(); + } + public function color(): string { return match ($this) { diff --git a/app/Enums/DocumentType.php b/app/Enums/DocumentType.php index 40b7997..7ab5992 100644 --- a/app/Enums/DocumentType.php +++ b/app/Enums/DocumentType.php @@ -4,7 +4,9 @@ declare(strict_types=1); namespace App\Enums; -enum DocumentType: string +use Filament\Support\Contracts\HasLabel; + +enum DocumentType: string implements HasLabel { case Passport = 'passport'; case Contract = 'contract'; @@ -12,7 +14,7 @@ enum DocumentType: string case EducationCertificate = 'education_certificate'; case Other = 'other'; - public function label(): string + public function getLabel(): string { return match ($this) { self::Passport => __('enums.document_type.passport'), @@ -23,6 +25,11 @@ enum DocumentType: string }; } + public function label(): string + { + return $this->getLabel(); + } + public function color(): string { return match ($this) { diff --git a/app/Enums/EmploymentStatus.php b/app/Enums/EmploymentStatus.php index 2e42d91..48f9840 100644 --- a/app/Enums/EmploymentStatus.php +++ b/app/Enums/EmploymentStatus.php @@ -4,14 +4,16 @@ declare(strict_types=1); namespace App\Enums; -enum EmploymentStatus: string +use Filament\Support\Contracts\HasLabel; + +enum EmploymentStatus: string implements HasLabel { case Active = 'active'; case Inactive = 'inactive'; case Terminated = 'terminated'; case OnLeave = 'on_leave'; - public function label(): string + public function getLabel(): string { return match ($this) { self::Active => __('enums.employment_status.active'), @@ -21,6 +23,11 @@ enum EmploymentStatus: string }; } + public function label(): string + { + return $this->getLabel(); + } + public function color(): string { return match ($this) { diff --git a/app/Enums/Gender.php b/app/Enums/Gender.php index 8aaaa24..fa4d6aa 100644 --- a/app/Enums/Gender.php +++ b/app/Enums/Gender.php @@ -4,13 +4,15 @@ declare(strict_types=1); namespace App\Enums; -enum Gender: string +use Filament\Support\Contracts\HasLabel; + +enum Gender: string implements HasLabel { case Male = 'male'; case Female = 'female'; // case Other = 'other'; - public function label(): string + public function getLabel(): string { return match ($this) { self::Male => __('enums.gender.male'), @@ -19,6 +21,11 @@ enum Gender: string }; } + public function label(): string + { + return $this->getLabel(); + } + public function color(): string { return match ($this) { diff --git a/app/Enums/ImportType.php b/app/Enums/ImportType.php index 00b838e..d9129b9 100644 --- a/app/Enums/ImportType.php +++ b/app/Enums/ImportType.php @@ -4,14 +4,16 @@ declare(strict_types=1); namespace App\Enums; -enum ImportType: string +use Filament\Support\Contracts\HasLabel; + +enum ImportType: string implements HasLabel { case Employees = 'employees'; case Vacations = 'vacations'; case Bonuses = 'bonuses'; case Reports = 'reports'; - public function label(): string + public function getLabel(): string { return match ($this) { self::Employees => __('enums.import_type.employees'), @@ -21,6 +23,11 @@ enum ImportType: string }; } + public function label(): string + { + return $this->getLabel(); + } + /** * @return array */ diff --git a/app/Enums/VacationType.php b/app/Enums/VacationType.php index 55b582d..453fdae 100644 --- a/app/Enums/VacationType.php +++ b/app/Enums/VacationType.php @@ -4,14 +4,16 @@ declare(strict_types=1); namespace App\Enums; -enum VacationType: string +use Filament\Support\Contracts\HasLabel; + +enum VacationType: string implements HasLabel { case Annual = 'annual'; case Marriage = 'marriage'; case Study = 'study'; case Other = 'other'; - public function label(): string + public function getLabel(): string { return match ($this) { self::Annual => __('enums.vacation_type.annual'), @@ -21,6 +23,11 @@ enum VacationType: string }; } + public function label(): string + { + return $this->getLabel(); + } + public function color(): string { return match ($this) { diff --git a/app/Filament/Resources/Employees/Schemas/EmployeeForm.php b/app/Filament/Resources/Employees/Schemas/EmployeeForm.php index 9eefe79..fb70d2c 100644 --- a/app/Filament/Resources/Employees/Schemas/EmployeeForm.php +++ b/app/Filament/Resources/Employees/Schemas/EmployeeForm.php @@ -4,12 +4,12 @@ namespace App\Filament\Resources\Employees\Schemas; use App\Enums\EmploymentStatus; use App\Enums\Gender; +use Filament\Forms\Components\TextInput; +use Filament\Support\RawJs; use App\Filament\Support\HrForm; -use App\Support\Countries; -use Filament\Forms\Components\DatePicker; +use App\Support\Countries;use Filament\Forms\Components\DatePicker; use Filament\Forms\Components\Select; use Filament\Forms\Components\Textarea; -use Filament\Forms\Components\TextInput; use Filament\Schemas\Components\Tabs; use Filament\Schemas\Components\Tabs\Tab; use Filament\Schemas\Schema; @@ -59,9 +59,12 @@ class EmployeeForm TextInput::make('phone') ->label(__('hr.fields.phone')) - ->tel() - ->default(config('hr.default_phone')) + ->prefix('+993') + ->mask(RawJs::make(<<<'JS' + '99 99-99-99' + JS)) ->required(), + Textarea::make('address') ->label(__('hr.fields.address')) ->rows(3) diff --git a/config/hr.php b/config/hr.php index bf38d6e..6b130d2 100644 --- a/config/hr.php +++ b/config/hr.php @@ -10,7 +10,7 @@ return [ 'leave_calculation' => env('HR_LEAVE_CALCULATION', 'calendar'), // calendar|business - 'default_phone' => '+993 61 92 92 48', + 'default_phone' => '+993', 'employee_number' => [ 'prefix' => 'EMP-', diff --git a/lang/en/enums.php b/lang/en/enums.php index 57e8c47..2f1f382 100644 --- a/lang/en/enums.php +++ b/lang/en/enums.php @@ -4,8 +4,8 @@ declare(strict_types=1); return [ 'gender' => [ - 'male' => 'Erkek', - 'female' => 'Aýal', + 'male' => 'Male', + 'female' => 'Female', 'other' => 'Other', ], diff --git a/lang/tk/enums.php b/lang/tk/enums.php index b9f851a..4947434 100644 --- a/lang/tk/enums.php +++ b/lang/tk/enums.php @@ -10,8 +10,8 @@ return [ ], 'employment_status' => [ - 'active' => 'Işjeň', - 'inactive' => 'Işjeň däl', + 'active' => 'Işleýär', + 'inactive' => 'Wagtlaýyn işlemeýär', 'terminated' => 'Işden boşadyldy', 'on_leave' => 'Rugsatda', ], diff --git a/tests/Feature/LocalizationTest.php b/tests/Feature/LocalizationTest.php index dcf27ce..90180f5 100644 --- a/tests/Feature/LocalizationTest.php +++ b/tests/Feature/LocalizationTest.php @@ -2,12 +2,14 @@ declare(strict_types=1); +use App\Enums\EmploymentStatus; use App\Enums\Gender; use App\Enums\NavigationGroup; use App\Filament\Resources\ActivityLogs\ActivityLogResource; use App\Filament\Resources\Departments\DepartmentResource; use App\Models\User; use BezhanSalleh\LanguageSwitch\Events\LocaleChanged; +use Filament\Forms\Components\Select; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Event; @@ -35,6 +37,21 @@ it('returns translated navigation group labels', function (): void { expect(NavigationGroup::LeaveManagement->getLabel())->toBe('Dynç alyş dolandyryşy'); }); +it('returns translated enum options for filament selects', function (): void { + App::setLocale('tk'); + + $options = Select::make('employment_status') + ->options(EmploymentStatus::class) + ->getOptions(); + + expect($options)->toBe([ + 'active' => 'Işleýär', + 'inactive' => 'Wagtlaýyn işlemeýär', + 'terminated' => 'Işden boşadyldy', + 'on_leave' => 'Rugsatda', + ]); +}); + it('returns translated filament navigation group labels at request time', function (): void { $admin = createAdminUser(['locale' => 'tk']);