client = $client; } public function openDeactivateModal(): void { $this->showDeactivateModal = true; } public function closeDeactivateModal(): void { $this->showDeactivateModal = false; } public function deactivate(): void { // Prevent admin from deactivating their own account if ($this->client->id === auth()->id()) { $this->showDeactivateModal = false; session()->flash('error', __('clients.cannot_deactivate_self')); return; } $oldStatus = $this->client->status->value; DB::transaction(function () use ($oldStatus) { $this->client->deactivate(); // Invalidate all active sessions for this user DB::table('sessions') ->where('user_id', $this->client->id) ->delete(); AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'deactivate', 'target_type' => 'user', 'target_id' => $this->client->id, 'old_values' => ['status' => $oldStatus], 'new_values' => ['status' => 'deactivated'], 'ip_address' => request()->ip(), 'created_at' => now(), ]); }); $this->showDeactivateModal = false; $this->client->refresh(); session()->flash('success', __('clients.user_deactivated')); } public function openReactivateModal(): void { $this->showReactivateModal = true; } public function closeReactivateModal(): void { $this->showReactivateModal = false; } public function reactivate(): void { $oldStatus = $this->client->status->value; DB::transaction(function () use ($oldStatus) { $this->client->reactivate(); AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'reactivate', 'target_type' => 'user', 'target_id' => $this->client->id, 'old_values' => ['status' => $oldStatus], 'new_values' => ['status' => 'active'], 'ip_address' => request()->ip(), 'created_at' => now(), ]); try { $this->client->notify(new AccountReactivatedNotification); } catch (\Exception $e) { report($e); } }); $this->showReactivateModal = false; $this->client->refresh(); session()->flash('success', __('clients.user_reactivated')); } public function openDeleteModal(): void { $this->deleteConfirmation = ''; $this->showDeleteModal = true; } public function closeDeleteModal(): void { $this->showDeleteModal = false; $this->deleteConfirmation = ''; } public function delete(): void { // Prevent admin from deleting their own account if ($this->client->id === auth()->id()) { $this->addError('deleteConfirmation', __('clients.cannot_delete_self')); return; } if ($this->deleteConfirmation !== $this->client->email) { $this->addError('deleteConfirmation', __('clients.email_confirmation_mismatch')); return; } DB::transaction(function () { // Log before deletion (so we have the record before cascade delete) AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'delete', 'target_type' => 'user', 'target_id' => $this->client->id, 'old_values' => $this->client->only([ 'id', 'user_type', 'full_name', 'email', 'national_id', 'company_name', 'company_cert_number', 'contact_person_name', 'contact_person_id', 'phone', 'status', ]), 'new_values' => null, 'ip_address' => request()->ip(), 'created_at' => now(), ]); $this->client->delete(); }); session()->flash('success', __('clients.user_deleted')); // Redirect to appropriate index based on user type $redirectRoute = $this->client->isIndividual() ? route('admin.clients.individual.index') : route('admin.clients.company.index'); $this->redirect($redirectRoute, navigate: true); } public function openPasswordResetModal(): void { $this->showPasswordResetModal = true; } public function closePasswordResetModal(): void { $this->showPasswordResetModal = false; } public function resetPassword(): void { $newPassword = Str::random(12); DB::transaction(function () use ($newPassword) { $this->client->update([ 'password' => Hash::make($newPassword), ]); AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'password_reset', 'target_type' => 'user', 'target_id' => $this->client->id, 'old_values' => null, 'new_values' => null, 'ip_address' => request()->ip(), 'created_at' => now(), ]); try { $this->client->notify(new PasswordResetByAdminNotification($newPassword)); } catch (\Exception $e) { report($e); } }); $this->showPasswordResetModal = false; session()->flash('success', __('clients.password_reset_sent')); } }; ?>
{{ __('clients.deactivate_effects') }}:
{{ __('clients.reactivate_effects') }}:
{{ __('clients.will_be_deleted') }}:
{{ __('clients.reset_password_effects') }}: