mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2026-01-28 07:43:18 +00:00
✨ Refactor project-support forms: add admin-only fields, improve Flux form components, and enhance layout for consistency. 🛠️ Remove redundant NostrAuth methods and streamline authorization logic.
This commit is contained in:
@@ -2,21 +2,28 @@
|
||||
|
||||
use App\Models\ProjectProposal;
|
||||
use App\Support\NostrAuth;
|
||||
use Livewire\Component;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Attributes\Title;
|
||||
use Livewire\Component;
|
||||
|
||||
new
|
||||
#[Layout('layouts.app')]
|
||||
#[Title('Projektförderung anlegen')]
|
||||
class extends Component {
|
||||
class extends Component
|
||||
{
|
||||
public array $form = [
|
||||
'name' => '',
|
||||
'description' => '',
|
||||
'support_in_sats' => '',
|
||||
'website' => '',
|
||||
'accepted' => false,
|
||||
'sats_paid' => 0,
|
||||
];
|
||||
|
||||
public bool $isAllowed = false;
|
||||
|
||||
public bool $isAdmin = false;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
if (NostrAuth::check()) {
|
||||
@@ -26,6 +33,10 @@ class extends Component {
|
||||
if ($currentPleb && $currentPleb->association_status->value > 1 && $currentPleb->paymentEvents()->where('year', date('Y'))->where('paid', true)->exists()) {
|
||||
$this->isAllowed = true;
|
||||
}
|
||||
|
||||
if ($currentPleb && in_array($currentPleb->npub, config('einundzwanzig.config.current_board'), true)) {
|
||||
$this->isAdmin = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,19 +45,24 @@ class extends Component {
|
||||
$this->validate([
|
||||
'form.name' => 'required|string|max:255',
|
||||
'form.description' => 'required|string',
|
||||
'form.support_in_sats' => 'required|integer|min:0',
|
||||
'form.website' => 'required|url|max:255',
|
||||
]);
|
||||
|
||||
ProjectProposal::query()->create([
|
||||
'name' => $this->form['name'],
|
||||
'description' => $this->form['description'],
|
||||
'support_in_sats' => 0,
|
||||
'support_in_sats' => (int) $this->form['support_in_sats'],
|
||||
'website' => $this->form['website'],
|
||||
'accepted' => $this->form['accepted'],
|
||||
'sats_paid' => $this->form['sats_paid'],
|
||||
'einundzwanzig_pleb_id' => \App\Models\EinundzwanzigPleb::query()->where('pubkey', NostrAuth::pubkey())->first()->id,
|
||||
]);
|
||||
|
||||
$this->redirectRoute('association.projectSupport');
|
||||
}
|
||||
};
|
||||
?>
|
||||
?>
|
||||
<div>
|
||||
@if($isAllowed)
|
||||
<div class="px-4 sm:px-6 lg:px-8 py-8 w-full max-w-9xl mx-auto">
|
||||
@@ -59,47 +75,62 @@ class extends Component {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="md:flex">
|
||||
<!-- Left column -->
|
||||
<div class="w-full md:w-60 mb-4 md:mb-0">
|
||||
<div
|
||||
class="bg-white dark:bg-gray-800 shadow-sm rounded-xl p-5">
|
||||
<h2 class="text-lg font-semibold text-gray-800 dark:text-gray-100 mb-4">
|
||||
Formular
|
||||
</h2>
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||
<!-- Form card -->
|
||||
<div class="lg:col-span-2">
|
||||
<flux:card>
|
||||
<flux:fieldset>
|
||||
<flux:legend>Formular</flux:legend>
|
||||
<div class="space-y-4">
|
||||
<flux:field>
|
||||
<flux:label>Name</flux:label>
|
||||
<flux:input wire:model="form.name" placeholder="Projektname" />
|
||||
<flux:error name="form.name" />
|
||||
</flux:field>
|
||||
</div>
|
||||
<div>
|
||||
<flux:field>
|
||||
<flux:label>Beschreibung</flux:label>
|
||||
<flux:textarea wire:model="form.description" rows="6" placeholder="Projektbeschreibung..." />
|
||||
<flux:error name="form.description" />
|
||||
<flux:label>Website</flux:label>
|
||||
<flux:input wire:model="form.website" type="url" placeholder="https://example.com" />
|
||||
<flux:error name="form.website" />
|
||||
</flux:field>
|
||||
<flux:field>
|
||||
<flux:label>Unterstützung (Sats)</flux:label>
|
||||
<flux:input wire:model="form.support_in_sats" type="number" placeholder="100000" />
|
||||
<flux:error name="form.support_in_sats" />
|
||||
</flux:field>
|
||||
<flux:editor wire:model="form.description" label="Beschreibung" description="Projektbeschreibung..." />
|
||||
<flux:error name="form.description" />
|
||||
|
||||
@if($isAdmin)
|
||||
<flux:separator />
|
||||
<flux:heading level="3" class="text-sm font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">Admin Felder</flux:heading>
|
||||
<div class="space-y-3 mt-3">
|
||||
<flux:field>
|
||||
<flux:label>Akzeptiert</flux:label>
|
||||
<flux:switch wire:model="form.accepted" />
|
||||
</flux:field>
|
||||
<flux:field>
|
||||
<flux:label>Sats bezahlt</flux:label>
|
||||
<flux:input type="number" wire:model="form.sats_paid" />
|
||||
</flux:field>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<flux:button wire:click="save" wire:loading.attr="disabled" variant="primary" class="w-full mt-4">
|
||||
Speichern
|
||||
</flux:button>
|
||||
</div>
|
||||
<flux:button wire:click="save" wire:loading.attr="disabled" variant="primary" class="w-full">
|
||||
Speichern
|
||||
</flux:button>
|
||||
</div>
|
||||
</div>
|
||||
</flux:fieldset>
|
||||
</flux:card>
|
||||
</div>
|
||||
|
||||
<!-- Right column -->
|
||||
<div class="flex-1 md:ml-8">
|
||||
<div
|
||||
class="bg-white dark:bg-gray-800 shadow-sm rounded-xl p-5">
|
||||
<h2 class="text-lg font-semibold text-gray-800 dark:text-gray-100 mb-4">
|
||||
Information
|
||||
</h2>
|
||||
<p class="text-sm text-gray-800 dark:text-gray-100">
|
||||
<!-- Information card -->
|
||||
<div>
|
||||
<flux:card>
|
||||
<flux:heading level="2">Information</flux:heading>
|
||||
<p class="text-sm text-gray-800 dark:text-gray-100 mt-4">
|
||||
Fülle das Formular aus, um eine neue Projektförderung anzulegen.
|
||||
</p>
|
||||
</div>
|
||||
</flux:card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -9,16 +9,23 @@ use Livewire\Component;
|
||||
new
|
||||
#[Layout('layouts.app')]
|
||||
#[Title('Projektförderung bearbeiten')]
|
||||
class extends Component {
|
||||
class extends Component
|
||||
{
|
||||
public ProjectProposal $project;
|
||||
|
||||
public array $form = [
|
||||
'name' => '',
|
||||
'description' => '',
|
||||
'support_in_sats' => '',
|
||||
'website' => '',
|
||||
'accepted' => false,
|
||||
'sats_paid' => 0,
|
||||
];
|
||||
|
||||
public bool $isAllowed = false;
|
||||
|
||||
public bool $isAdmin = false;
|
||||
|
||||
public function mount($projectProposal): void
|
||||
{
|
||||
$this->project = ProjectProposal::query()->where('slug', $projectProposal)->firstOrFail();
|
||||
@@ -38,8 +45,16 @@ class extends Component {
|
||||
$this->form = [
|
||||
'name' => $this->project->name,
|
||||
'description' => $this->project->description,
|
||||
'support_in_sats' => (string) $this->project->support_in_sats,
|
||||
'website' => $this->project->website ?? '',
|
||||
'accepted' => (bool) $this->project->accepted,
|
||||
'sats_paid' => $this->project->sats_paid,
|
||||
];
|
||||
}
|
||||
|
||||
if ($currentPleb && in_array($currentPleb->npub, config('einundzwanzig.config.current_board'), true)) {
|
||||
$this->isAdmin = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,11 +63,17 @@ class extends Component {
|
||||
$this->validate([
|
||||
'form.name' => 'required|string|max:255',
|
||||
'form.description' => 'required|string',
|
||||
'form.support_in_sats' => 'required|integer|min:0',
|
||||
'form.website' => 'required|url|max:255',
|
||||
]);
|
||||
|
||||
$this->project->update([
|
||||
'name' => $this->form['name'],
|
||||
'description' => $this->form['description'],
|
||||
'support_in_sats' => (int) $this->form['support_in_sats'],
|
||||
'website' => $this->form['website'],
|
||||
'accepted' => $this->isAdmin ? (bool) $this->form['accepted'] : $this->project->accepted,
|
||||
'sats_paid' => $this->isAdmin ? $this->form['sats_paid'] : $this->project->sats_paid,
|
||||
]);
|
||||
|
||||
$this->redirectRoute('association.projectSupport.item', $this->project);
|
||||
@@ -72,47 +93,70 @@ class extends Component {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="md:flex">
|
||||
<!-- Left column -->
|
||||
<div class="w-full md:w-60 mb-4 md:mb-0">
|
||||
<div
|
||||
class="bg-white dark:bg-gray-800 shadow-sm rounded-xl p-5">
|
||||
<h2 class="text-lg font-semibold text-gray-800 dark:text-gray-100 mb-4">
|
||||
Formular
|
||||
</h2>
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<flux:field>
|
||||
<flux:label>Name</flux:label>
|
||||
<flux:input wire:model="form.name" placeholder="Projektname" />
|
||||
<flux:error name="form.name" />
|
||||
</flux:field>
|
||||
</div>
|
||||
<div>
|
||||
<flux:field>
|
||||
<flux:label>Beschreibung</flux:label>
|
||||
<flux:textarea wire:model="form.description" rows="6" placeholder="Projektbeschreibung..." />
|
||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
|
||||
<!-- Left column - Form -->
|
||||
<div class="lg:col-span-2">
|
||||
<flux:card>
|
||||
<flux:fieldset>
|
||||
<flux:legend>Formular</flux:legend>
|
||||
<div class="space-y-4">
|
||||
<div>
|
||||
<flux:field>
|
||||
<flux:label>Name</flux:label>
|
||||
<flux:input wire:model="form.name" placeholder="Projektname" />
|
||||
<flux:error name="form.name" />
|
||||
</flux:field>
|
||||
</div>
|
||||
<div>
|
||||
<flux:field>
|
||||
<flux:label>Website</flux:label>
|
||||
<flux:input wire:model="form.website" type="url" placeholder="https://example.com" />
|
||||
<flux:error name="form.website" />
|
||||
</flux:field>
|
||||
</div>
|
||||
<div>
|
||||
<flux:field>
|
||||
<flux:label>Unterstützung (Sats)</flux:label>
|
||||
<flux:input wire:model="form.support_in_sats" type="number" placeholder="100000" />
|
||||
<flux:error name="form.support_in_sats" />
|
||||
</flux:field>
|
||||
</div>
|
||||
<div>
|
||||
<flux:editor wire:model="form.description" label="Beschreibung" description="Projektbeschreibung..." />
|
||||
<flux:error name="form.description" />
|
||||
</flux:field>
|
||||
</div>
|
||||
|
||||
@if($isAdmin)
|
||||
<flux:separator />
|
||||
<flux:heading level="3" class="text-sm font-semibold uppercase tracking-wide text-gray-500 dark:text-gray-400">Admin Felder</flux:heading>
|
||||
<div class="space-y-3 mt-3">
|
||||
<flux:field>
|
||||
<flux:label>Akzeptiert</flux:label>
|
||||
<flux:switch wire:model="form.accepted" />
|
||||
</flux:field>
|
||||
<flux:field>
|
||||
<flux:label>Sats bezahlt</flux:label>
|
||||
<flux:input type="number" wire:model="form.sats_paid" />
|
||||
</flux:field>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<flux:button wire:click="update" wire:loading.attr="disabled" variant="primary" class="w-full mt-4">
|
||||
Speichern
|
||||
</flux:button>
|
||||
</div>
|
||||
<flux:button wire:click="update" wire:loading.attr="disabled" variant="primary" class="w-full">
|
||||
Speichern
|
||||
</flux:button>
|
||||
</div>
|
||||
</div>
|
||||
</flux:fieldset>
|
||||
</flux:card>
|
||||
</div>
|
||||
|
||||
<!-- Right column -->
|
||||
<div class="flex-1 md:ml-8">
|
||||
<div
|
||||
class="bg-white dark:bg-gray-800 shadow-sm rounded-xl p-5">
|
||||
<h2 class="text-lg font-semibold text-gray-800 dark:text-gray-100 mb-4">
|
||||
Information
|
||||
</h2>
|
||||
<p class="text-sm text-gray-800 dark:text-gray-100">
|
||||
<!-- Right column - Information -->
|
||||
<div>
|
||||
<flux:card>
|
||||
<flux:heading level="2">Information</flux:heading>
|
||||
<p class="text-sm text-gray-800 dark:text-gray-100 mt-4">
|
||||
Bearbeite die Projektförderung und speichere deine Änderungen.
|
||||
</p>
|
||||
</div>
|
||||
</flux:card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -64,21 +64,6 @@ new class extends Component {
|
||||
->get();
|
||||
}
|
||||
|
||||
public function handleNostrLoggedIn($pubkey): void
|
||||
{
|
||||
NostrAuth::login($pubkey);
|
||||
$this->currentPubkey = $pubkey;
|
||||
$this->currentPleb = EinundzwanzigPleb::query()->where('pubkey', $pubkey)->first();
|
||||
$this->isAllowed = true;
|
||||
}
|
||||
|
||||
public function handleNostrLoggedOut(): void
|
||||
{
|
||||
$this->isAllowed = false;
|
||||
$this->currentPubkey = null;
|
||||
$this->currentPleb = null;
|
||||
}
|
||||
|
||||
public function confirmDeleteProject($id): void
|
||||
{
|
||||
$this->projectToDelete = ProjectProposal::query()->findOrFail($id);
|
||||
|
||||
@@ -21,7 +21,6 @@ new class extends Component {
|
||||
$this->projectProposal = \App\Models\ProjectProposal::query()->where('slug', $projectProposal)->firstOrFail();
|
||||
if (NostrAuth::check()) {
|
||||
$this->currentPubkey = NostrAuth::pubkey();
|
||||
$this->handleNostrLoggedIn($this->currentPubkey);
|
||||
$this->isAllowed = true;
|
||||
}
|
||||
}
|
||||
@@ -45,17 +44,6 @@ new class extends Component {
|
||||
->get();
|
||||
}
|
||||
|
||||
public function handleNostrLoggedIn($pubkey): void
|
||||
{
|
||||
$this->currentPubkey = $pubkey;
|
||||
$this->currentPleb = \App\Models\EinundzwanzigPleb::query()->where('pubkey', $pubkey)->first();
|
||||
$this->isAllowed = true;
|
||||
$this->ownVoteExists = Vote::query()
|
||||
->where('project_proposal_id', $this->projectProposal->id)
|
||||
->where('einundzwanzig_pleb_id', $this->currentPleb->id)
|
||||
->exists();
|
||||
}
|
||||
|
||||
public function handleApprove(): void
|
||||
{
|
||||
Vote::query()->updateOrCreate([
|
||||
@@ -95,7 +83,9 @@ new class extends Component {
|
||||
<h1 class="text-2xl md:text-3xl text-gray-800 dark:text-gray-100 font-bold mb-2">
|
||||
{{ $projectProposal->name }}
|
||||
</h1>
|
||||
{!! $projectProposal->description !!}
|
||||
<x-markdown>
|
||||
{!! $projectProposal->description !!}
|
||||
</x-markdown>
|
||||
</header>
|
||||
|
||||
<div class="space-y-3 sm:flex sm:items-center sm:justify-between sm:space-y-0 mb-6">
|
||||
|
||||
Reference in New Issue
Block a user