You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
53 lines
1.5 KiB
<?php
|
|
|
|
namespace App\Livewire\Forms\Channel;
|
|
|
|
use App\Domains\Channel\Enums\Client\AuthType;
|
|
use Livewire\Attributes\Validate;
|
|
use Livewire\Form;
|
|
|
|
class ClientForm extends Form
|
|
{
|
|
#[Validate('required|string|max:255', as: 'domains/channel/field.client.name')]
|
|
public string $name = '';
|
|
|
|
#[Validate('required|max:255', as: 'domains/channel/field.client.domain')]
|
|
public string $domain = '';
|
|
|
|
#[Validate('required', as: 'domains/channel/field.client.auth_type')]
|
|
public AuthType $auth_type = AuthType::NONE;
|
|
|
|
#[Validate(as: [
|
|
'credentials' => 'domains/channel/field.client.credentials',
|
|
'credentials.username' => 'domains/channel/field.client.credentials.username',
|
|
'credentials.password' => 'domains/channel/field.client.credentials.password',
|
|
'credentials.token' => 'domains/channel/field.client.credentials.token',
|
|
])]
|
|
public array $credentials = [];
|
|
|
|
#[Validate('required|max:255', as: 'domains/channel/field.client.webhook')]
|
|
public string $webhook = '';
|
|
|
|
public function updatingAuthType(): void
|
|
{
|
|
$this->reset('credentials');
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
if ($this->auth_type === AuthType::TOKEN) {
|
|
return [
|
|
'credentials.token' => 'required',
|
|
];
|
|
}
|
|
|
|
if ($this->auth_type == AuthType::BASIC) {
|
|
return [
|
|
'credentials.username' => 'required',
|
|
'credentials.password' => 'required',
|
|
];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
}
|
|
|