diff --git a/app/Support/UserProfileMenu.php b/app/Support/UserProfileMenu.php new file mode 100644 index 0000000..8af3f5d --- /dev/null +++ b/app/Support/UserProfileMenu.php @@ -0,0 +1,96 @@ +> */ + public static function items(?Authenticatable $user = null): array + { + $user ??= auth()->user(); + + if (! $user) { + return []; + } + + $items = []; + + foreach ([ + ['label' => 'Home', 'path' => '', 'host' => 'home'], + ['label' => 'Profile', 'path' => 'profile'], + ['label' => 'Account Settings', 'path' => 'account-settings'], + ['label' => 'Dashboard', 'path' => 'dashboard'], + ['label' => 'Billing', 'path' => 'billing'], + ] as $link) { + $items[] = [ + 'type' => 'link', + 'label' => $link['label'], + 'href' => self::platformUrl($link['host'] ?? 'account', $link['path']), + ]; + } + + if (self::userIsAdmin($user)) { + $items[] = [ + 'type' => 'link', + 'label' => 'Admin', + 'href' => self::platformUrl('account', 'admin'), + ]; + } + + if (Route::has('logout')) { + $items[] = [ + 'type' => 'logout', + 'label' => 'Logout', + 'action' => route('logout'), + ]; + } + + return $items; + } + + private static function platformUrl(string $host, string $path = ''): string + { + if ($host === 'home') { + if (function_exists('ladill_home_url')) { + return ladill_home_url($path); + } + + $domain = config('app.home_domain'); + if (! $domain) { + $platform = (string) config('app.platform_domain', parse_url((string) config('app.url', ''), PHP_URL_HOST) ?: ''); + $domain = $platform !== '' ? 'home.'.$platform : (string) config('app.account_domain'); + } + + return self::absoluteUrl((string) $domain, $path); + } + + if (function_exists('ladill_account_url')) { + return ladill_account_url($path); + } + + return self::absoluteUrl((string) config('app.account_domain'), $path); + } + + private static function absoluteUrl(string $domain, string $path = ''): string + { + $base = 'https://'.trim($domain, '/'); + + if ($path === '') { + return $base; + } + + return $base.'/'.ltrim($path, '/'); + } + + private static function userIsAdmin(Authenticatable $user): bool + { + if (method_exists($user, 'isAdmin')) { + return $user->isAdmin(); + } + + return (bool) ($user->is_admin ?? false); + } +} diff --git a/resources/views/layouts/hosting.blade.php b/resources/views/layouts/hosting.blade.php index d8b409e..29a1533 100644 --- a/resources/views/layouts/hosting.blade.php +++ b/resources/views/layouts/hosting.blade.php @@ -45,8 +45,7 @@ 'profileActive' => false, 'profileName' => $navUser?->name ?? '', 'profileSubtitle' => $navUser?->email ?? '', - 'profileMenuItems' => [ - ['type' => 'link', 'label' => 'Profile', 'href' => $navAcct.'/profile'], + 'profileMenuItems' => \App\Support\UserProfileMenu::items($navUser), ['type' => 'link', 'label' => 'Account Settings', 'href' => $navAcct.'/account-settings'], ['type' => 'logout', 'label' => 'Logout', 'action' => route('logout')], ], diff --git a/resources/views/layouts/user.blade.php b/resources/views/layouts/user.blade.php index 1a81c16..ef92ed1 100644 --- a/resources/views/layouts/user.blade.php +++ b/resources/views/layouts/user.blade.php @@ -73,8 +73,7 @@ 'profileActive' => request()->routeIs('account.settings'), 'profileName' => $navUser?->name ?? '', 'profileSubtitle' => $navUser?->email ?? '', - 'profileMenuItems' => [ - ['type' => 'link', 'label' => 'Settings', 'href' => route('account.settings')], + 'profileMenuItems' => \App\Support\UserProfileMenu::items($navUser), ['type' => 'link', 'label' => 'Account Settings', 'href' => ladill_account_url('account-settings')], ['type' => 'link', 'label' => 'Overview', 'href' => route('transfer.dashboard')], ['type' => 'logout', 'label' => 'Logout', 'action' => route('logout')], diff --git a/resources/views/partials/mobile-bottom-nav.blade.php b/resources/views/partials/mobile-bottom-nav.blade.php index c0088ca..8613313 100644 --- a/resources/views/partials/mobile-bottom-nav.blade.php +++ b/resources/views/partials/mobile-bottom-nav.blade.php @@ -11,7 +11,6 @@ if ($profileMenuItems === [] && $profileUrl !== '#') { $profileMenuItems = [['type' => 'link', 'label' => 'Profile', 'href' => $profileUrl]]; } - $searchLabel = $searchLabel ?? 'Search'; $navActive = fn (bool $active) => $active ? 'text-indigo-600' : 'text-slate-600'; @endphp
{{ $user->name ?? 'Your account' }}
+{{ $user->email }}
+