Commit 8e66a067 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Move delete actions from list tables into show pages

Employee delete: removed from list table (was broken due to row click
propagation), added as red button inside EmployeeShow with proper
wire:confirm and redirect after success.

Participant delete: removed from list table, added as red button inside
ParticipantShow that opens the DeleteParticipant modal with per-invoice
refund options. Redirects to list after deletion.
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 9d46be15
......@@ -6,7 +6,6 @@
use App\Domain\HR\Enums\EmploymentType;
use App\Domain\HR\Models\Employee;
use App\Domain\Identity\Services\PermissionService;
use Illuminate\Support\Facades\DB;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Title;
use Livewire\Attributes\Url;
......@@ -51,37 +50,6 @@ public function updatedBranchId(): void
$this->resetPage();
}
public function delete(string $uuid): void
{
$this->authorize('employees.delete');
$employee = Employee::where('uuid', $uuid)->firstOrFail();
DB::transaction(function () use ($employee) {
// 1. Deactivate trainer record if exists
if ($employee->trainer) {
$employee->trainer->update(['status' => 'inactive']);
}
// 2. Soft-delete linked user account if exists
if ($employee->user_id) {
$user = \App\Models\User::find($employee->user_id);
if ($user) {
if ($user->person_id) {
\App\Domain\Identity\Models\Person::where('id', $user->person_id)
->update(['user_id' => null]);
}
$user->delete();
}
}
// 3. Soft-delete the employee
$employee->delete();
});
session()->flash('success', __('تم حذف الموظف بنجاح'));
}
public function render()
{
$query = Employee::with(['person', 'branch'])
......
......@@ -3,6 +3,7 @@
namespace App\Livewire\HR;
use App\Domain\HR\Models\Employee;
use Illuminate\Support\Facades\DB;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Title;
use Livewire\Component;
......@@ -29,6 +30,33 @@ public function mount(Employee $employee): void
]);
}
public function delete(): void
{
$this->authorize('employees.delete');
DB::transaction(function () {
if ($this->employee->trainer) {
$this->employee->trainer->update(['status' => 'inactive']);
}
if ($this->employee->user_id) {
$user = \App\Models\User::find($this->employee->user_id);
if ($user) {
if ($user->person_id) {
\App\Domain\Identity\Models\Person::where('id', $user->person_id)
->update(['user_id' => null]);
}
$user->delete();
}
}
$this->employee->delete();
});
session()->flash('success', __('تم حذف الموظف بنجاح'));
$this->redirect(route('employees.list'), navigate: true);
}
public function render()
{
$person = $this->employee->person;
......
......@@ -130,7 +130,7 @@ public function deleteParticipant(): void
$this->showModal = false;
session()->flash('success', __('تم حذف المشترك بنجاح'));
$this->dispatch('participant-deleted');
$this->redirect(route('participants.list'), navigate: true);
}
public function render()
......
......@@ -7,7 +7,6 @@
use App\Domain\Training\Models\Activity;
use App\Livewire\Concerns\AppliesRoleScope;
use Livewire\Attributes\Layout;
use Livewire\Attributes\On;
use Livewire\Attributes\Title;
use Livewire\Attributes\Url;
use Livewire\Component;
......@@ -50,11 +49,6 @@ public function updatedSkillLevel(): void
$this->resetPage();
}
#[On('participant-deleted')]
public function refreshList(): void
{
// Livewire re-renders automatically
}
public function render()
{
......
......@@ -93,11 +93,6 @@ class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 f
<a href="{{ route('employees.edit', $emp) }}" wire:navigate
class="text-blue-600 hover:text-blue-800 text-xs font-medium">{{ __('تعديل') }}</a>
@endcan
@can('employees.delete')
<button wire:click="delete('{{ $emp->uuid }}')"
wire:confirm="{{ __('هل أنت متأكد من حذف هذا الموظف؟') }}"
class="text-red-600 hover:text-red-800 text-xs font-medium">{{ __('حذف') }}</button>
@endcan
</div>
</td>
</tr>
......
......@@ -56,6 +56,16 @@
</div>
</div>
<div class="flex items-center gap-2 self-start sm:self-auto">
@can('employees.delete')
<button wire:click="delete"
wire:confirm="{{ __('هل أنت متأكد من حذف هذا الموظف؟ سيتم تعطيل حساب المستخدم المرتبط وتغيير حالة المدرب إلى غير نشط.') }}"
wire:loading.attr="disabled"
wire:target="delete"
class="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 text-sm font-medium transition-colors">
<span wire:loading.remove wire:target="delete">{{ __('حذف الموظف') }}</span>
<span wire:loading wire:target="delete">{{ __('جارٍ الحذف...') }}</span>
</button>
@endcan
@can('employees.update')
<a href="{{ route('employees.edit', $employee) }}" wire:navigate
class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 text-sm font-medium">
......
<div>
@can('participants.delete')
<livewire:participants.delete-participant />
@endcan
<!-- Header -->
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4 sm:mb-6">
<h1 class="text-xl sm:text-2xl font-bold text-gray-800">{{ __('المشتركين') }}</h1>
......@@ -125,9 +121,6 @@ class="w-full px-3 sm:px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 f
@can('participants.update')
<a href="{{ route('participants.edit', $participant) }}" wire:navigate class="text-green-600 hover:text-green-800 text-sm font-medium">{{ __('تعديل') }}</a>
@endcan
@can('participants.delete')
<button wire:click="$dispatch('open-delete-participant', { id: {{ $participant->id }} })" class="text-red-600 hover:text-red-800 text-sm font-medium" onclick="event.stopPropagation()">{{ __('حذف') }}</button>
@endcan
</div>
</td>
</tr>
......@@ -207,12 +200,6 @@ class="flex-1 text-center py-2 text-sm font-medium text-green-600 hover:text-gre
{{ __('تعديل') }}
</a>
@endcan
@can('participants.delete')
<button wire:click="$dispatch('open-delete-participant', { id: {{ $participant->id }} })"
class="flex-1 text-center py-2 text-sm font-medium text-red-600 hover:text-red-800 bg-red-50 rounded-lg transition-colors">
{{ __('حذف') }}
</button>
@endcan
</div>
</div>
@empty
......
<div>
@can('participants.delete')
<livewire:participants.delete-participant />
@endcan
{{-- Flash Messages --}}
@if(session('success'))
<div class="mb-4 p-4 bg-green-50 border border-green-200 rounded-lg text-green-700 text-sm">
......@@ -53,6 +57,12 @@
</div>
</div>
<div class="flex items-center gap-2 self-start sm:self-auto">
@can('participants.delete')
<button wire:click="$dispatch('open-delete-participant', { id: {{ $participant->id }} })"
class="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700 text-sm font-medium transition-colors">
{{ __('حذف المشترك') }}
</button>
@endcan
@can('participants.update')
<a href="{{ route('participants.edit', $participant) }}" wire:navigate
class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 text-sm font-medium">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment