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:
Andras Bacsai
2025-08-19 14:15:31 +02:00
parent eaee87d008
commit 5c4a265542
19 changed files with 659 additions and 250 deletions

View File

@@ -3,22 +3,48 @@
namespace App\Livewire\Storage;
use App\Models\S3Storage;
use App\Support\ValidationPatterns;
use Livewire\Component;
class Form extends Component
{
public S3Storage $storage;
protected $rules = [
'storage.is_usable' => 'nullable|boolean',
'storage.name' => 'nullable|min:3|max:255',
'storage.description' => 'nullable|min:3|max:255',
'storage.region' => 'required|max:255',
'storage.key' => 'required|max:255',
'storage.secret' => 'required|max:255',
'storage.bucket' => 'required|max:255',
'storage.endpoint' => 'required|url|max:255',
];
protected function rules(): array
{
return [
'storage.is_usable' => 'nullable|boolean',
'storage.name' => ValidationPatterns::nameRules(required: false),
'storage.description' => ValidationPatterns::descriptionRules(),
'storage.region' => 'required|max:255',
'storage.key' => 'required|max:255',
'storage.secret' => 'required|max:255',
'storage.bucket' => 'required|max:255',
'storage.endpoint' => 'required|url|max:255',
];
}
protected function messages(): array
{
return array_merge(
ValidationPatterns::combinedMessages(),
[
'storage.name.regex' => 'The Name may only contain letters, numbers, spaces, dashes (-), underscores (_), dots (.), slashes (/), colons (:), and parentheses ().',
'storage.description.regex' => 'The Description contains invalid characters. Only letters, numbers, spaces, and common punctuation (- _ . : / () \' " , ! ? @ # % & + = [] {} | ~ ` *) are allowed.',
'storage.region.required' => 'The Region field is required.',
'storage.region.max' => 'The Region may not be greater than 255 characters.',
'storage.key.required' => 'The Access Key field is required.',
'storage.key.max' => 'The Access Key may not be greater than 255 characters.',
'storage.secret.required' => 'The Secret Key field is required.',
'storage.secret.max' => 'The Secret Key may not be greater than 255 characters.',
'storage.bucket.required' => 'The Bucket field is required.',
'storage.bucket.max' => 'The Bucket may not be greater than 255 characters.',
'storage.endpoint.required' => 'The Endpoint field is required.',
'storage.endpoint.url' => 'The Endpoint must be a valid URL.',
'storage.endpoint.max' => 'The Endpoint may not be greater than 255 characters.',
]
);
}
protected $validationAttributes = [
'storage.is_usable' => 'Is Usable',