mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-12-01 09:37:12 +09:00
## Summary UX/UI overhaul of the admin pages, focused on the most-used surfaces (dashboard, jobs list/detail, users list/detail), fixing reported overflow bugs and making everything usable on mobile. ### Job detail page (`/admin/jobs?id=...`) - **Status timeline**: long timelines (retries/edits) collapse to the last 6 stages behind a `+N earlier (M failed)` expander chip, with a Collapse chip when expanded; resets when switching jobs - **Source field overflow fixed**: info-grid cells get `min-w-0` so long source strings truncate instead of bleeding across Created/Progress/Total Time - **Audio Source Details modal**: rebuilt with stacked wrap-safe rows (no clipped values), scrollable, plus a prominent "Open in YouTube/Spotify" link built from provider + source ID - **Configuration fields**: click-to-edit values with always-visible pencil (was hover-only); empty values show "— click to set" - **Bug fix**: "Trigger Now" in the reset-result dialog called a deleted `handleTriggerWorker` (runtime crash); reimplemented via `adminApi.triggerWorker` - 404 job load no longer shows a redundant error toast (also fixes a pre-existing flaky e2e) - Skips loading the 100-job list while viewing a single job - `generating_screens` status gets a label + filter option ### Jobs list - Search box jumps straight to the detail page when given a job ID - Status filter synced to URL (`?status=failed` is shareable/linkable) - Compact created dates; User/Progress/Created columns hidden on small screens ### Dashboard - Stat cards link to their pages; Job Status Breakdown rows link to the pre-filtered jobs list ### Users list/detail + layout - Responsive columns, truncation-safe email cells, mobile-stacking detail header, break-all for long emails/fingerprints - Breadcrumb shows "User Detail" instead of raw "detail" segment; header no longer overflows on phones ## Testing - 4 new e2e tests (timeline collapse/expand, short-timeline no-collapse, provider link from source ID, job-ID search jump); full admin-job-detail spec 28/28 passing - Full regression e2e suite: 171 passed; frontend unit tests: 1132 passed - Visually verified at 1280px and 390px widths with mocked-API renders (worst-case long timeline + long source strings) @coderabbitai ignore 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
170 lines
5.2 KiB
TypeScript
170 lines
5.2 KiB
TypeScript
"use client"
|
|
|
|
import React, { useEffect, useState } from "react"
|
|
import { useRouter } from "next/navigation"
|
|
import { getAccessToken } from "@/lib/api"
|
|
import { useAuth } from "@/lib/auth"
|
|
import { useAdminSettings } from "@/lib/admin-settings"
|
|
import { Loader2 } from "lucide-react"
|
|
import { SidebarProvider, SidebarInset, SidebarTrigger } from "@/components/ui/sidebar"
|
|
import { AdminSidebar } from "@/components/admin/admin-sidebar"
|
|
import { Separator } from "@/components/ui/separator"
|
|
import { Switch } from "@/components/ui/switch"
|
|
import { Label } from "@/components/ui/label"
|
|
import {
|
|
Breadcrumb,
|
|
BreadcrumbItem,
|
|
BreadcrumbLink,
|
|
BreadcrumbList,
|
|
BreadcrumbPage,
|
|
BreadcrumbSeparator,
|
|
} from "@/components/ui/breadcrumb"
|
|
import { usePathname } from "next/navigation"
|
|
|
|
function AdminBreadcrumb() {
|
|
const pathname = usePathname()
|
|
|
|
const getBreadcrumbs = () => {
|
|
const segments = pathname.split("/").filter(Boolean)
|
|
const breadcrumbs: { label: string; href?: string }[] = []
|
|
|
|
// Always start with Admin
|
|
if (segments[0] === "admin") {
|
|
if (segments.length === 1) {
|
|
breadcrumbs.push({ label: "Dashboard" })
|
|
} else {
|
|
breadcrumbs.push({ label: "Admin", href: "/admin" })
|
|
|
|
if (segments[1] === "users") {
|
|
if (segments.length === 2) {
|
|
breadcrumbs.push({ label: "Users" })
|
|
} else {
|
|
breadcrumbs.push({ label: "Users", href: "/admin/users" })
|
|
breadcrumbs.push({
|
|
label: segments[2] === "detail" ? "User Detail" : decodeURIComponent(segments[2]),
|
|
})
|
|
}
|
|
} else if (segments[1] === "jobs") {
|
|
if (segments.length === 2) {
|
|
breadcrumbs.push({ label: "Jobs" })
|
|
} else if (segments[2]) {
|
|
breadcrumbs.push({ label: "Jobs", href: "/admin/jobs" })
|
|
breadcrumbs.push({ label: decodeURIComponent(segments[2]) })
|
|
}
|
|
} else if (segments[1] === "searches") {
|
|
breadcrumbs.push({ label: "Audio Searches" })
|
|
} else if (segments[1] === "abuse") {
|
|
breadcrumbs.push({ label: "Abuse Investigation" })
|
|
} else {
|
|
// Fallback: prettify the URL segment (payments, referrals, rate-limits, ...)
|
|
breadcrumbs.push({
|
|
label: segments[1]
|
|
.split("-")
|
|
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
|
|
.join(" "),
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
return breadcrumbs
|
|
}
|
|
|
|
const breadcrumbs = getBreadcrumbs()
|
|
|
|
return (
|
|
<Breadcrumb>
|
|
<BreadcrumbList>
|
|
{breadcrumbs.map((crumb, index) => (
|
|
<React.Fragment key={`${crumb.href || ''}-${crumb.label}`}>
|
|
{index > 0 && <BreadcrumbSeparator />}
|
|
<BreadcrumbItem>
|
|
{crumb.href ? (
|
|
<BreadcrumbLink href={crumb.href}>{crumb.label}</BreadcrumbLink>
|
|
) : (
|
|
<BreadcrumbPage>{crumb.label}</BreadcrumbPage>
|
|
)}
|
|
</BreadcrumbItem>
|
|
</React.Fragment>
|
|
))}
|
|
</BreadcrumbList>
|
|
</Breadcrumb>
|
|
)
|
|
}
|
|
|
|
export default function AdminLayout({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode
|
|
}) {
|
|
const router = useRouter()
|
|
const { user } = useAuth()
|
|
const [isChecking, setIsChecking] = useState(true)
|
|
// IMPORTANT: All hooks must be called before any conditional returns
|
|
// to satisfy React's Rules of Hooks
|
|
const { showTestData, setShowTestData } = useAdminSettings()
|
|
|
|
useEffect(() => {
|
|
const token = getAccessToken()
|
|
if (!token) {
|
|
router.replace("/")
|
|
return
|
|
}
|
|
|
|
// Check if user is admin (either by role or @nomadkaraoke.com email)
|
|
if (user) {
|
|
const isAdmin = user.role === "admin" || user.email?.endsWith("@nomadkaraoke.com")
|
|
if (!isAdmin) {
|
|
router.replace("/app")
|
|
return
|
|
}
|
|
}
|
|
|
|
// If we have a token but no user yet, wait for auth to load
|
|
if (!user) {
|
|
return
|
|
}
|
|
|
|
setIsChecking(false)
|
|
}, [router, user])
|
|
|
|
// Show loading while checking auth
|
|
if (isChecking || !user) {
|
|
return (
|
|
<div
|
|
className="min-h-screen flex items-center justify-center"
|
|
style={{ background: "var(--bg)" }}
|
|
>
|
|
<Loader2 className="w-8 h-8 animate-spin" style={{ color: "var(--text-muted)" }} />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<SidebarProvider>
|
|
<AdminSidebar />
|
|
<SidebarInset>
|
|
<header className="flex h-16 shrink-0 items-center gap-2 border-b px-4">
|
|
<SidebarTrigger className="-ml-1" />
|
|
<Separator orientation="vertical" className="mr-2 h-4" />
|
|
<div className="min-w-0 overflow-hidden">
|
|
<AdminBreadcrumb />
|
|
</div>
|
|
<div className="ml-auto flex items-center gap-2 shrink-0">
|
|
<Switch
|
|
id="show-test-data"
|
|
checked={showTestData}
|
|
onCheckedChange={setShowTestData}
|
|
/>
|
|
<Label htmlFor="show-test-data" className="text-sm text-muted-foreground cursor-pointer whitespace-nowrap">
|
|
<span className="hidden sm:inline">Show test data</span>
|
|
<span className="sm:hidden">Test data</span>
|
|
</Label>
|
|
</div>
|
|
</header>
|
|
<main className="flex-1 p-4 md:p-6 min-w-0 overflow-hidden">{children}</main>
|
|
</SidebarInset>
|
|
</SidebarProvider>
|
|
)
|
|
}
|