Files
sencho/frontend/src/components/UserProfileDropdown.tsx
T
Anso 4f26f22cce feat: add Community/Pro licensing, fleet view, and UI reorganization (#145)
* feat: add license gating system with Lemon Squeezy integration

Add Community/Pro tier infrastructure:
- LicenseService singleton with Lemon Squeezy license API integration
- /api/license endpoints (GET info, POST activate/deactivate/validate)
- 14-day Pro trial activated automatically on first boot
- 72-hour periodic validation with 30-day offline grace period
- LicenseContext provider for frontend tier awareness
- License settings tab with activation UI and status display
- ProBadge and ProGate reusable components for feature gating
- requirePro per-route guard for backend Pro-only endpoints
- Proxy bypass for /api/license routes (local-only, never proxied)

* feat: add user profile dropdown and reorganize top navigation

- Create UserProfileDropdown component with settings, billing, theme
  toggle (System/Light/Dark), documentation links, and logout button
- Remove logout button from sidebar header
- Remove standalone settings button from top bar
- Move theme toggle from Settings modal to profile dropdown
- Inject app version via Vite define from root package.json
- Add globals.d.ts for __APP_VERSION__ type declaration

* refactor(settings): remove appearance tab from settings modal

Theme toggle was moved to the User Profile Dropdown in the previous
commit. Remove the now-redundant Appearance section, its nav button,
and the unused theme/setTheme props from SettingsModal.

* feat: add fleet view dashboard and about settings section

Fleet Overview: aggregates all nodes into a card grid showing status,
container counts, CPU/RAM/disk usage bars. Pro tier unlocks stack
drill-down with auto-refresh (30s). Backend endpoints /api/fleet/overview
and /api/fleet/node/:nodeId/stacks query nodes in parallel.

About section in Settings: displays version, license tier, status,
instance ID, and links to docs/changelog/issues.

Sidebar perf fix: stack status fetches now run in parallel via
Promise.allSettled instead of sequential for-loop, significantly
reducing load time for nodes with many stacks.

Also removes version number from User Profile Dropdown (now in About).

* fix(ci): resolve Docker build and E2E test failures

- Copy root package.json into frontend build stage so vite.config.ts
  can read the app version during Docker multi-stage build.
- Update auth E2E test: logout button moved into User Profile Dropdown.
- Update nodes E2E test: Settings button moved into User Profile Dropdown.
2026-03-25 08:32:07 -04:00

145 lines
6.4 KiB
TypeScript

import { Settings, LogOut, ExternalLink, Monitor, Sun, Moon, User } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
import { Separator } from '@/components/ui/separator';
import { useAuth } from '@/context/AuthContext';
import { useLicense } from '@/context/LicenseContext';
import { ProBadge } from './ProBadge';
type Theme = 'light' | 'dark' | 'auto';
interface UserProfileDropdownProps {
theme: Theme;
setTheme: (theme: Theme) => void;
onOpenSettings: () => void;
}
export function UserProfileDropdown({ theme, setTheme, onOpenSettings }: UserProfileDropdownProps) {
const { logout } = useAuth();
const { license, isPro } = useLicense();
return (
<Popover>
<PopoverTrigger asChild>
<Button variant="outline" size="icon" className="rounded-full w-9 h-9" title="Profile">
<User className="w-4 h-4" />
</Button>
</PopoverTrigger>
<PopoverContent className="w-64 p-0 rounded-xl" align="end" sideOffset={8}>
{/* User Info */}
<div className="px-4 py-3">
<div className="flex items-center gap-2">
<div className="w-8 h-8 rounded-full bg-muted flex items-center justify-center">
<User className="w-4 h-4 text-muted-foreground" />
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium truncate">admin</p>
<div className="flex items-center gap-1.5 text-xs text-muted-foreground">
{isPro ? <ProBadge /> : <span>Community</span>}
</div>
</div>
</div>
</div>
<Separator />
{/* Navigation Links */}
<div className="p-1">
<button
onClick={onOpenSettings}
className="flex items-center gap-2 w-full px-3 py-2 text-sm rounded-lg hover:bg-muted transition-colors text-left"
>
<Settings className="w-4 h-4 text-muted-foreground" />
Settings
</button>
{license?.status === 'active' && (
<a
href="https://sencho.io/billing"
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-2 w-full px-3 py-2 text-sm rounded-lg hover:bg-muted transition-colors"
>
<ExternalLink className="w-4 h-4 text-muted-foreground" />
Billing
</a>
)}
</div>
<Separator />
{/* Theme Toggle */}
<div className="p-3">
<p className="text-xs text-muted-foreground mb-2">Theme</p>
<div className="flex gap-1 bg-muted/50 rounded-lg p-1">
<button
onClick={() => setTheme('auto')}
className={`flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-md text-xs transition-colors ${
theme === 'auto' ? 'bg-background shadow-sm font-medium' : 'text-muted-foreground hover:text-foreground'
}`}
>
<Monitor className="w-3.5 h-3.5" />
System
</button>
<button
onClick={() => setTheme('light')}
className={`flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-md text-xs transition-colors ${
theme === 'light' ? 'bg-background shadow-sm font-medium' : 'text-muted-foreground hover:text-foreground'
}`}
>
<Sun className="w-3.5 h-3.5" />
Light
</button>
<button
onClick={() => setTheme('dark')}
className={`flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-md text-xs transition-colors ${
theme === 'dark' ? 'bg-background shadow-sm font-medium' : 'text-muted-foreground hover:text-foreground'
}`}
>
<Moon className="w-3.5 h-3.5" />
Dark
</button>
</div>
</div>
<Separator />
{/* Documentation Links */}
<div className="p-1">
<a
href="https://docs.sencho.io"
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-2 w-full px-3 py-2 text-sm rounded-lg hover:bg-muted transition-colors"
>
<ExternalLink className="w-4 h-4 text-muted-foreground" />
Documentation
</a>
<a
href="https://github.com/AnsoCode/Sencho/issues"
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-2 w-full px-3 py-2 text-sm rounded-lg hover:bg-muted transition-colors"
>
<ExternalLink className="w-4 h-4 text-muted-foreground" />
Feedback
</a>
</div>
<Separator />
{/* Logout */}
<div className="p-2">
<Button
variant="outline"
className="w-full justify-center"
onClick={logout}
>
<LogOut className="w-4 h-4 mr-2" />
Log Out
</Button>
</div>
</PopoverContent>
</Popover>
);
}