For custom sites we'll post to via their own API — there's no wired-in publisher for these, so this is where the site owner documents how to actually post there (auth, endpoints, payload shape). Shown in the UI for non-WordPress sites, exposed via the JSON API, and pointed to from AI_API.md's "any other network/CMS" fallback section so an agent checks it before improvising. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
109 lines
3.1 KiB
PHP
109 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Sites;
|
|
|
|
use App\Models\Site;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Component;
|
|
|
|
#[Layout('components.layouts.app')]
|
|
class Index extends Component
|
|
{
|
|
public bool $showForm = false;
|
|
|
|
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 ?string $apiInstructions = null;
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.sites.index', [
|
|
'sites' => Site::orderBy('name')->get(),
|
|
'cmsTypes' => Site::CMS_TYPES,
|
|
]);
|
|
}
|
|
|
|
public function create(): void
|
|
{
|
|
$this->resetForm();
|
|
$this->showForm = true;
|
|
}
|
|
|
|
public function edit(int $id): void
|
|
{
|
|
$site = Site::findOrFail($id);
|
|
$this->editingId = $site->id;
|
|
$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->apiInstructions = $site->api_instructions;
|
|
$this->showForm = true;
|
|
}
|
|
|
|
public function save(): void
|
|
{
|
|
$validated = $this->validate([
|
|
'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'],
|
|
'apiInstructions' => ['nullable', 'string'],
|
|
]);
|
|
|
|
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,
|
|
'api_instructions' => $validated['apiInstructions'],
|
|
]);
|
|
|
|
$this->resetForm();
|
|
$this->showForm = false;
|
|
}
|
|
|
|
public function delete(int $id): void
|
|
{
|
|
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->apiInstructions = null;
|
|
$this->resetValidation();
|
|
}
|
|
}
|