Major UI refresh on the nav-design-improvements branch. Drops 2013-era
inline styles and consolidates patterns behind shared primitives.
Foundation
- New Wulf brand layer in app/styles/brand.css repointing --primary to
the standards-guide blue (#0075AD) with utility classes for numerics
(.num / .num-lg / .num-xl), metric labels, surface tints, and the
wolf-mark watermark
- Switch primary face to IBM Plex Sans + IBM Plex Mono via next/font;
Helvetica/Arial stays in the fallback chain for brand fidelity
- Wordmark subtitle changed from "PSA Management System" to
"Operations console" everywhere it appeared
- Tagline footer ("Don't be afraid to cry") on every non-mobile page
Status moved out of /dashboard
- New /status route with integration tiles grouped by category, sync
health table, worker pulse cards (analyzer / RMM / sync scheduler),
token-expiry section, conditional alert banner
- Top-bar StatusIndicator polls integration health every 60s and links
to /status
- INTEGRATIONS_DISABLED env var suppresses operator-disabled
integrations (e.g. SentinelOne) — no failure noise from broken-on-
purpose entries. Aliases supported (sentinelone → s1, etc.)
Dashboard rebuilt around KPIs
- /api/dashboard/overview adds today snapshot (opened, resolved, open
total, SLA breaches) with delta math
- /api/dashboard/trends backs queue × priority heatmap, 30-day volume
area chart, 30-day mean resolution time line chart, today's active
engineers leaderboard
Components
- StatusBadge driven by lib/status-registry.ts (priority, ticket
status, classification, source, company type, publish, active /
yes-no / billable / approved registries)
- StatusLight (8px geometric square, five states, three sizes)
- EmptyState (shared dashed panel with icon + headline + optional CTA)
- KpiCard with delta indicator and tonal left border
- WulfMark (mark / wordmark variants from /public/branding)
- Skeleton helpers (SkeletonRow / Rows / Card / Chart / Header / Table)
Navigation
- Admin flat link → dropdown with seven shortcuts
- New UserMenu (initials avatar, role badge, settings + sign-out)
- Active-route highlight is now a 2px Wulf-blue underline echoing the
PageHeader rule (consistent across flat links and submenu triggers);
active children inside dropdowns use bg-primary/10
- Submenu width is content-driven (min-w 320 / max-w 440, single col)
- Mobile hamburger via Sheet, reuses the same nav config
Pages migrated
- 16 admin sub-pages adopt PageHeader (with accent prop)
- /addigy-devices: shadcn Table + Checkbox; PageHeader; status badges
- 10 raw <table> blocks across admin/sync/* migrated to shadcn Table
- /veeam-analysis migrated to shadcn Table (kept its expansion logic)
- Detail routes (analyzer ticket, analyzer analysis) get breadcrumbs
DataTable
- Rewritten on @tanstack/react-table v8 in manual mode; external API
unchanged so all 10+ data-browser pages keep working
- New optional props for drill-down rows: getRowCanExpand + renderSubRow
Mobile
- Multi-select Popover gets max-w-[calc(100vw-1rem)] and
collisionPadding so dropdowns can't overflow narrow viewports
- CI filter bar wraps and shrinks; stat pill flows below
Docs
- New ARCHITECTURE.md (load-bearing reference for runtime, data flow,
workers, analyzer pipeline, auth, deployment, gotchas)
- New DESIGN.md (tokens, layout, navigation IA, component vocabulary,
rolling backlog of remaining cleanup)
- CLAUDE.md refreshed with pointers to the two new docs and the
INTEGRATIONS_DISABLED operator config note
- shadcn registry registered as project-level MCP server (.mcp.json)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
249 lines
9.1 KiB
TypeScript
249 lines
9.1 KiB
TypeScript
'use client';
|
|
|
|
import { useState, useEffect, useCallback, Suspense } from 'react';
|
|
import { useSearchParams } from 'next/navigation';
|
|
import { Button } from '@/components/ui/button';
|
|
import {
|
|
CheckCircle2, XCircle, AlertTriangle, RefreshCw, Loader2,
|
|
Link2, Link2Off, FileText, CreditCard, Building2, ArrowDownToLine, BarChart3,
|
|
} from 'lucide-react';
|
|
import { PageHeader } from '@/components/navigation/page-header';
|
|
|
|
interface QboStatus {
|
|
tokenStatus: 'valid' | 'expired' | 'missing';
|
|
counts: {
|
|
invoices: number;
|
|
payments: number;
|
|
deposits: number;
|
|
transactions: number;
|
|
reports: number;
|
|
};
|
|
lastSync: {
|
|
invoices: string | null;
|
|
payments: string | null;
|
|
deposits: string | null;
|
|
transactions: string | null;
|
|
reports: string | null;
|
|
};
|
|
}
|
|
|
|
function fmtDate(d: string | null) {
|
|
if (!d) return 'Never';
|
|
const date = new Date(d);
|
|
const diff = Date.now() - date.getTime();
|
|
const mins = Math.floor(diff / 60000);
|
|
if (mins < 1) return 'Just now';
|
|
if (mins < 60) return `${mins}m ago`;
|
|
const hrs = Math.floor(mins / 60);
|
|
if (hrs < 24) return `${hrs}h ago`;
|
|
return `${Math.floor(hrs / 24)}d ago`;
|
|
}
|
|
|
|
function fmtNum(n: number) {
|
|
return n.toLocaleString();
|
|
}
|
|
|
|
const ENTITY_META = [
|
|
{ key: 'invoices', label: 'Invoices', icon: FileText, color: 'text-blue-400' },
|
|
{ key: 'payments', label: 'Payments', icon: CreditCard, color: 'text-green-400' },
|
|
{ key: 'deposits', label: 'Deposits', icon: Building2, color: 'text-purple-400' },
|
|
{ key: 'transactions', label: 'Transactions', icon: ArrowDownToLine, color: 'text-orange-400' },
|
|
{ key: 'reports', label: 'Reports', icon: BarChart3, color: 'text-cyan-400' },
|
|
] as const;
|
|
|
|
function QboPageInner() {
|
|
const searchParams = useSearchParams();
|
|
const connected = searchParams.get('connected');
|
|
const disconnected = searchParams.get('disconnected');
|
|
const errorParam = searchParams.get('error');
|
|
|
|
const [status, setStatus] = useState<QboStatus | null>(null);
|
|
const [loading, setLoading] = useState(true);
|
|
const [syncing, setSyncing] = useState(false);
|
|
const [syncMessage, setSyncMessage] = useState<string | null>(null);
|
|
const [banner, setBanner] = useState<{ type: 'success' | 'error' | 'info'; msg: string } | null>(null);
|
|
|
|
const fetchStatus = useCallback(async () => {
|
|
setLoading(true);
|
|
try {
|
|
const res = await fetch('/api/qbo/sync');
|
|
const data = await res.json();
|
|
setStatus(data);
|
|
} catch {
|
|
setStatus(null);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
fetchStatus();
|
|
}, [fetchStatus]);
|
|
|
|
useEffect(() => {
|
|
if (connected === 'true') setBanner({ type: 'success', msg: 'QuickBooks Online connected successfully.' });
|
|
else if (disconnected === 'true') setBanner({ type: 'info', msg: 'QuickBooks Online disconnected.' });
|
|
else if (errorParam) setBanner({ type: 'error', msg: decodeURIComponent(errorParam) });
|
|
}, [connected, disconnected, errorParam]);
|
|
|
|
async function triggerSync(syncType: 'full' | 'incremental') {
|
|
setSyncing(true);
|
|
setSyncMessage(null);
|
|
try {
|
|
const res = await fetch('/api/qbo/sync', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ syncType, triggeredBy: 'admin-ui' }),
|
|
});
|
|
const data = await res.json();
|
|
if (res.ok) {
|
|
setSyncMessage(`${syncType === 'full' ? 'Full' : 'Incremental'} sync started. This may take a few minutes.`);
|
|
setTimeout(() => fetchStatus(), 10000);
|
|
setTimeout(() => fetchStatus(), 30000);
|
|
setTimeout(() => { fetchStatus(); setSyncing(false); }, 60000);
|
|
} else {
|
|
setSyncMessage(`Error: ${data.error}`);
|
|
setSyncing(false);
|
|
}
|
|
} catch (err) {
|
|
setSyncMessage(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
setSyncing(false);
|
|
}
|
|
}
|
|
|
|
const tokenOk = status?.tokenStatus === 'valid';
|
|
const tokenBadge = {
|
|
valid: { icon: CheckCircle2, label: 'Connected', cls: 'text-green-400' },
|
|
expired: { icon: AlertTriangle, label: 'Token Expired', cls: 'text-yellow-400' },
|
|
missing: { icon: XCircle, label: 'Not Connected', cls: 'text-red-400' },
|
|
}[status?.tokenStatus ?? 'missing'];
|
|
|
|
return (
|
|
<>
|
|
<PageHeader
|
|
title="QuickBooks Online"
|
|
description="Sync invoices, payments, deposits, transactions and financial reports"
|
|
breadcrumbs={[{ label: 'Admin', href: '/admin' }, { label: 'QuickBooks Online' }]}
|
|
accent
|
|
actions={
|
|
<Button variant="outline" size="sm" onClick={fetchStatus} disabled={loading}>
|
|
<RefreshCw className={`w-4 h-4 mr-2 ${loading ? 'animate-spin' : ''}`} />
|
|
Refresh
|
|
</Button>
|
|
}
|
|
/>
|
|
<div className="p-6 max-w-4xl mx-auto space-y-6">
|
|
{/* Banner */}
|
|
{banner && (
|
|
<div className={`flex items-center gap-3 px-4 py-3 rounded-lg border text-sm ${
|
|
banner.type === 'success' ? 'bg-green-500/10 border-green-500/30 text-green-300' :
|
|
banner.type === 'error' ? 'bg-red-500/10 border-red-500/30 text-red-300' :
|
|
'bg-blue-500/10 border-blue-500/30 text-blue-300'
|
|
}`}>
|
|
{banner.type === 'success' ? <CheckCircle2 className="w-4 h-4 shrink-0" /> :
|
|
banner.type === 'error' ? <XCircle className="w-4 h-4 shrink-0" /> :
|
|
<AlertTriangle className="w-4 h-4 shrink-0" />}
|
|
{banner.msg}
|
|
<button className="ml-auto opacity-60 hover:opacity-100" onClick={() => setBanner(null)}>✕</button>
|
|
</div>
|
|
)}
|
|
|
|
{/* Connection Status */}
|
|
<div className="rounded-xl border bg-card p-5 space-y-4">
|
|
<div className="flex items-center justify-between">
|
|
<h2 className="font-semibold text-base">Connection Status</h2>
|
|
{loading ? (
|
|
<Loader2 className="w-4 h-4 animate-spin text-muted-foreground" />
|
|
) : (
|
|
<div className={`flex items-center gap-1.5 text-sm font-medium ${tokenBadge.cls}`}>
|
|
<tokenBadge.icon className="w-4 h-4" />
|
|
{tokenBadge.label}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex gap-3 flex-wrap">
|
|
<a href="/api/qbo/auth">
|
|
<Button variant="outline" size="sm" className="gap-2">
|
|
<Link2 className="w-4 h-4" />
|
|
{tokenOk ? 'Reconnect' : 'Connect to QuickBooks'}
|
|
</Button>
|
|
</a>
|
|
{tokenOk && (
|
|
<a href="/api/qbo/disconnect">
|
|
<Button variant="outline" size="sm" className="gap-2 text-red-400 border-red-500/30 hover:bg-red-500/10">
|
|
<Link2Off className="w-4 h-4" />
|
|
Disconnect
|
|
</Button>
|
|
</a>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Sync Controls */}
|
|
<div className="rounded-xl border bg-card p-5 space-y-4">
|
|
<h2 className="font-semibold text-base">Sync</h2>
|
|
<div className="flex gap-3 flex-wrap">
|
|
<Button
|
|
onClick={() => triggerSync('full')}
|
|
disabled={syncing || !tokenOk}
|
|
size="sm"
|
|
className="gap-2"
|
|
>
|
|
{syncing ? <Loader2 className="w-4 h-4 animate-spin" /> : <RefreshCw className="w-4 h-4" />}
|
|
Full Sync
|
|
</Button>
|
|
<Button
|
|
onClick={() => triggerSync('incremental')}
|
|
disabled={syncing || !tokenOk}
|
|
variant="outline"
|
|
size="sm"
|
|
className="gap-2"
|
|
>
|
|
{syncing ? <Loader2 className="w-4 h-4 animate-spin" /> : <RefreshCw className="w-4 h-4" />}
|
|
Incremental Sync
|
|
</Button>
|
|
</div>
|
|
{syncMessage && (
|
|
<p className="text-sm text-muted-foreground">{syncMessage}</p>
|
|
)}
|
|
</div>
|
|
|
|
{/* Entity Counts */}
|
|
<div className="rounded-xl border bg-card p-5 space-y-4">
|
|
<h2 className="font-semibold text-base">Synced Data</h2>
|
|
{loading ? (
|
|
<div className="flex items-center gap-2 text-muted-foreground text-sm">
|
|
<Loader2 className="w-4 h-4 animate-spin" /> Loading...
|
|
</div>
|
|
) : (
|
|
<div className="grid grid-cols-2 sm:grid-cols-3 gap-4">
|
|
{ENTITY_META.map(({ key, label, icon: Icon, color }) => (
|
|
<div key={key} className="flex items-center gap-3 p-3 rounded-lg bg-muted/30 border border-border">
|
|
<Icon className={`w-5 h-5 shrink-0 ${color}`} />
|
|
<div>
|
|
<div className="text-lg font-semibold leading-none">
|
|
{fmtNum(status?.counts[key] ?? 0)}
|
|
</div>
|
|
<div className="text-xs text-muted-foreground mt-0.5">{label}</div>
|
|
<div className="text-xs text-muted-foreground/60 mt-0.5">
|
|
{fmtDate(status?.lastSync[key] ?? null)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default function QboAdminPage() {
|
|
return (
|
|
<Suspense fallback={<div className="p-6 text-muted-foreground text-sm">Loading...</div>}>
|
|
<QboPageInner />
|
|
</Suspense>
|
|
);
|
|
}
|