diff --git a/app/Data/Users/UserData.php b/app/Data/Users/UserData.php index cac9f67..34911a5 100644 --- a/app/Data/Users/UserData.php +++ b/app/Data/Users/UserData.php @@ -4,9 +4,19 @@ namespace App\Data\Users; -use Spatie\LaravelData\Data; +use App\Data\Ui\ManageRoles\RoleData; +use Spatie\LaravelData\Attributes\DataCollectionOf; +use Spatie\LaravelData\{Data, DataCollection}; final class UserData extends Data { - public function __construct(public string $name, public string $email) {} + public function __construct( + public string $name, + public string $email, + public bool $active = false, + + /** @var DataCollection|null */ + #[DataCollectionOf(class: RoleData::class)] + public ?DataCollection $roles = null, + ) {} } diff --git a/app/Providers/ScopeServiceProvider.php b/app/Providers/DirectiveServiceProvider.php similarity index 81% rename from app/Providers/ScopeServiceProvider.php rename to app/Providers/DirectiveServiceProvider.php index 392d750..4d1e09e 100644 --- a/app/Providers/ScopeServiceProvider.php +++ b/app/Providers/DirectiveServiceProvider.php @@ -7,7 +7,7 @@ use Illuminate\Support\{Arr, ServiceProvider}; use Illuminate\Support\Facades\Blade; -final class ScopeServiceProvider extends ServiceProvider +final class DirectiveServiceProvider extends ServiceProvider { /** * Bootstrap services. @@ -15,9 +15,19 @@ final class ScopeServiceProvider extends ServiceProvider public function boot(): void { $this->registerScopeDirective(); + $this->registerInitialsDirective(); } - public function registerScopeDirective(): void + private function registerInitialsDirective(): void + { + Blade::directive('initials', fn ($expression) => ""); + } + + private function registerScopeDirective(): void { /** * All credits from this blade directive goes to Konrad Kalemba. diff --git a/app/View/Components/Table.php b/app/View/Components/Table.php index 8a34bfd..972120a 100644 --- a/app/View/Components/Table.php +++ b/app/View/Components/Table.php @@ -23,7 +23,7 @@ public function __construct( public bool $withPagination = false, public array $rowDecoration = [], public array $cellDecoration = [], - public bool $showEmptyText = false, + public bool $showEmptyText = true, public string $emptyText = 'No records found.', public string $containerClass = 'relative overflow-x-auto rounded-2xl -pb-2', public bool $noHover = false, @@ -173,6 +173,7 @@ public function render(): View|Closure|string + @isset($rows) @foreach($rows as $k => $row) @endforeach - + @endisset @isset ($footer) - @if(count($rows) === 0) + @if(!$rows || count($rows) === 0) @if($showEmptyText)
{{ $emptyText }} diff --git a/bootstrap/providers.php b/bootstrap/providers.php index 7b0123d..6e73c74 100644 --- a/bootstrap/providers.php +++ b/bootstrap/providers.php @@ -5,5 +5,5 @@ return [ App\Providers\AppServiceProvider::class, App\Providers\FortifyServiceProvider::class, - App\Providers\ScopeServiceProvider::class, + App\Providers\DirectiveServiceProvider::class, ]; diff --git a/resources/views/components/dashboard/roles/⚡manager.blade.php b/resources/views/components/dashboard/roles/⚡manager.blade.php index 61e485c..d65b003 100644 --- a/resources/views/components/dashboard/roles/⚡manager.blade.php +++ b/resources/views/components/dashboard/roles/⚡manager.blade.php @@ -85,11 +85,7 @@ public function mount(): void @php /** @var RoleData $role */ @endphp
@foreach($role->users as $user) - - - {{implode('', array_map(fn($w) => strtoupper($w[0]), explode(' ', $user->name)))}} - - + @endforeach
@endscope diff --git a/resources/views/components/dashboard/users/⚡assignments.blade.php b/resources/views/components/dashboard/users/⚡assignments.blade.php new file mode 100644 index 0000000..a6e31ba --- /dev/null +++ b/resources/views/components/dashboard/users/⚡assignments.blade.php @@ -0,0 +1,138 @@ + */ + #[DataCollectionOf(TableHeader::class)] + public DataCollection $header; + + /** @var DataCollection|null */ + #[DataCollectionOf(UserData::class)] + public ?DataCollection $users = null; + + public function mount(): void + { + $this->header = TableHeader::collect([ + new TableHeader('name', 'User'), + new TableHeader('role.name', 'Role'), + new TableHeader('role.service', 'Service Access'), + new TableHeader('status', 'Status'), + ], DataCollection::class); + + $this->users = UserData::collect([ + new UserData( + name: 'Priya Rao', + email: 'priya@example.com', + active: true, + roles: RoleData::collect([ + new RoleData( + name: 'Super Admin', + users: UserData::collect([], DataCollection::class), + services: ServiceData::collect([ + new ServiceData(name: 'AWS Core'), + new ServiceData(name: 'GitHub Enterprise'), + ], DataCollection::class), + status: RolesStatus::Active, + ), + new RoleData( + name: 'HR Manager', + users: UserData::collect([], DataCollection::class), + services: ServiceData::collect([ + new ServiceData(name: 'Keka'), + new ServiceData(name: 'Outlook'), + ], DataCollection::class), + status: RolesStatus::Active, + ) + ], DataCollection::class) + ), + + new UserData( + name: 'Kushal Saha', + email: 'kushal@example.com', + active: true, + roles: RoleData::collect([ + new RoleData( + name: 'Backend Developer', + users: UserData::collect([], DataCollection::class), + services: ServiceData::collect([ + new ServiceData(name: 'Forge'), + ], DataCollection::class), + status: RolesStatus::Active, + ) + ], DataCollection::class) + ), + + new UserData( + name: 'Alex Johnson', + email: 'alex@example.com', + active: false, + roles: RoleData::collect([ + new RoleData( + name: 'Guest Viewer', + users: UserData::collect([], DataCollection::class), + services: ServiceData::collect([ + new ServiceData(name: 'Analytics Dashboard'), + ], DataCollection::class), + status: RolesStatus::Active, + ) + ], DataCollection::class) + ) + ], DataCollection::class); + } +}; +?> + +
+ + + + {{ __('Assign user') }} + + + + + @scope('cell_name', $row) + + @endscope + @scope('cell_role.name', $row) +
+ @foreach ($row->roles as $role) + + {{$role->name}} + + @endforeach +
+ @endscope + + @scope('cell_role.service', $row) +
+ @foreach ($row->roles as $role) + @foreach($role->services as $service) + {{$service->name}}, + @endforeach + @endforeach +
+ @endscope + + @scope('cell_status', $row) + @if($row->active) + Active + @else + Not Active + @endif + @endscope + + @scope('actions', $row) + + @endscope +
+
+
diff --git a/resources/views/components/shared/avatar.blade.php b/resources/views/components/shared/avatar.blade.php index 6d92360..0d3caa4 100644 --- a/resources/views/components/shared/avatar.blade.php +++ b/resources/views/components/shared/avatar.blade.php @@ -1,3 +1,18 @@ -twMerge(['class' => 'bg-blue-300 w-8 h-8 border border-white rounded-full flex items-center justify-center'])}}> - {{$slot}} +@props(['placeholder', 'title', 'subtitle']) +
+twMerge(['class' => 'bg-blue-300 text-blue-800 w-8 h-8 border border-white rounded-full flex items-center justify-center'])}}> + @isset($placeholder) + @initials($placeholder) + @endisset +
+ @isset($title) +

+ {{$title}} +

+ @endisset + @isset($subtitle) + {{$subtitle}} + @endisset +
+
diff --git a/resources/views/pages/⚡dashboard.blade.php b/resources/views/pages/⚡dashboard.blade.php index 17ec168..62f984f 100644 --- a/resources/views/pages/⚡dashboard.blade.php +++ b/resources/views/pages/⚡dashboard.blade.php @@ -18,5 +18,6 @@ class extends Component { +