feat(deliveries): delivery requests and upload/share evidence
Deploy / deploy (push) Successful in 5m17s
Deploy / deploy (push) Successful in 5m17s
A built package used to become DELIVERED on one click with nothing behind it, and nothing recorded what a client had asked for. - Marking delivered is now two recorded steps: Record upload (the link on the client's portal, contents confirmed) then Share link (who it was sent to). The second is refused until the first is on record. - Delivery requests log a client's ask by episode, pasted shot codes or a Shot Status selection. A line closes only when its shot goes out with evidence after the request was logged; a request can otherwise only be cancelled with a reason. - Delivered Outside Pipeline takes an upload link and recipient, required for shots on an open request. - The dashboard gains an Awaiting delivery section listing open requests and built packages the client does not have yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,11 +3,14 @@
|
||||
import { useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { ArrowLeft, Package, CheckCircle2, XCircle, RefreshCw } from "lucide-react";
|
||||
import { ArrowLeft, Package, CheckCircle2, XCircle, RefreshCw, Upload } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useToast } from "@/components/ui/use-toast";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { handoffStage } from "@/lib/render-pipeline/delivery-handoff";
|
||||
import { DELIVERY_STATUS_STYLES, statusLabel } from "../status-colors";
|
||||
import { RecordShareDialog, RecordUploadDialog } from "./HandoffDialogs";
|
||||
import { RequestsPanel } from "./RequestsPanel";
|
||||
|
||||
interface ReadyExport {
|
||||
exportId: string;
|
||||
@@ -35,14 +38,25 @@ interface PackageRow {
|
||||
rootPath: string | null;
|
||||
errorMessage: string | null;
|
||||
projectName: string;
|
||||
projectCode: string;
|
||||
createdAt: string;
|
||||
builtAt: string | null;
|
||||
uploadUrl: string | null;
|
||||
uploadedAt: string | null;
|
||||
uploadedByName: string | null;
|
||||
sharedWith: string | null;
|
||||
sharedNote: string | null;
|
||||
deliveredAt: string | null;
|
||||
deliveredByName: string | null;
|
||||
itemCount: number;
|
||||
verifiedCount: number;
|
||||
exrFileCount: number;
|
||||
movCount: number;
|
||||
totalBytes: number;
|
||||
items: {
|
||||
id: string;
|
||||
shotCode: string;
|
||||
clientCode: string | null;
|
||||
versionString: string;
|
||||
status: string;
|
||||
fileCount: number | null;
|
||||
@@ -69,6 +83,7 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
||||
const [projectId, setProjectId] = useState<string>("");
|
||||
const [episode, setEpisode] = useState<string>("");
|
||||
const [building, setBuilding] = useState(false);
|
||||
const [handoff, setHandoff] = useState<{ step: "upload" | "share"; packageId: string } | null>(null);
|
||||
|
||||
const { data: projects } = useQuery({
|
||||
queryKey: ["pipeline-projects"],
|
||||
@@ -126,16 +141,23 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function packageAction(id: string, verb: "delivered" | "cancel") {
|
||||
const res = await fetch(`/api/deliveries/${id}/${verb}`, { method: "POST" });
|
||||
const body = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
toast({ title: `${verb} failed`, description: body.error ?? res.statusText, variant: "destructive" });
|
||||
}
|
||||
function refreshPackages() {
|
||||
queryClient.invalidateQueries({ queryKey: ["delivery-packages"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["delivery-ready"] });
|
||||
}
|
||||
|
||||
async function cancelPackage(id: string) {
|
||||
const res = await fetch(`/api/deliveries/${id}/cancel`, { method: "POST" });
|
||||
const body = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
toast({ title: "Cancel failed", description: body.error ?? res.statusText, variant: "destructive" });
|
||||
}
|
||||
refreshPackages();
|
||||
}
|
||||
|
||||
// Looked up from the live list so the dialog never acts on a stale row.
|
||||
const handoffPackage = handoff ? packages?.packages.find((p) => p.id === handoff.packageId) : undefined;
|
||||
|
||||
const episodes = ready?.episodes ?? [];
|
||||
const shown = episode ? episodes.filter((e) => e.episode === episode) : episodes;
|
||||
|
||||
@@ -183,6 +205,8 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
||||
)}
|
||||
</div>
|
||||
|
||||
<RequestsPanel projectId={projectId} canBuild={canBuild} />
|
||||
|
||||
{/* Ready to build */}
|
||||
{projectId && (
|
||||
<div className="rounded-lg border border-zinc-800 bg-zinc-900/40">
|
||||
@@ -238,7 +262,9 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
||||
<div className="rounded-lg border border-zinc-800 bg-zinc-900/40">
|
||||
<div className="px-4 py-2.5 border-b border-zinc-800 text-sm font-medium text-white">Packages</div>
|
||||
<div className="divide-y divide-zinc-800/60">
|
||||
{(packages?.packages ?? []).map((p) => (
|
||||
{(packages?.packages ?? []).map((p) => {
|
||||
const stage = handoffStage(p);
|
||||
return (
|
||||
<details key={p.id} className="group">
|
||||
<summary className="flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-zinc-900/60 flex-wrap">
|
||||
<span className="text-sm text-white font-medium">#{p.packageNumber}</span>
|
||||
@@ -251,10 +277,16 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
||||
<span
|
||||
className={cn(
|
||||
"rounded-full border px-2 py-0.5 text-xs",
|
||||
DELIVERY_STATUS_STYLES[p.status] ?? ""
|
||||
// Built is not delivered: a package still owed to the
|
||||
// client must not read as a green "READY".
|
||||
stage ? "bg-amber-500/15 text-amber-400 border-amber-500/30" : (DELIVERY_STATUS_STYLES[p.status] ?? "")
|
||||
)}
|
||||
>
|
||||
{statusLabel(p.status)}
|
||||
{stage === "AWAITING_UPLOAD"
|
||||
? "BUILT — NOT UPLOADED"
|
||||
: stage === "AWAITING_SHARE"
|
||||
? "UPLOADED — LINK NOT SHARED"
|
||||
: statusLabel(p.status)}
|
||||
</span>
|
||||
<span className="text-xs text-zinc-500">
|
||||
{p.episode ? `episode ${p.episode} · ` : ""}
|
||||
@@ -263,17 +295,30 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
||||
<span className="text-xs text-zinc-600">{new Date(p.createdAt).toLocaleDateString()}</span>
|
||||
{p.status === "BUILDING" && <RefreshCw className="h-3.5 w-3.5 text-blue-400 animate-spin" />}
|
||||
<span className="ml-auto flex items-center gap-2">
|
||||
{canBuild && p.status === "READY" && p.kind === "EXR_DELIVERY" && (
|
||||
{canBuild && stage === "AWAITING_UPLOAD" && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
packageAction(p.id, "delivered");
|
||||
setHandoff({ step: "upload", packageId: p.id });
|
||||
}}
|
||||
>
|
||||
<Upload className="h-4 w-4 mr-2 text-amber-400" />
|
||||
Record upload
|
||||
</Button>
|
||||
)}
|
||||
{canBuild && stage === "AWAITING_SHARE" && (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
setHandoff({ step: "share", packageId: p.id });
|
||||
}}
|
||||
>
|
||||
<CheckCircle2 className="h-4 w-4 mr-2 text-emerald-400" />
|
||||
Mark delivered
|
||||
Share link
|
||||
</Button>
|
||||
)}
|
||||
{canBuild && ["QUEUED", "FAILED", "DRAFT"].includes(p.status) && (
|
||||
@@ -282,7 +327,7 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
||||
variant="outline"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
packageAction(p.id, "cancel");
|
||||
cancelPackage(p.id);
|
||||
}}
|
||||
>
|
||||
<XCircle className="h-4 w-4 mr-2 text-red-400" />
|
||||
@@ -294,9 +339,31 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
||||
<div className="px-4 pb-4 space-y-2">
|
||||
{p.rootPath && <div className="text-xs text-zinc-500 break-all">{p.rootPath}</div>}
|
||||
{p.errorMessage && <div className="text-xs text-red-400">{p.errorMessage}</div>}
|
||||
{p.uploadedAt && p.uploadUrl && (
|
||||
<div className="text-xs text-zinc-400 break-all">
|
||||
Uploaded {new Date(p.uploadedAt).toLocaleString()}
|
||||
{p.uploadedByName ? ` by ${p.uploadedByName}` : ""} —{" "}
|
||||
<a href={p.uploadUrl} target="_blank" rel="noreferrer" className="text-sky-400 hover:underline">
|
||||
{p.uploadUrl}
|
||||
</a>
|
||||
{canBuild && stage === "AWAITING_SHARE" && (
|
||||
<button
|
||||
type="button"
|
||||
className="ml-2 text-zinc-500 hover:text-white underline"
|
||||
onClick={() => setHandoff({ step: "upload", packageId: p.id })}
|
||||
>
|
||||
change
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{p.deliveredAt && (
|
||||
<div className="text-xs text-emerald-400">
|
||||
Delivered {new Date(p.deliveredAt).toLocaleString()}
|
||||
{p.sharedWith
|
||||
? `Link shared with ${p.sharedWith} ${new Date(p.deliveredAt).toLocaleString()}`
|
||||
: `Delivered ${new Date(p.deliveredAt).toLocaleString()} — before uploads and shares were recorded`}
|
||||
{p.deliveredByName ? ` by ${p.deliveredByName}` : ""}
|
||||
{p.sharedNote ? ` — ${p.sharedNote}` : ""}
|
||||
</div>
|
||||
)}
|
||||
<div className="grid sm:grid-cols-2 lg:grid-cols-3 gap-x-6 gap-y-1">
|
||||
@@ -325,12 +392,24 @@ export function DeliveriesClient({ canBuild }: { canBuild: boolean }) {
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
{(packages?.packages ?? []).length === 0 && (
|
||||
<div className="p-4 text-sm text-zinc-500">No packages built yet</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{handoff?.step === "upload" && handoffPackage && (
|
||||
<RecordUploadDialog pkg={handoffPackage} onClose={() => setHandoff(null)} onSaved={refreshPackages} />
|
||||
)}
|
||||
{handoff?.step === "share" && handoffPackage?.uploadUrl && (
|
||||
<RecordShareDialog
|
||||
pkg={{ ...handoffPackage, uploadUrl: handoffPackage.uploadUrl }}
|
||||
onClose={() => setHandoff(null)}
|
||||
onSaved={refreshPackages}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user