= 105123bb74 chore: introduce role management functionality with DTOs and Livewire components
- Added Role and User DTOs for dynamic role handling.
- Implemented table and badge components for displaying role data.
- Registered a Blade directive for scoped slots in `ScopeServiceProvider`.
- Updated dashboard views to include role management section.
2026-05-08 13:15:00 +00:00

135 lines
4.4 KiB
PHP

<?php
use App\Data\Ui\ManageRoles\RoleData;
use App\Data\Ui\ManageRoles\RolesCollection;
use App\Data\Ui\ManageRoles\RolesData;
use App\Data\Ui\ManageRoles\ServiceCollection;
use App\Data\Ui\ManageRoles\ServiceData;
use App\Data\Users\UserCollection;
use App\Data\Users\UserData;
use App\Data\Users\UsersData;
use Livewire\Component;
new class extends Component {
/**
* @var array<int, array{
* key: string,
* label: string,
* format: array{0: string, 1: string}|null
* }>
*/
public array $header;
public RolesData $rolesData;
public function mount(): void
{
$this->header = [
[
'key' => 'name',
'label' => 'Role Name',
],
[
'key' => 'users',
'label' => 'User Assigned',
],
[
'key' => 'services',
'label' => 'Services',
],
[
'key' => 'status',
'label' => 'Status',
]
];
$this->rolesData = new RolesData(
roles: new RolesCollection([
new RoleData(
name: 'Super Admin',
users: new UsersData(
users: new UserCollection([
new UserData(
name: 'Kushal Saha',
email: 'kushal@example.com'
),
new UserData(
name: 'Test Example',
email: 'test@example.com'
)
]
)
),
services: new ServiceCollection(
[
new ServiceData(
name: 'Teams'
)
]
),
status: \App\Enums\RolesStatus::Active
),
new RoleData(
name: 'Super Admin',
users: new UsersData(
users: new UserCollection([
new UserData(
name: 'Kushal Saha',
email: 'kushal@example.com'
)
]
)
),
services: new ServiceCollection(
[
new ServiceData(
name: 'Teams'
),
new ServiceData(
name: 'Outlook'
)
]
),
status: \App\Enums\RolesStatus::Active
),
])
);
}
};
?>
<div>
<x-shared.card title="Roles" icon="lucide-shield-ellipsis" class="p-0">
<x-slot:actions>
<x-shared.button>
<div class="flex items-center gap-x-2">
<x-lucide-plus class="w-5 h-5"/>
{{ __('Add role') }}
</div>
</x-shared.button>
</x-slot:actions>
<x-table :headers="$header" :rows="$rolesData->roles">
@scope('cell_users', $row)
@foreach($row->users->users as $user)
<span
class="inline-flex items-center justify-center w-7 h-7 rounded-full bg-gray-200 text-gray-800 font-bold text-[10px] tracking-tight">
{{implode('', array_map(fn($w) => strtoupper($w[0]), explode(' ', $user->name)))}}
</span>
@endforeach
@endscope
@scope('cell_status', $row)
<x-shared.badge class="bg-lime-200 text-lime-800 font-bold">
{{ ucfirst($row->status->name) }}
</x-shared.badge>
@endscope
@scope('cell_services', $row)
@foreach($row->services as $service)
<x-shared.badge class="bg-indigo-200 text-indigo-800 font-bold">
{{$service->name}}
</x-shared.badge>
@endforeach
@endscope
</x-table>
</x-shared.card>
</div>