mirror of
https://github.com/tiennm99/coolify.git
synced 2026-04-28 18:22:22 +00:00
refactor(validation): implement centralized validation patterns across components
- Introduced `ValidationPatterns` class to standardize validation rules and messages for various fields across multiple components. - Updated components including `General`, `StackForm`, `Create`, and `Show` to utilize the new validation patterns, ensuring consistent validation logic. - Enhanced error messages for required fields and added regex validation for names and descriptions to improve user feedback. - Adjusted styling in the `create.blade.php` view for better visual hierarchy.
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Livewire\Team;
|
||||
|
||||
use App\Models\Team;
|
||||
use App\Models\TeamInvitation;
|
||||
use App\Support\ValidationPatterns;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Component;
|
||||
@@ -14,10 +15,25 @@ class Index extends Component
|
||||
|
||||
public Team $team;
|
||||
|
||||
protected $rules = [
|
||||
'team.name' => 'required|min:3|max:255',
|
||||
'team.description' => 'nullable|min:3|max:255',
|
||||
];
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'team.name' => ValidationPatterns::nameRules(),
|
||||
'team.description' => ValidationPatterns::descriptionRules(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function messages(): array
|
||||
{
|
||||
return array_merge(
|
||||
ValidationPatterns::combinedMessages(),
|
||||
[
|
||||
'team.name.required' => 'The Name field is required.',
|
||||
'team.name.regex' => 'The Name may only contain letters, numbers, spaces, dashes (-), underscores (_), dots (.), slashes (/), colons (:), and parentheses ().',
|
||||
'team.description.regex' => 'The Description contains invalid characters. Only letters, numbers, spaces, and common punctuation (- _ . : / () \' " , ! ? @ # % & + = [] {} | ~ ` *) are allowed.',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected $validationAttributes = [
|
||||
'team.name' => 'name',
|
||||
|
||||
Reference in New Issue
Block a user