Add client form working.
This commit is contained in:
parent
2d4ef3d6e1
commit
53b6c1d326
|
|
@ -15,7 +15,7 @@ return new class extends Migration
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->string('abbreviation')->nullable();
|
$table->string('abbreviation')->nullable();
|
||||||
$table->date('audition_date');
|
$table->date('audition_date')->nullable();
|
||||||
$table->string('status')->default('active');
|
$table->string('status')->default('active');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
<x-layouts::app :title="__('Clients')">
|
<x-layouts::app :title="__('Clients')">
|
||||||
<div class="max-w-7xl mx-auto">
|
<div class="max-w-7xl mx-auto space-y-4">
|
||||||
<livewire:client-list/>
|
<div class="flex justify-end">
|
||||||
|
<livewire:create-client />
|
||||||
|
</div>
|
||||||
|
<livewire:client-list />
|
||||||
</div>
|
</div>
|
||||||
</x-layouts::app>
|
</x-layouts::app>
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Livewire\Attributes\Computed;
|
use Livewire\Attributes\Computed;
|
||||||
|
use Livewire\Attributes\On;
|
||||||
use Livewire\WithPagination;
|
use Livewire\WithPagination;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -22,6 +23,9 @@ new class extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[On('client-created')]
|
||||||
|
public function refresh(): void {}
|
||||||
|
|
||||||
#[Computed]
|
#[Computed]
|
||||||
public function clients()
|
public function clients()
|
||||||
{
|
{
|
||||||
|
|
@ -61,8 +65,8 @@ new class extends Component {
|
||||||
@foreach($this->clients as $client)
|
@foreach($this->clients as $client)
|
||||||
<flux:table.row :key="$client->id">
|
<flux:table.row :key="$client->id">
|
||||||
<flux:table.cell>{{ $client->name }}</flux:table.cell>
|
<flux:table.cell>{{ $client->name }}</flux:table.cell>
|
||||||
<flux:table.cell>{{ $client->abbreviation }}</flux:table.cell>
|
<flux:table.cell>{{ $client->abbreviation ?? '' }}</flux:table.cell>
|
||||||
<flux:table.cell>{{ $client->audition_date->local()->format('m/d/Y') }}</flux:table.cell>
|
<flux:table.cell>{{ $client->audition_date?->local()->format('m/d/Y') ?? '' }}</flux:table.cell>
|
||||||
<flux:table.cell>
|
<flux:table.cell>
|
||||||
<flux:badge :color="$client->status->color()">
|
<flux:badge :color="$client->status->color()">
|
||||||
{{ $client->status->value }}
|
{{ $client->status->value }}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Client;
|
||||||
|
use Livewire\Component;
|
||||||
|
use Livewire\Attributes\Validate;
|
||||||
|
use Flux\Flux;
|
||||||
|
|
||||||
|
new class extends Component {
|
||||||
|
#[Validate('required|string|max:255|unique:clients,name')]
|
||||||
|
public string $name = '';
|
||||||
|
|
||||||
|
#[Validate('required|string|max:10|unique:clients,abbreviation')]
|
||||||
|
public string $abbreviation = '';
|
||||||
|
|
||||||
|
#[Validate('nullable|date|after_or_equal:today')]
|
||||||
|
public ?string $audition_date = null;
|
||||||
|
|
||||||
|
public function save(): void
|
||||||
|
{
|
||||||
|
$this->validate();
|
||||||
|
|
||||||
|
Client::create([
|
||||||
|
'name' => $this->name,
|
||||||
|
'abbreviation' => $this->abbreviation,
|
||||||
|
'audition_date' => $this->audition_date ?: null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->reset();
|
||||||
|
Flux::modal('create-client')->close();
|
||||||
|
$this->dispatch('client-created');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<flux:modal.trigger name="create-client">
|
||||||
|
<flux:button icon="plus" variant="primary">
|
||||||
|
New Client
|
||||||
|
</flux:button>
|
||||||
|
</flux:modal.trigger>
|
||||||
|
|
||||||
|
|
||||||
|
<flux:modal name="create-client" class="md:w-96">
|
||||||
|
<form wire:submit="save" class="space-y-6">
|
||||||
|
<flux:heading size="lg">Create 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 variant="ghost" wire:click="$flux.modal('create-client').close()">Cancel</flux:button>--}}
|
||||||
|
<flux:button type="submit" variant="primary">Create</flux:button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</flux:modal>
|
||||||
|
</div>
|
||||||
Loading…
Reference in New Issue