mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2025-12-14 12:06:46 +00:00
🛠️ Refactor service components: Add dynamic type filters, restructure landing page UI, and introduce ServiceForm for improved form handling and validations
This commit is contained in:
@@ -4,8 +4,49 @@ namespace App\Enums;
|
||||
|
||||
enum SelfHostedServiceType: string
|
||||
{
|
||||
case Mempool = 'mempool';
|
||||
case LNbits = 'lnbits';
|
||||
case Alby = 'alby';
|
||||
case BtcpayServer = 'btcpay_server';
|
||||
case ElectrumFulcrumServer = 'electrum_fulcrum_server';
|
||||
case LNbits = 'lnbits';
|
||||
case LnbitsServer = 'lnbits_server';
|
||||
case Mempool = 'mempool';
|
||||
case NostrBlossomServer = 'nostr_blossom_server';
|
||||
case NostrClient = 'nostr_client';
|
||||
case NostrRelayServer = 'nostr_relay_server';
|
||||
case PkarrDnsServer = 'pkarr_dns_server';
|
||||
case Other = 'other';
|
||||
|
||||
public function color(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Mempool => 'blue',
|
||||
self::LNbits => 'purple',
|
||||
self::Alby => 'amber',
|
||||
self::ElectrumFulcrumServer => 'cyan',
|
||||
self::BtcpayServer => 'green',
|
||||
self::LnbitsServer => 'violet',
|
||||
self::NostrRelayServer => 'fuchsia',
|
||||
self::NostrClient => 'pink',
|
||||
self::NostrBlossomServer => 'rose',
|
||||
self::PkarrDnsServer => 'orange',
|
||||
self::Other => 'zinc',
|
||||
};
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::Mempool => 'Mempool',
|
||||
self::LNbits => 'LNbits',
|
||||
self::Alby => 'Alby',
|
||||
self::ElectrumFulcrumServer => 'Electrum/Fulcrum Server',
|
||||
self::BtcpayServer => 'BTCPay Server',
|
||||
self::LnbitsServer => 'LNbits Server',
|
||||
self::NostrRelayServer => 'Nostr Relay',
|
||||
self::NostrClient => 'Nostr Client',
|
||||
self::NostrBlossomServer => 'Nostr Blossom',
|
||||
self::PkarrDnsServer => 'Pkarr DNS Server',
|
||||
self::Other => 'Other',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
119
app/Livewire/Forms/ServiceForm.php
Normal file
119
app/Livewire/Forms/ServiceForm.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Forms;
|
||||
|
||||
use App\Enums\SelfHostedServiceType;
|
||||
use App\Models\SelfHostedService;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Form;
|
||||
|
||||
class ServiceForm extends Form
|
||||
{
|
||||
public ?SelfHostedService $service = null;
|
||||
|
||||
#[Validate('required|string|max:255')]
|
||||
public string $name = '';
|
||||
|
||||
#[Validate('nullable|string')]
|
||||
public ?string $intro = null;
|
||||
|
||||
#[Validate('nullable|url|max:255')]
|
||||
public ?string $url_clearnet = null;
|
||||
|
||||
#[Validate('nullable|string|max:255')]
|
||||
public ?string $url_onion = null;
|
||||
|
||||
#[Validate('nullable|string|max:255')]
|
||||
public ?string $url_i2p = null;
|
||||
|
||||
#[Validate('nullable|string|max:255')]
|
||||
public ?string $url_pkdns = null;
|
||||
|
||||
#[Validate('required')]
|
||||
public ?string $type = null;
|
||||
|
||||
#[Validate('nullable|string')]
|
||||
public ?string $contact = null;
|
||||
|
||||
#[Validate('boolean')]
|
||||
public bool $anonymous = false;
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'type' => [
|
||||
'required',
|
||||
'in:' . collect(SelfHostedServiceType::cases())->map(fn($c) => $c->value)->implode(',')
|
||||
],
|
||||
'intro' => ['nullable', 'string'],
|
||||
'url_clearnet' => ['nullable', 'url', 'max:255'],
|
||||
'url_onion' => ['nullable', 'string', 'max:255'],
|
||||
'url_i2p' => ['nullable', 'string', 'max:255'],
|
||||
'url_pkdns' => ['nullable', 'string', 'max:255'],
|
||||
'contact' => ['nullable', 'string'],
|
||||
'anonymous' => ['boolean'],
|
||||
];
|
||||
}
|
||||
|
||||
public function setService(SelfHostedService $service): void
|
||||
{
|
||||
$this->service = $service;
|
||||
|
||||
$this->name = $service->name;
|
||||
$this->intro = $service->intro;
|
||||
$this->url_clearnet = $service->url_clearnet;
|
||||
$this->url_onion = $service->url_onion;
|
||||
$this->url_i2p = $service->url_i2p;
|
||||
$this->url_pkdns = $service->url_pkdns;
|
||||
$this->type = $service->type?->value;
|
||||
$this->contact = $service->contact;
|
||||
$this->anonymous = is_null($service->created_by);
|
||||
}
|
||||
|
||||
public function store(): SelfHostedService
|
||||
{
|
||||
$this->validate();
|
||||
$this->validateAtLeastOneUrl();
|
||||
|
||||
return SelfHostedService::create([
|
||||
'name' => $this->name,
|
||||
'type' => $this->type,
|
||||
'intro' => $this->intro,
|
||||
'url_clearnet' => $this->url_clearnet,
|
||||
'url_onion' => $this->url_onion,
|
||||
'url_i2p' => $this->url_i2p,
|
||||
'url_pkdns' => $this->url_pkdns,
|
||||
'contact' => $this->contact,
|
||||
'created_by' => $this->anonymous ? null : auth()->id(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(): void
|
||||
{
|
||||
$this->validate();
|
||||
$this->validateAtLeastOneUrl();
|
||||
|
||||
$this->service->update([
|
||||
'name' => $this->name,
|
||||
'type' => $this->type,
|
||||
'intro' => $this->intro,
|
||||
'url_clearnet' => $this->url_clearnet,
|
||||
'url_onion' => $this->url_onion,
|
||||
'url_i2p' => $this->url_i2p,
|
||||
'url_pkdns' => $this->url_pkdns,
|
||||
'contact' => $this->contact,
|
||||
'created_by' => $this->anonymous ? null : ($this->service->created_by ?? auth()->id()),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function validateAtLeastOneUrl(): void
|
||||
{
|
||||
if (empty($this->url_clearnet) && empty($this->url_onion) && empty($this->url_i2p) && empty($this->url_pkdns)) {
|
||||
$this->addError('url_clearnet', __('Mindestens eine URL muss angegeben werden.'));
|
||||
throw new \Illuminate\Validation\ValidationException(
|
||||
\Illuminate\Support\Facades\Validator::make([], [])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ class User extends Authenticatable implements CipherSweetEncrypted
|
||||
->addOptionalTextField('node_id')
|
||||
->addOptionalTextField('email')
|
||||
->addOptionalTextField('paynym')
|
||||
->addJsonField('lnbits', $map)
|
||||
->addNullableJsonField('lnbits', $map, strict: false)
|
||||
->addBlindIndex('public_key', new BlindIndex('public_key_index'))
|
||||
->addBlindIndex('lightning_address', new BlindIndex('lightning_address_index'))
|
||||
->addBlindIndex('lnurl', new BlindIndex('lnurl_index'))
|
||||
|
||||
Reference in New Issue
Block a user