Edit client links working.
This commit is contained in:
parent
53b6c1d326
commit
04729c071e
|
|
@ -4,5 +4,6 @@
|
|||
<livewire:create-client />
|
||||
</div>
|
||||
<livewire:client-list />
|
||||
<livewire:edit-client />
|
||||
</div>
|
||||
</x-layouts::app>
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ new class extends Component {
|
|||
}
|
||||
|
||||
#[On('client-created')]
|
||||
#[On('client-updated')]
|
||||
public function refresh(): void {}
|
||||
|
||||
#[Computed]
|
||||
|
|
@ -80,8 +81,8 @@ new class extends Component {
|
|||
|
||||
<flux:navmenu>
|
||||
<flux:menu.group heading="{{ $client->abbreviation }}">
|
||||
<flux:navmenu.separator></flux:navmenu.separator>
|
||||
<flux:navmenu.item href="#" icon="pencil">Edit</flux:navmenu.item>
|
||||
<flux:menu.separator></flux:menu.separator>
|
||||
<flux:menu.item wire:click="$dispatch('edit-client', { clientId: {{ $client->id }} })" icon="pencil">Edit</flux:menu.item>
|
||||
</flux:menu.group>
|
||||
</flux:navmenu>
|
||||
</flux:dropdown>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Client;
|
||||
use Livewire\Component;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Attributes\On;
|
||||
use Flux\Flux;
|
||||
|
||||
new class extends Component {
|
||||
public ?int $clientId = null;
|
||||
|
||||
#[Validate('required|string|max:255')]
|
||||
public string $name = '';
|
||||
|
||||
#[Validate('required|string|max:10')]
|
||||
public string $abbreviation = '';
|
||||
|
||||
#[Validate('nullable|date|after_or_equal:today')]
|
||||
public ?string $audition_date = null;
|
||||
|
||||
#[On('edit-client')]
|
||||
public function edit(int $clientId): void
|
||||
{
|
||||
$this->clientId = $clientId;
|
||||
$client = Client::findOrFail($clientId);
|
||||
|
||||
$this->name = $client->name;
|
||||
$this->abbreviation = $client->abbreviation;
|
||||
$this->audition_date = $client->audition_date?->format('Y-m-d');
|
||||
|
||||
$this->resetValidation();
|
||||
Flux::modal('edit-client')->show();
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$this->validate([
|
||||
'name' => 'required|string|max:255|unique:clients,name,' . $this->clientId,
|
||||
'abbreviation' => 'required|string|max:10|unique:clients,abbreviation,' . $this->clientId,
|
||||
'audition_date' => 'nullable|date|after_or_equal:today',
|
||||
]);
|
||||
|
||||
$client = Client::findOrFail($this->clientId);
|
||||
$client->update([
|
||||
'name' => $this->name,
|
||||
'abbreviation' => $this->abbreviation,
|
||||
'audition_date' => $this->audition_date ?: null,
|
||||
]);
|
||||
|
||||
$this->reset();
|
||||
Flux::modal('edit-client')->close();
|
||||
$this->dispatch('client-updated');
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div>
|
||||
<flux:modal name="edit-client" class="md:w-96">
|
||||
<form wire:submit="save" class="space-y-6">
|
||||
<flux:heading size="lg">Edit Client</flux:heading>
|
||||
|
||||
<flux:input label="Name" wire:model="name" />
|
||||
<flux:input label="Abbreviation" wire:model="abbreviation" maxlength="10" />
|
||||
<flux:input label="Audition Date" wire:model="audition_date" type="date" />
|
||||
|
||||
<div class="flex gap-2">
|
||||
<flux:spacer />
|
||||
<flux:button type="submit" variant="primary">Save</flux:button>
|
||||
</div>
|
||||
</form>
|
||||
</flux:modal>
|
||||
</div>
|
||||
Loading…
Reference in New Issue