feat: add Social Accounts Livewire CRUD page

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Doar Mihai
2026-07-18 15:05:55 +03:00
co-authored by Claude Sonnet 5
parent 3f46eecff8
commit cee5b1976b
4 changed files with 256 additions and 3 deletions
+91
View File
@@ -0,0 +1,91 @@
<?php
namespace App\Livewire\SocialAccounts;
use App\Models\SocialAccount;
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 $network = '';
public string $username = '';
public string $email = '';
public string $password = '';
public ?string $type = null;
public function render()
{
return view('livewire.social-accounts.index', [
'accounts' => SocialAccount::orderBy('username')->get(),
'networks' => SocialAccount::NETWORKS,
'types' => SocialAccount::TYPES,
]);
}
public function create(): void
{
$this->resetForm();
$this->showForm = true;
}
public function edit(int $id): void
{
$account = SocialAccount::findOrFail($id);
$this->editingId = $account->id;
$this->network = $account->network;
$this->username = $account->username;
$this->email = $account->email;
$this->password = $account->password;
$this->type = $account->type;
$this->showForm = true;
}
public function save(): void
{
$validated = $this->validate([
'network' => ['required', 'string', 'in:' . implode(',', SocialAccount::NETWORKS)],
'username' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'max:255'],
'password' => ['required', 'string', 'max:255'],
'type' => ['nullable', 'string', 'in:' . implode(',', SocialAccount::TYPES)],
]);
SocialAccount::updateOrCreate(['id' => $this->editingId], $validated);
$this->resetForm();
$this->showForm = false;
}
public function delete(int $id): void
{
SocialAccount::findOrFail($id)->delete();
}
public function toggleReveal(int $id): void
{
$this->revealedId = $this->revealedId === $id ? null : $id;
}
public function resetForm(): void
{
$this->editingId = null;
$this->network = '';
$this->username = '';
$this->email = '';
$this->password = '';
$this->type = null;
$this->resetValidation();
}
}