- Removed redundant custom collections and `Wireable` trait from DTOs. - Replaced custom collection properties with `DataCollection`. - Updated role management views to use improved components, including avatars and toggle. - Refined Blade directives for scoped slots. - Minor cleanup in configuration and dependencies.
128 lines
3.9 KiB
PHP
128 lines
3.9 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 App\Enums\RolesStatus;
|
|
use Livewire\Component;
|
|
use Spatie\LaravelData\Attributes\DataCollectionOf;
|
|
use Spatie\LaravelData\DataCollection;
|
|
|
|
new class extends Component {
|
|
/**
|
|
* @var array<int, array{
|
|
* key: string,
|
|
* label: string,
|
|
* format: array{0: string, 1: string}|null
|
|
* }>
|
|
*/
|
|
public array $header;
|
|
|
|
#[DataCollectionOf(class: RoleData::class)]
|
|
public DataCollection $roles;
|
|
|
|
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->roles = RoleData::collect(
|
|
[
|
|
new RoleData(
|
|
name: "Super Admin",
|
|
|
|
users: UserData::collect(
|
|
[
|
|
new UserData(
|
|
name: "Kushal Saha",
|
|
email: "kushal@example.com",
|
|
),
|
|
new UserData(
|
|
name: "Test Example",
|
|
email: "test@example.com",
|
|
),
|
|
],
|
|
DataCollection::class,
|
|
),
|
|
|
|
services: ServiceData::collect(
|
|
[
|
|
new ServiceData(name: "Teams"),
|
|
new ServiceData(name: "Outlook"),
|
|
],
|
|
DataCollection::class,
|
|
),
|
|
|
|
status: RolesStatus::Active,
|
|
),
|
|
],
|
|
DataCollection::class,
|
|
);
|
|
}
|
|
};
|
|
?>
|
|
|
|
|
|
<div>
|
|
<x-shared.card title="Roles" icon="lucide-shield-ellipsis" class="p-0">
|
|
<x-slot:actions>
|
|
<x-shared.button icon="lucide-plus">
|
|
{{ __('Add role') }}
|
|
</x-shared.button>
|
|
</x-slot:actions>
|
|
|
|
<x-table :headers="$header" :rows="$roles">
|
|
@scope('cell_users', $role)
|
|
@php /** @var RoleData $role */ @endphp
|
|
<div class="flex -space-x-3">
|
|
@foreach($role->users as $user)
|
|
<x-shared.avatar>
|
|
<span class="text-xs font-bold text-center text-blue-800">
|
|
{{implode('', array_map(fn($w) => strtoupper($w[0]), explode(' ', $user->name)))}}
|
|
</span>
|
|
</x-shared.avatar>
|
|
@endforeach
|
|
</div>
|
|
@endscope
|
|
@scope('cell_status', $role)
|
|
@php /** @var RoleData $role */ @endphp
|
|
<x-shared.badge class="bg-lime-200 text-lime-800 font-bold">
|
|
{{ ucfirst($role->status->name) }}
|
|
</x-shared.badge>
|
|
@endscope
|
|
@scope('cell_services', $role)
|
|
@php /** @var RoleData $role */ @endphp
|
|
@foreach($role->services as $service)
|
|
<x-shared.badge class="bg-indigo-200 text-indigo-800 font-bold">
|
|
{{$service->name}}
|
|
</x-shared.badge>
|
|
@endforeach
|
|
@endscope
|
|
|
|
@scope('actions', $role)
|
|
<x-shared.button icon="lucide-square-pen"/>
|
|
@endscope
|
|
</x-table>
|
|
</x-shared.card>
|
|
</div>
|