40b99f3add
Deploy / deploy (push) Successful in 3m19s
At phone width the sidebar stayed 240px wide, leaving pages a ~135px strip. Below md it is now hidden behind a menu button in the header and opens as a drawer (closes on navigation, backdrop, X or Escape); from md up the sidebar is unchanged. Page wrappers use p-4 on phones and keep p-6/p-8 from md. Shot detail: on phones the thumbnail takes the full width with the details below it instead of pushing them off screen, the action buttons wrap, and the tab bar scrolls sideways. Desktop sizing is kept as it was. Every change is behind a md: breakpoint, so the desktop layout is the same. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
257 lines
8.4 KiB
TypeScript
257 lines
8.4 KiB
TypeScript
import { auth } from "@/auth";
|
|
import { db } from "@/lib/db";
|
|
import { StatsCards } from "@/components/dashboard/StatsCards";
|
|
import { BlockedQueue } from "@/components/dashboard/BlockedQueue";
|
|
import { FarmStrip } from "@/components/dashboard/FarmStrip";
|
|
import { DeliveryCountdown } from "@/components/dashboard/DeliveryCountdown";
|
|
import { QcQueue } from "@/components/dashboard/QcQueue";
|
|
import { RecentDeliveries } from "@/components/dashboard/RecentDeliveries";
|
|
import { WhoseCourt } from "@/components/dashboard/WhoseCourt";
|
|
import { ShotQueue } from "@/components/dashboard/ShotQueue";
|
|
import { TaskWidgets } from "@/components/dashboard/TaskWidgets";
|
|
import { ScheduleWidgets } from "@/components/dashboard/ScheduleWidgets";
|
|
import {
|
|
getBlockedExports,
|
|
getDeliveryCountdown,
|
|
getFarmStatus,
|
|
getOpsCounts,
|
|
getQcQueue,
|
|
getQcStaleHours,
|
|
getRecentDeliveries,
|
|
getWhoseCourt,
|
|
} from "@/lib/dashboard/ops";
|
|
import type { DashboardStats } from "@/types";
|
|
|
|
export const metadata = { title: "Dashboard" };
|
|
|
|
// Queue depth and machine state are stale the moment they are cached.
|
|
export const dynamic = "force-dynamic";
|
|
|
|
/**
|
|
* The dashboard answers one question: can we ship what is due, and what is
|
|
* stopping us? Everything on it is pipeline state — exports, QC, deliveries,
|
|
* worker heartbeats — rather than anything a person has to maintain by hand.
|
|
*/
|
|
async function getDashboardData(userId: string, role: string) {
|
|
const isArtist = role === "ARTIST";
|
|
const isClient = role === "CLIENT";
|
|
|
|
// Producers see the floor; an artist sees the failures that are theirs.
|
|
const [counts, blocked, farm, episodes, qcQueue, qcStaleHours, deliveries, court] =
|
|
await Promise.all([
|
|
getOpsCounts(isArtist ? userId : undefined),
|
|
getBlockedExports(isArtist ? { artistId: userId } : {}),
|
|
getFarmStatus(),
|
|
getDeliveryCountdown(),
|
|
isArtist || isClient ? [] : getQcQueue(),
|
|
getQcStaleHours(),
|
|
isArtist || isClient ? [] : getRecentDeliveries(),
|
|
isArtist || isClient ? null : getWhoseCourt(),
|
|
]);
|
|
|
|
// An artist's own shots come first; everyone else sees the floor.
|
|
const shots = await db.shot.findMany({
|
|
where: {
|
|
...(isArtist ? { artistId: userId } : {}),
|
|
status: { not: "COMPLETE" },
|
|
project: { status: { in: ["ACTIVE", "ON_HOLD"] } },
|
|
},
|
|
take: 15,
|
|
orderBy: [{ dueDate: { sort: "asc", nulls: "last" } }, { updatedAt: "desc" }],
|
|
include: {
|
|
artist: { select: { id: true, name: true, image: true, email: true } },
|
|
versions: {
|
|
take: 1,
|
|
orderBy: { versionNumber: "desc" },
|
|
include: { comments: { select: { id: true, isResolved: true } } },
|
|
},
|
|
},
|
|
});
|
|
|
|
const myTasks = await db.task.findMany({
|
|
where: { assignedArtistId: userId, status: { not: "DONE" } },
|
|
take: 8,
|
|
orderBy: [{ dueDate: "asc" }, { priority: "desc" }],
|
|
include: {
|
|
shot: { select: { shotCode: true } },
|
|
asset: { select: { assetCode: true } },
|
|
project: { select: { id: true, name: true, code: true } },
|
|
},
|
|
});
|
|
|
|
const reviewTasks = isArtist || isClient ? [] : await db.task.findMany({
|
|
where: { status: { in: ["INTERNAL_REVIEW", "CLIENT_REVIEW"] } },
|
|
take: 8,
|
|
orderBy: { updatedAt: "desc" },
|
|
include: {
|
|
shot: { select: { shotCode: true } },
|
|
asset: { select: { assetCode: true } },
|
|
project: { select: { id: true, name: true, code: true } },
|
|
assignedArtist: { select: { id: true, name: true, image: true, email: true } },
|
|
},
|
|
});
|
|
|
|
// Schedule overview (producers/supervisors/admins) — unchanged; it reads the
|
|
// schedule page's own data rather than anything the pipeline owns.
|
|
const scheduledTasks =
|
|
!isArtist && !isClient
|
|
? await db.task.findMany({
|
|
where: { scheduledStartDate: { not: null }, status: { not: "DONE" } },
|
|
include: {
|
|
shot: { select: { shotCode: true } },
|
|
asset: { select: { assetCode: true } },
|
|
project: { select: { id: true, name: true, code: true } },
|
|
assignedArtist: {
|
|
select: { id: true, name: true, email: true, image: true },
|
|
},
|
|
},
|
|
orderBy: { scheduledStartDate: "asc" },
|
|
})
|
|
: [];
|
|
|
|
const scheduleArtists =
|
|
!isArtist && !isClient
|
|
? await db.user.findMany({
|
|
where: { isActive: true, role: { not: "CLIENT" } },
|
|
select: { id: true, name: true, email: true, image: true, role: true },
|
|
orderBy: { name: "asc" },
|
|
})
|
|
: [];
|
|
|
|
const stats: DashboardStats = counts;
|
|
|
|
return {
|
|
stats,
|
|
blocked,
|
|
farm,
|
|
episodes,
|
|
qcQueue,
|
|
qcStaleHours,
|
|
deliveries,
|
|
court,
|
|
shots,
|
|
myTasks,
|
|
reviewTasks,
|
|
scheduledTasks,
|
|
scheduleArtists,
|
|
};
|
|
}
|
|
|
|
export default async function DashboardPage() {
|
|
const session = await auth();
|
|
if (!session?.user) return null;
|
|
|
|
const isClient = session.user.role === "CLIENT";
|
|
const isArtistRole = session.user.role === "ARTIST";
|
|
const canSeeSchedule = ["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role);
|
|
const {
|
|
stats,
|
|
blocked,
|
|
farm,
|
|
episodes,
|
|
qcQueue,
|
|
qcStaleHours,
|
|
deliveries,
|
|
court,
|
|
shots,
|
|
myTasks,
|
|
reviewTasks,
|
|
scheduledTasks,
|
|
scheduleArtists,
|
|
} = await getDashboardData(session.user.id, session.user.role);
|
|
|
|
return (
|
|
<div className="p-4 md:p-8 space-y-6 max-w-[1600px] mx-auto">
|
|
<div className="mb-4">
|
|
<h1 className="text-3xl font-bold text-white">Dashboard</h1>
|
|
<p className="text-zinc-400 mt-1">
|
|
Welcome back, {session.user.name ?? session.user.email}
|
|
</p>
|
|
</div>
|
|
|
|
{!isClient && <StatsCards stats={stats} />}
|
|
|
|
{!isClient && (
|
|
<div className="space-y-3">
|
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
|
Delivery countdown
|
|
</h2>
|
|
<DeliveryCountdown episodes={episodes} />
|
|
</div>
|
|
)}
|
|
|
|
{!isClient && (
|
|
<div id="blocked" className="grid grid-cols-1 xl:grid-cols-3 gap-6 items-start scroll-mt-6">
|
|
<div className="xl:col-span-2 space-y-3">
|
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
|
{isArtistRole ? "Your blocked shots" : "Blocked — needs a human"}
|
|
</h2>
|
|
<BlockedQueue blocked={blocked} />
|
|
</div>
|
|
|
|
<div className="space-y-3">
|
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
|
Render farm
|
|
</h2>
|
|
<FarmStrip farm={farm} />
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{!isClient && !isArtistRole && (
|
|
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6 items-start">
|
|
<div className="xl:col-span-2 space-y-3">
|
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
|
QC queue
|
|
</h2>
|
|
<QcQueue entries={qcQueue} staleHours={qcStaleHours} />
|
|
</div>
|
|
|
|
<div className="space-y-6">
|
|
<div className="space-y-3">
|
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
|
Deliveries
|
|
</h2>
|
|
<RecentDeliveries deliveries={deliveries} />
|
|
</div>
|
|
{court && (
|
|
<div className="space-y-3">
|
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
|
Whose court
|
|
</h2>
|
|
<WhoseCourt court={court} />
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{!isClient && (
|
|
<TaskWidgets
|
|
myTasks={myTasks as any}
|
|
reviewTasks={reviewTasks as any}
|
|
role={session.user.role}
|
|
/>
|
|
)}
|
|
|
|
{canSeeSchedule && (
|
|
<div className="space-y-3">
|
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
|
Schedule Overview
|
|
</h2>
|
|
<ScheduleWidgets scheduledTasks={scheduledTasks as any} artists={scheduleArtists} />
|
|
</div>
|
|
)}
|
|
|
|
<div className="space-y-3">
|
|
<h2 className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
|
|
{session.user.role === "ARTIST" ? "My shots" : "Shots in flight"}
|
|
</h2>
|
|
<div className="rounded-lg border border-border bg-card p-1">
|
|
<ShotQueue shots={shots as any} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|