feat: manage cms_type and WordPress credentials in Sites UI
This commit is contained in:
@@ -13,16 +13,25 @@ class Index extends Component
|
||||
|
||||
public ?int $editingId = null;
|
||||
|
||||
public ?int $revealedId = null;
|
||||
|
||||
public string $name = '';
|
||||
|
||||
public string $url = '';
|
||||
|
||||
public ?string $description = null;
|
||||
|
||||
public string $cmsType = 'custom';
|
||||
|
||||
public string $wpUsername = '';
|
||||
|
||||
public string $wpAppPassword = '';
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.sites.index', [
|
||||
'sites' => Site::orderBy('name')->get(),
|
||||
'cmsTypes' => Site::CMS_TYPES,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -39,6 +48,9 @@ class Index extends Component
|
||||
$this->name = $site->name;
|
||||
$this->url = $site->url;
|
||||
$this->description = $site->description;
|
||||
$this->cmsType = $site->cms_type;
|
||||
$this->wpUsername = $site->wp_username ?? '';
|
||||
$this->wpAppPassword = $site->wp_app_password ?? '';
|
||||
$this->showForm = true;
|
||||
}
|
||||
|
||||
@@ -48,9 +60,19 @@ class Index extends Component
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'url' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'cmsType' => ['required', 'string', 'in:' . implode(',', Site::CMS_TYPES)],
|
||||
'wpUsername' => ['required_if:cmsType,wordpress', 'nullable', 'string', 'max:255'],
|
||||
'wpAppPassword' => ['required_if:cmsType,wordpress', 'nullable', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
Site::updateOrCreate(['id' => $this->editingId], $validated);
|
||||
Site::updateOrCreate(['id' => $this->editingId], [
|
||||
'name' => $validated['name'],
|
||||
'url' => $validated['url'],
|
||||
'description' => $validated['description'],
|
||||
'cms_type' => $validated['cmsType'],
|
||||
'wp_username' => $validated['cmsType'] === 'wordpress' ? $validated['wpUsername'] : null,
|
||||
'wp_app_password' => $validated['cmsType'] === 'wordpress' ? $validated['wpAppPassword'] : null,
|
||||
]);
|
||||
|
||||
$this->resetForm();
|
||||
$this->showForm = false;
|
||||
@@ -61,12 +83,20 @@ class Index extends Component
|
||||
Site::findOrFail($id)->delete();
|
||||
}
|
||||
|
||||
public function toggleReveal(int $id): void
|
||||
{
|
||||
$this->revealedId = $this->revealedId === $id ? null : $id;
|
||||
}
|
||||
|
||||
public function resetForm(): void
|
||||
{
|
||||
$this->editingId = null;
|
||||
$this->name = '';
|
||||
$this->url = '';
|
||||
$this->description = null;
|
||||
$this->cmsType = 'custom';
|
||||
$this->wpUsername = '';
|
||||
$this->wpAppPassword = '';
|
||||
$this->resetValidation();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user