refactor(livewire): organizar componentes y vistas por dominio en subnamespaces
- app/Livewire: 34 componentes agrupados en Issues/, Projects/, Phases/, Companies/, Users/, Admin/, Inspections/, Layers/, Media/, Common/ (Client/, Reports/, Forms/, Actions/ ya estaban). Namespaces actualizados. - resources/views/livewire: vistas sueltas movidas a subcarpetas espejo (companies/, users/, phases/, roles/, inspections/, media/, common/); render() actualizado. - Referencias actualizadas sin romper nada: rutas (FQN, nombres de ruta intactos), tags <livewire:...>/@livewire() a alias con punto, y use de los tests. - No tocado: Volt de Breeze (auth/profile/navigation), y el portal cliente (user-nav/client-projects) que ya tenía referencias inconsistentes. Verificado: 69 rutas OK, vistas compilan, suite 69 passing (solo 2 pre-existentes sqlite). autoload regenerado con --ignore-platform-reqs (PHP 8.2). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Projects;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
|
||||
class ProjectUsers extends Component
|
||||
{
|
||||
public Project $project;
|
||||
public $allUsers = [];
|
||||
public $selectedUserId = '';
|
||||
public $selectedRole = 'viewer';
|
||||
|
||||
public function mount(Project $project)
|
||||
{
|
||||
$this->project = $project;
|
||||
$this->loadAvailable();
|
||||
}
|
||||
|
||||
/** Users not yet assigned to the project (for the dropdown). */
|
||||
public function loadAvailable(): void
|
||||
{
|
||||
$assignedIds = $this->project->users()->pluck('users.id')->toArray();
|
||||
$this->allUsers = User::whereNotIn('id', $assignedIds)->orderBy('name')->get();
|
||||
}
|
||||
|
||||
/** Reload the dropdown when the embedded table changes assignments. */
|
||||
#[On('project-users-changed')]
|
||||
public function onUsersChanged(): void
|
||||
{
|
||||
$this->loadAvailable();
|
||||
}
|
||||
|
||||
public function assignUser()
|
||||
{
|
||||
abort_unless(Auth::user()->can('assign users'), 403);
|
||||
|
||||
$this->validate([
|
||||
'selectedUserId' => 'required|exists:users,id',
|
||||
'selectedRole' => 'required|in:' . implode(',', array_keys(ProjectUsersTable::ROLES)),
|
||||
]);
|
||||
|
||||
$this->project->users()->attach($this->selectedUserId, [
|
||||
'role_in_project' => $this->selectedRole,
|
||||
]);
|
||||
|
||||
$this->reset(['selectedUserId', 'selectedRole']);
|
||||
$this->loadAvailable();
|
||||
$this->dispatch('project-users-changed');
|
||||
$this->dispatch('notify', 'Usuario asignado al proyecto.');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.projects.project-users', [
|
||||
'roles' => ProjectUsersTable::ROLES,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user