complete story 15.3

This commit is contained in:
Naser Mansour
2026-01-09 19:02:28 +02:00
parent b2b287e156
commit 80072eae56
9 changed files with 1221 additions and 20 deletions
@@ -0,0 +1,172 @@
<?php
use App\Enums\PotentialClientType;
use App\Models\PotentialClient;
use Livewire\Volt\Component;
new class extends Component {
public string $type = '';
public string $name = '';
public string $phone = '';
public string $email = '';
public string $address = '';
public string $social_media = '';
public string $website = '';
public string $notes = '';
public function rules(): array
{
return [
'type' => ['required', 'in:individual,company,agency'],
'name' => ['nullable', 'string', 'max:255'],
'phone' => ['nullable', 'string', 'max:50'],
'email' => ['nullable', 'email', 'max:255'],
'address' => ['nullable', 'string', 'max:1000'],
'social_media' => ['nullable', 'string', 'max:255'],
'website' => ['nullable', 'url', 'max:255'],
'notes' => ['nullable', 'string', 'max:5000'],
];
}
public function messages(): array
{
return [
'type.required' => __('potential-clients.type_required'),
];
}
public function create(): void
{
$validated = $this->validate();
PotentialClient::create($validated);
session()->flash('success', __('potential-clients.created_success'));
$this->redirect(route('admin.potential-clients.index'), navigate: true);
}
public function with(): array
{
return [
'types' => PotentialClientType::cases(),
];
}
}; ?>
<div>
<div class="mb-6">
<flux:button variant="ghost" :href="route('admin.potential-clients.index')" wire:navigate icon="arrow-left">
{{ __('potential-clients.back_to_list') }}
</flux:button>
</div>
<div class="mb-6">
<flux:heading size="xl">{{ __('potential-clients.create_potential_client') }}</flux:heading>
<flux:text class="mt-1 text-zinc-500">{{ __('potential-clients.subtitle') }}</flux:text>
</div>
<div class="rounded-lg border border-zinc-200 bg-white p-6">
<form wire:submit="create" class="space-y-6">
{{-- Type Selection --}}
<div>
<flux:heading size="lg" class="mb-4">{{ __('potential-clients.fields.type') }}</flux:heading>
<flux:field>
<flux:label class="required">{{ __('potential-clients.fields.type') }}</flux:label>
<flux:select wire:model="type" required>
<flux:select.option value="">{{ __('potential-clients.select_type') }}</flux:select.option>
@foreach ($types as $typeOption)
<flux:select.option value="{{ $typeOption->value }}">
{{ $typeOption->label() }}
</flux:select.option>
@endforeach
</flux:select>
<flux:error name="type" />
</flux:field>
</div>
{{-- Contact Information --}}
<div class="border-t border-zinc-200 pt-6">
<flux:heading size="lg" class="mb-4">{{ __('potential-clients.contact_information') }}</flux:heading>
<div class="grid gap-6 sm:grid-cols-2">
<flux:field>
<flux:label>{{ __('potential-clients.fields.name') }}</flux:label>
<flux:input
wire:model="name"
type="text"
/>
<flux:error name="name" />
</flux:field>
<flux:field>
<flux:label>{{ __('potential-clients.fields.phone') }}</flux:label>
<flux:input
wire:model="phone"
type="tel"
/>
<flux:error name="phone" />
</flux:field>
<flux:field>
<flux:label>{{ __('potential-clients.fields.email') }}</flux:label>
<flux:input
wire:model="email"
type="email"
/>
<flux:error name="email" />
</flux:field>
<flux:field>
<flux:label>{{ __('potential-clients.fields.website') }}</flux:label>
<flux:input
wire:model="website"
type="url"
placeholder="https://"
/>
<flux:error name="website" />
</flux:field>
<flux:field class="sm:col-span-2">
<flux:label>{{ __('potential-clients.fields.address') }}</flux:label>
<flux:textarea
wire:model="address"
rows="2"
/>
<flux:error name="address" />
</flux:field>
<flux:field class="sm:col-span-2">
<flux:label>{{ __('potential-clients.fields.social_media') }}</flux:label>
<flux:input
wire:model="social_media"
type="text"
:placeholder="__('potential-clients.social_media_placeholder')"
/>
<flux:error name="social_media" />
</flux:field>
</div>
</div>
{{-- Additional Information --}}
<div class="border-t border-zinc-200 pt-6">
<flux:heading size="lg" class="mb-4">{{ __('potential-clients.additional_information') }}</flux:heading>
<flux:field>
<flux:label>{{ __('potential-clients.fields.notes') }}</flux:label>
<flux:textarea
wire:model="notes"
rows="4"
/>
<flux:error name="notes" />
</flux:field>
</div>
<div class="flex items-center justify-end gap-4 border-t border-zinc-200 pt-6">
<flux:button variant="ghost" :href="route('admin.potential-clients.index')" wire:navigate>
{{ __('potential-clients.cancel') }}
</flux:button>
<flux:button variant="primary" type="submit">
{{ __('potential-clients.create') }}
</flux:button>
</div>
</form>
</div>
</div>
@@ -0,0 +1,187 @@
<?php
use App\Enums\PotentialClientType;
use App\Models\PotentialClient;
use Livewire\Volt\Component;
new class extends Component {
public PotentialClient $potentialClient;
public string $type = '';
public string $name = '';
public string $phone = '';
public string $email = '';
public string $address = '';
public string $social_media = '';
public string $website = '';
public string $notes = '';
public function mount(PotentialClient $potentialClient): void
{
$this->potentialClient = $potentialClient;
$this->type = $potentialClient->type->value;
$this->name = $potentialClient->name ?? '';
$this->phone = $potentialClient->phone ?? '';
$this->email = $potentialClient->email ?? '';
$this->address = $potentialClient->address ?? '';
$this->social_media = $potentialClient->social_media ?? '';
$this->website = $potentialClient->website ?? '';
$this->notes = $potentialClient->notes ?? '';
}
public function rules(): array
{
return [
'type' => ['required', 'in:individual,company,agency'],
'name' => ['nullable', 'string', 'max:255'],
'phone' => ['nullable', 'string', 'max:50'],
'email' => ['nullable', 'email', 'max:255'],
'address' => ['nullable', 'string', 'max:1000'],
'social_media' => ['nullable', 'string', 'max:255'],
'website' => ['nullable', 'url', 'max:255'],
'notes' => ['nullable', 'string', 'max:5000'],
];
}
public function messages(): array
{
return [
'type.required' => __('potential-clients.type_required'),
];
}
public function update(): void
{
$validated = $this->validate();
$this->potentialClient->update($validated);
session()->flash('success', __('potential-clients.updated_success'));
$this->redirect(route('admin.potential-clients.show', $this->potentialClient), navigate: true);
}
public function with(): array
{
return [
'types' => PotentialClientType::cases(),
];
}
}; ?>
<div>
<div class="mb-6">
<flux:button variant="ghost" :href="route('admin.potential-clients.show', $potentialClient)" wire:navigate icon="arrow-left">
{{ __('potential-clients.back_to_details') }}
</flux:button>
</div>
<div class="mb-6">
<flux:heading size="xl">{{ __('potential-clients.edit_potential_client') }}</flux:heading>
<flux:text class="mt-1 text-zinc-500">{{ $potentialClient->name ?? __('potential-clients.not_provided') }}</flux:text>
</div>
<div class="rounded-lg border border-zinc-200 bg-white p-6">
<form wire:submit="update" class="space-y-6">
{{-- Type Selection --}}
<div>
<flux:heading size="lg" class="mb-4">{{ __('potential-clients.fields.type') }}</flux:heading>
<flux:field>
<flux:label class="required">{{ __('potential-clients.fields.type') }}</flux:label>
<flux:select wire:model="type" required>
<flux:select.option value="">{{ __('potential-clients.select_type') }}</flux:select.option>
@foreach ($types as $typeOption)
<flux:select.option value="{{ $typeOption->value }}">
{{ $typeOption->label() }}
</flux:select.option>
@endforeach
</flux:select>
<flux:error name="type" />
</flux:field>
</div>
{{-- Contact Information --}}
<div class="border-t border-zinc-200 pt-6">
<flux:heading size="lg" class="mb-4">{{ __('potential-clients.contact_information') }}</flux:heading>
<div class="grid gap-6 sm:grid-cols-2">
<flux:field>
<flux:label>{{ __('potential-clients.fields.name') }}</flux:label>
<flux:input
wire:model="name"
type="text"
/>
<flux:error name="name" />
</flux:field>
<flux:field>
<flux:label>{{ __('potential-clients.fields.phone') }}</flux:label>
<flux:input
wire:model="phone"
type="tel"
/>
<flux:error name="phone" />
</flux:field>
<flux:field>
<flux:label>{{ __('potential-clients.fields.email') }}</flux:label>
<flux:input
wire:model="email"
type="email"
/>
<flux:error name="email" />
</flux:field>
<flux:field>
<flux:label>{{ __('potential-clients.fields.website') }}</flux:label>
<flux:input
wire:model="website"
type="url"
placeholder="https://"
/>
<flux:error name="website" />
</flux:field>
<flux:field class="sm:col-span-2">
<flux:label>{{ __('potential-clients.fields.address') }}</flux:label>
<flux:textarea
wire:model="address"
rows="2"
/>
<flux:error name="address" />
</flux:field>
<flux:field class="sm:col-span-2">
<flux:label>{{ __('potential-clients.fields.social_media') }}</flux:label>
<flux:input
wire:model="social_media"
type="text"
:placeholder="__('potential-clients.social_media_placeholder')"
/>
<flux:error name="social_media" />
</flux:field>
</div>
</div>
{{-- Additional Information --}}
<div class="border-t border-zinc-200 pt-6">
<flux:heading size="lg" class="mb-4">{{ __('potential-clients.additional_information') }}</flux:heading>
<flux:field>
<flux:label>{{ __('potential-clients.fields.notes') }}</flux:label>
<flux:textarea
wire:model="notes"
rows="4"
/>
<flux:error name="notes" />
</flux:field>
</div>
<div class="flex items-center justify-end gap-4 border-t border-zinc-200 pt-6">
<flux:button variant="ghost" :href="route('admin.potential-clients.show', $potentialClient)" wire:navigate>
{{ __('potential-clients.cancel') }}
</flux:button>
<flux:button variant="primary" type="submit">
{{ __('potential-clients.save') }}
</flux:button>
</div>
</form>
</div>
</div>
@@ -12,6 +12,9 @@ new class extends Component {
public string $typeFilter = '';
public int $perPage = 10;
public ?int $deletingClientId = null;
public bool $showDeleteModal = false;
public function updatedSearch(): void
{
$this->resetPage();
@@ -34,6 +37,34 @@ new class extends Component {
$this->resetPage();
}
public function confirmDelete(int $id): void
{
$this->deletingClientId = $id;
$this->showDeleteModal = true;
}
public function cancelDelete(): void
{
$this->deletingClientId = null;
$this->showDeleteModal = false;
}
public function delete(): void
{
if ($this->deletingClientId) {
PotentialClient::find($this->deletingClientId)?->delete();
session()->flash('success', __('potential-clients.deleted_success'));
}
$this->deletingClientId = null;
$this->showDeleteModal = false;
}
public function getDeletingClientProperty(): ?PotentialClient
{
return $this->deletingClientId ? PotentialClient::find($this->deletingClientId) : null;
}
public function with(): array
{
return [
@@ -58,7 +89,7 @@ new class extends Component {
<flux:text class="mt-1 text-zinc-500">{{ __('potential-clients.subtitle') }}</flux:text>
</div>
<div class="header-actions">
<flux:button variant="primary" href="#" icon="plus" class="w-full sm:w-auto justify-center">
<flux:button variant="primary" :href="route('admin.potential-clients.create')" wire:navigate icon="plus" class="w-full sm:w-auto justify-center">
{{ __('potential-clients.add_potential_client') }}
</flux:button>
</div>
@@ -160,16 +191,26 @@ new class extends Component {
variant="ghost"
size="sm"
icon="eye"
href="#"
:href="route('admin.potential-clients.show', $potentialClient)"
wire:navigate
:title="__('potential-clients.view')"
/>
<flux:button
variant="ghost"
size="sm"
icon="pencil"
href="#"
:href="route('admin.potential-clients.edit', $potentialClient)"
wire:navigate
:title="__('potential-clients.edit')"
/>
<flux:button
variant="ghost"
size="sm"
icon="trash"
wire:click="confirmDelete({{ $potentialClient->id }})"
:title="__('potential-clients.delete')"
class="text-red-600 hover:text-red-700"
/>
</div>
</td>
</tr>
@@ -190,7 +231,7 @@ new class extends Component {
{{ __('potential-clients.clear_filters') }}
</flux:button>
@else
<flux:button variant="primary" href="#" class="mt-4">
<flux:button variant="primary" :href="route('admin.potential-clients.create')" wire:navigate class="mt-4">
{{ __('potential-clients.add_potential_client') }}
</flux:button>
@endif
@@ -208,4 +249,26 @@ new class extends Component {
</div>
@endif
</div>
{{-- Delete Confirmation Modal --}}
<flux:modal wire:model="showDeleteModal" class="min-w-[22rem]">
<div class="space-y-6">
<div>
<flux:heading size="lg">{{ __('potential-clients.delete_confirm_title') }}</flux:heading>
<flux:text class="mt-2">{{ __('potential-clients.delete_confirm_message') }}</flux:text>
@if ($this->deletingClient)
<flux:text class="mt-2 font-medium">{{ $this->deletingClient->name ?? __('potential-clients.not_provided') }}</flux:text>
@endif
</div>
<div class="flex gap-2">
<flux:spacer />
<flux:button variant="ghost" wire:click="cancelDelete">
{{ __('potential-clients.cancel') }}
</flux:button>
<flux:button variant="danger" wire:click="delete">
{{ __('potential-clients.delete') }}
</flux:button>
</div>
</div>
</flux:modal>
</div>
@@ -0,0 +1,188 @@
<?php
use App\Enums\PotentialClientType;
use App\Models\PotentialClient;
use Livewire\Volt\Component;
new class extends Component {
public PotentialClient $potentialClient;
public bool $showDeleteModal = false;
public function confirmDelete(): void
{
$this->showDeleteModal = true;
}
public function cancelDelete(): void
{
$this->showDeleteModal = false;
}
public function delete(): void
{
$this->potentialClient->delete();
session()->flash('success', __('potential-clients.deleted_success'));
$this->redirect(route('admin.potential-clients.index'), navigate: true);
}
}; ?>
<div>
<div class="mb-6 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
<div>
<flux:button variant="ghost" :href="route('admin.potential-clients.index')" wire:navigate icon="arrow-left">
{{ __('potential-clients.back_to_list') }}
</flux:button>
</div>
<div class="flex flex-wrap gap-2">
<flux:button variant="primary" :href="route('admin.potential-clients.edit', $potentialClient)" wire:navigate icon="pencil">
{{ __('potential-clients.edit') }}
</flux:button>
<flux:button variant="danger" wire:click="confirmDelete" icon="trash">
{{ __('potential-clients.delete') }}
</flux:button>
</div>
</div>
<div class="mb-6">
<flux:heading size="xl">{{ __('potential-clients.potential_client_details') }}</flux:heading>
<flux:text class="mt-1 text-zinc-500">{{ $potentialClient->name ?? __('potential-clients.not_provided') }}</flux:text>
</div>
<div class="grid gap-6 lg:grid-cols-3">
{{-- Main Information --}}
<div class="lg:col-span-2 space-y-6">
{{-- Type --}}
<div class="rounded-lg border border-zinc-200 bg-white">
<div class="border-b border-zinc-200 px-6 py-4">
<flux:heading size="lg">{{ __('potential-clients.fields.type') }}</flux:heading>
</div>
<div class="p-6">
@switch($potentialClient->type)
@case(PotentialClientType::Individual)
<flux:badge color="blue" size="lg">{{ $potentialClient->type->label() }}</flux:badge>
@break
@case(PotentialClientType::Company)
<flux:badge color="purple" size="lg">{{ $potentialClient->type->label() }}</flux:badge>
@break
@case(PotentialClientType::Agency)
<flux:badge color="amber" size="lg">{{ $potentialClient->type->label() }}</flux:badge>
@break
@endswitch
</div>
</div>
{{-- Contact Information --}}
<div class="rounded-lg border border-zinc-200 bg-white">
<div class="border-b border-zinc-200 px-6 py-4">
<flux:heading size="lg">{{ __('potential-clients.contact_information') }}</flux:heading>
</div>
<div class="p-6">
<div class="grid gap-6 sm:grid-cols-2">
<div>
<flux:text class="text-sm font-medium text-zinc-500">{{ __('potential-clients.fields.name') }}</flux:text>
<flux:text class="mt-1 text-zinc-900">{{ $potentialClient->name ?? __('potential-clients.not_provided') }}</flux:text>
</div>
<div>
<flux:text class="text-sm font-medium text-zinc-500">{{ __('potential-clients.fields.phone') }}</flux:text>
<flux:text class="mt-1 text-zinc-900">
@if ($potentialClient->phone)
<a href="tel:{{ $potentialClient->phone }}" class="text-amber-600 hover:text-amber-700">
{{ $potentialClient->phone }}
</a>
@else
{{ __('potential-clients.not_provided') }}
@endif
</flux:text>
</div>
<div>
<flux:text class="text-sm font-medium text-zinc-500">{{ __('potential-clients.fields.email') }}</flux:text>
<flux:text class="mt-1 text-zinc-900">
@if ($potentialClient->email)
<a href="mailto:{{ $potentialClient->email }}" class="text-amber-600 hover:text-amber-700">
{{ $potentialClient->email }}
</a>
@else
{{ __('potential-clients.not_provided') }}
@endif
</flux:text>
</div>
<div>
<flux:text class="text-sm font-medium text-zinc-500">{{ __('potential-clients.fields.website') }}</flux:text>
<flux:text class="mt-1 text-zinc-900">
@if ($potentialClient->website)
<a href="{{ $potentialClient->website }}" target="_blank" rel="noopener noreferrer" class="text-amber-600 hover:text-amber-700">
{{ $potentialClient->website }}
</a>
@else
{{ __('potential-clients.not_provided') }}
@endif
</flux:text>
</div>
<div class="sm:col-span-2">
<flux:text class="text-sm font-medium text-zinc-500">{{ __('potential-clients.fields.address') }}</flux:text>
<flux:text class="mt-1 text-zinc-900">{{ $potentialClient->address ?? __('potential-clients.not_provided') }}</flux:text>
</div>
<div class="sm:col-span-2">
<flux:text class="text-sm font-medium text-zinc-500">{{ __('potential-clients.fields.social_media') }}</flux:text>
<flux:text class="mt-1 text-zinc-900">{{ $potentialClient->social_media ?? __('potential-clients.not_provided') }}</flux:text>
</div>
</div>
</div>
</div>
{{-- Notes --}}
@if ($potentialClient->notes)
<div class="rounded-lg border border-zinc-200 bg-white">
<div class="border-b border-zinc-200 px-6 py-4">
<flux:heading size="lg">{{ __('potential-clients.fields.notes') }}</flux:heading>
</div>
<div class="p-6">
<flux:text class="whitespace-pre-wrap text-zinc-700">{{ $potentialClient->notes }}</flux:text>
</div>
</div>
@endif
</div>
{{-- Sidebar --}}
<div class="space-y-6">
{{-- Record Information --}}
<div class="rounded-lg border border-zinc-200 bg-white">
<div class="border-b border-zinc-200 px-6 py-4">
<flux:heading size="lg">{{ __('potential-clients.record_information') }}</flux:heading>
</div>
<div class="p-6 space-y-4">
<div>
<flux:text class="text-sm font-medium text-zinc-500">{{ __('potential-clients.created_at') }}</flux:text>
<flux:text class="mt-1 text-zinc-900">{{ $potentialClient->created_at->format('Y-m-d H:i') }}</flux:text>
</div>
<div>
<flux:text class="text-sm font-medium text-zinc-500">{{ __('potential-clients.updated_at') }}</flux:text>
<flux:text class="mt-1 text-zinc-900">{{ $potentialClient->updated_at->format('Y-m-d H:i') }}</flux:text>
</div>
</div>
</div>
</div>
</div>
{{-- Delete Confirmation Modal --}}
<flux:modal wire:model="showDeleteModal" class="min-w-[22rem]">
<div class="space-y-6">
<div>
<flux:heading size="lg">{{ __('potential-clients.delete_confirm_title') }}</flux:heading>
<flux:text class="mt-2">{{ __('potential-clients.delete_confirm_message') }}</flux:text>
<flux:text class="mt-2 font-medium">{{ $potentialClient->name ?? __('potential-clients.not_provided') }}</flux:text>
</div>
<div class="flex gap-2">
<flux:spacer />
<flux:button variant="ghost" wire:click="cancelDelete">
{{ __('potential-clients.cancel') }}
</flux:button>
<flux:button variant="danger" wire:click="delete">
{{ __('potential-clients.delete') }}
</flux:button>
</div>
</div>
</flux:modal>
</div>