refactor: replace AdminPageHeader with PageShell
Migrate pages to PageShell, add global autofill styles, and update SDK/simulator page logic for server URL and state consistency.
This commit is contained in:
1 parent
fa4516b078
commit
81c5e4e2fd
24 files changed
+1238
-595
No files matched your search
@@ -1,29 +1,38 @@
|
||||
import { cn } from '@/lib/utils';
|
||||
import Link from 'next/link';
|
||||
import React from 'react';
|
||||
|
||||
interface AdminPageHeaderProps {
|
||||
title: string;
|
||||
actions?: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function AdminPageHeader({ title, actions }: AdminPageHeaderProps) {
|
||||
export function AdminPageHeader({ title, actions, className }: AdminPageHeaderProps) {
|
||||
return (
|
||||
<header className="mb-3 flex min-h-8 flex-wrap items-center justify-between gap-2 border-b border-[var(--border)] pb-2.5">
|
||||
<div className="flex min-w-0 items-center gap-1.5">
|
||||
<Link
|
||||
href="/vcon/dashboard"
|
||||
className="text-[11.5px] text-[var(--text-faint)] hover:text-[var(--text-muted)]"
|
||||
>
|
||||
Console
|
||||
</Link>
|
||||
<span className="text-[11px] text-[var(--border-strong)]" aria-hidden="true">
|
||||
/
|
||||
</span>
|
||||
<h1 className="truncate text-[13.5px] font-medium tracking-tight text-[var(--text)]">
|
||||
{title}
|
||||
</h1>
|
||||
<header
|
||||
className={cn(
|
||||
'-mx-3.5 mb-3 flex h-10 shrink-0 items-center border-b border-[var(--border)] bg-[var(--surface)] px-3.5 sm:-mx-5 sm:px-5',
|
||||
className
|
||||
)}
|
||||
>
|
||||
<div className="flex w-full max-w-[var(--console-width)] min-w-0 items-center justify-between gap-2">
|
||||
<div className="flex min-w-0 items-center gap-1.5">
|
||||
<Link
|
||||
href="/vcon/dashboard"
|
||||
className="text-[11.5px] text-[var(--text-faint)] hover:text-[var(--text-muted)]"
|
||||
>
|
||||
Console
|
||||
</Link>
|
||||
<span className="text-[11px] text-[var(--border-strong)]" aria-hidden="true">
|
||||
/
|
||||
</span>
|
||||
<h1 className="truncate text-[13px] font-medium tracking-tight text-[var(--text)]">
|
||||
{title}
|
||||
</h1>
|
||||
</div>
|
||||
{actions && <div className="flex shrink-0 items-center gap-1.5">{actions}</div>}
|
||||
</div>
|
||||
{actions && <div className="flex items-center gap-1.5">{actions}</div>}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ export const MainLayout: React.FC<MainLayoutProps> = ({
|
||||
onToggleSidebar={() => setSidebarOpen((prev) => !prev)}
|
||||
/>
|
||||
<main className="flex flex-1 min-w-0 flex-col">
|
||||
<div className="w-full max-w-[var(--console-width)] flex-1 px-3.5 py-3 sm:px-5 sm:py-3.5">
|
||||
<div className="w-full max-w-[var(--console-width)] flex-1 px-3.5 pb-4 pt-0 sm:px-5">
|
||||
{children}
|
||||
</div>
|
||||
<Footer isAdmin={true} />
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { cn } from '@/lib/utils';
|
||||
import React from 'react';
|
||||
import { AdminPageHeader } from './AdminPageHeader';
|
||||
|
||||
interface PageShellProps {
|
||||
title: string;
|
||||
actions?: React.ReactNode;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Single-Source-of-Truth Page Container for all /vcon/* Control Panel views.
|
||||
* Guarantees that AdminPageHeader, StatStrip, Panels, Settings forms, and Tables
|
||||
* share the exact same full-width container alignment and uniform vertical rhythm.
|
||||
*/
|
||||
export function PageShell({
|
||||
title,
|
||||
actions,
|
||||
children,
|
||||
className,
|
||||
}: PageShellProps) {
|
||||
return (
|
||||
<section className={cn('flex w-full min-w-0 flex-col', className)}>
|
||||
<AdminPageHeader title={title} actions={actions} className="mb-0" />
|
||||
<div className="flex w-full max-w-[var(--console-width)] min-w-0 flex-col gap-3 pt-3 [&>.stat-strip]:mb-0">
|
||||
{children}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default PageShell;
|
||||
@@ -3,6 +3,7 @@
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Icon } from '@/components/ui/Icon';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { getCached, setCached } from '@/lib/vconCache';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
@@ -12,6 +13,11 @@ interface SidebarProps {
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
interface CachedProfile {
|
||||
email?: string;
|
||||
role?: string;
|
||||
}
|
||||
|
||||
const NAVIGATION_SECTIONS = [
|
||||
{
|
||||
group: 'Main',
|
||||
@@ -41,6 +47,12 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
const pathname = usePathname();
|
||||
const [isSigningOut, setIsSigningOut] = useState(false);
|
||||
const [theme, setTheme] = useState<'dark' | 'light'>('dark');
|
||||
const [adminEmail, setAdminEmail] = useState<string>(
|
||||
() => getCached<CachedProfile>('vcon:profile', {}).email || 'Admin'
|
||||
);
|
||||
const [adminRole, setAdminRole] = useState<string>(
|
||||
() => getCached<CachedProfile>('vcon:profile', {}).role || 'Owner'
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const saved = localStorage.getItem('datastack-theme') as 'dark' | 'light' | null;
|
||||
@@ -50,6 +62,28 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
document.documentElement.classList.toggle('dark', initial === 'dark');
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const cached = getCached<CachedProfile>('vcon:profile', {});
|
||||
if (cached.email) {
|
||||
setAdminEmail(cached.email);
|
||||
if (cached.role) setAdminRole(cached.role);
|
||||
}
|
||||
|
||||
fetch('/api/auth/profile', { credentials: 'include' })
|
||||
.then((res) => (res.ok ? res.json() : null))
|
||||
.then((data) => {
|
||||
if (data?.profile?.email) {
|
||||
setCached('vcon:profile', data.profile);
|
||||
setCached('vcon:profile-loaded', true);
|
||||
setAdminEmail(data.profile.email);
|
||||
setAdminRole(data.profile.role || 'Owner');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// Keep cached or default identity label if offline
|
||||
});
|
||||
}, [pathname]);
|
||||
|
||||
const toggleTheme = () => {
|
||||
const nextTheme = theme === 'dark' ? 'light' : 'dark';
|
||||
setTheme(nextTheme);
|
||||
@@ -72,6 +106,8 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
const avatarInitial = adminEmail.trim().charAt(0).toUpperCase() || 'A';
|
||||
|
||||
return (
|
||||
<>
|
||||
{isOpen && (
|
||||
@@ -87,7 +123,7 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
isOpen ? 'translate-x-0' : '-translate-x-full'
|
||||
)}
|
||||
>
|
||||
{/* Brand Header */}
|
||||
{/* Brand Header (h-10 = 40px, aligned pixel-for-pixel with AdminPageHeader) */}
|
||||
<div className="flex h-10 shrink-0 items-center justify-between border-b border-[var(--border)] px-3">
|
||||
<Link
|
||||
href="/vcon/dashboard"
|
||||
@@ -158,23 +194,23 @@ export const Sidebar: React.FC<SidebarProps> = ({
|
||||
))}
|
||||
</nav>
|
||||
|
||||
{/* Bottom Dock: Identity + Theme Toggle + Sign Out */}
|
||||
{/* Bottom Dock: Live Admin Identity + Theme Toggle + Sign Out */}
|
||||
<div className="flex shrink-0 items-center gap-1 border-t border-[var(--border)] bg-[var(--bg)] px-2.5 py-2">
|
||||
<Link
|
||||
href="/vcon/profile"
|
||||
onClick={onClose}
|
||||
className="flex flex-1 min-w-0 items-center gap-2 hover:opacity-90"
|
||||
title="Admin Profile"
|
||||
title={`Admin Profile (${adminEmail})`}
|
||||
>
|
||||
<div className="grid h-6 w-6 shrink-0 place-items-center border border-[var(--border-strong)] bg-[var(--surface-3)] text-[10.5px] font-medium text-[var(--text)]">
|
||||
A
|
||||
{avatarInitial}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1 leading-tight">
|
||||
<div className="truncate text-[11px] font-medium text-[var(--text)]">
|
||||
Admin
|
||||
{adminEmail}
|
||||
</div>
|
||||
<div className="truncate text-[9px] uppercase tracking-wider text-[var(--text-faint)]">
|
||||
Owner
|
||||
{adminRole}
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
Reference in new issue
Block a user