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.
77 lines
2.3 KiB
77 lines
2.3 KiB
<?php
|
|
|
|
use App\Domains\Channel\Actions\AppProvisioning\ModifyConsumerAppDetail;
|
|
use App\Domains\Channel\Actions\AppProvisioning\ProvisionConsumerApp;
|
|
use App\Domains\Channel\DTOs\AppProvisioning\ModifyConsumerAppDetailDTO;
|
|
use App\Domains\Channel\DTOs\AppProvisioning\ProvisionConsumerAppDTO;
|
|
use App\Domains\Channel\Models\Client;
|
|
use App\Livewire\Concerns\WithModal;
|
|
use App\Livewire\Concerns\WithToast;
|
|
use App\Livewire\Forms\Channel\ClientForm;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
|
|
new class extends Component
|
|
{
|
|
use WithModal;
|
|
use WithToast;
|
|
|
|
#[Locked]
|
|
public ?string $id = null;
|
|
|
|
#[Locked]
|
|
public string $mode = 'create';
|
|
|
|
public ClientForm $form;
|
|
|
|
protected string $resourceName = 'client';
|
|
|
|
public function save(ProvisionConsumerApp $create, ModifyConsumerAppDetail $modify): void
|
|
{
|
|
$this->form->validate();
|
|
|
|
if ($this->mode === 'create') {
|
|
$create->execute(new ProvisionConsumerAppDTO(
|
|
name: $this->form->name,
|
|
domain: $this->form->domain,
|
|
webhook_url: $this->form->webhook,
|
|
auth_type: $this->form->auth_type,
|
|
credentials: $this->form->credentials,
|
|
));
|
|
} else {
|
|
$modify->execute($this->client, new ModifyConsumerAppDetailDTO(
|
|
webhook_url: $this->form->webhook,
|
|
auth_type: $this->form->auth_type,
|
|
credentials: $this->form->credentials,
|
|
));
|
|
}
|
|
|
|
$this->success($this->message);
|
|
$this->dispatch('hide-client-form-modal');
|
|
$this->js("LaravelDataTables['client-table'].ajax.reload(null, false)");
|
|
$this->form->reset();
|
|
$this->form->resetValidation();
|
|
$this->reset('id', 'mode');
|
|
}
|
|
|
|
#[Computed]
|
|
public function client(): ?Client
|
|
{
|
|
return $this->id ? Client::where('ulid', $this->id)->first() : null;
|
|
}
|
|
|
|
public function show(int|string $id): void
|
|
{
|
|
$this->id = $id;
|
|
$this->mode = 'update';
|
|
$this->form->fill($this->client->only(['name', 'webhook', 'domain', 'auth_type']));
|
|
}
|
|
|
|
public function hide(): void
|
|
{
|
|
$this->form->reset();
|
|
$this->form->resetValidation();
|
|
$this->reset('id', 'mode');
|
|
}
|
|
};
|
|
|