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:
+35
-3
@@ -6,6 +6,7 @@ import { revalidatePath } from "next/cache";
|
||||
import { z } from "zod";
|
||||
import { ShotStatus, ShotPriority, ShotApprovalStatus, Prisma } from "@prisma/client";
|
||||
import { recalcShotStatus, markShotForRevisions } from "@/lib/shot-status";
|
||||
import { countShotsOnOpenRequests } from "@/lib/render-pipeline/delivery-requests";
|
||||
|
||||
const createShotSchema = z.object({
|
||||
scene: z.string().min(1).max(50).regex(/^[A-Z0-9_]+$/i, "Alphanumeric and underscore only"),
|
||||
@@ -718,6 +719,8 @@ export async function bulkSetManualDelivery(
|
||||
shotIds: string[],
|
||||
deliveredOn: string | null,
|
||||
note?: string,
|
||||
/** Where it was uploaded and who was sent the link. */
|
||||
evidence?: { uploadUrl?: string; sharedWith?: string },
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session?.user) throw new Error("Unauthorized");
|
||||
@@ -726,7 +729,7 @@ export async function bulkSetManualDelivery(
|
||||
}
|
||||
|
||||
const ids = z.array(z.string().cuid()).parse(shotIds);
|
||||
if (!ids.length) return { success: true, updated: 0 };
|
||||
if (!ids.length) return { success: true as const, updated: 0 };
|
||||
|
||||
let deliveredAt: Date | null = null;
|
||||
if (deliveredOn) {
|
||||
@@ -745,6 +748,27 @@ export async function bulkSetManualDelivery(
|
||||
if (shots.length !== ids.length) throw new Error("Some shots not found");
|
||||
|
||||
const trimmedNote = note?.trim() || null;
|
||||
const uploadUrl = evidence?.uploadUrl?.trim() || null;
|
||||
const sharedWith = evidence?.sharedWith?.trim() || null;
|
||||
if (uploadUrl && !/^https?:\/\/\S+$/i.test(uploadUrl)) {
|
||||
return { success: false as const, error: "The upload link must be a full http(s) link" };
|
||||
}
|
||||
|
||||
// A backfill of old deliveries may have no link to give. A shot a client is
|
||||
// waiting on is different: without the link and recipient the request it
|
||||
// answers would stay open, so say so now rather than leave it unexplained.
|
||||
if (deliveredAt && (!uploadUrl || !sharedWith)) {
|
||||
const owed = await countShotsOnOpenRequests(ids);
|
||||
if (owed > 0) {
|
||||
// Returned, not thrown: a production build replaces a thrown action
|
||||
// error with a generic message, and this one has to reach the person.
|
||||
return {
|
||||
success: false as const,
|
||||
error: `${owed} of these shots ${owed === 1 ? "is" : "are"} on an open delivery request — add the upload link and who it was sent to`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
await db.shot.updateMany({
|
||||
where: { id: { in: ids } },
|
||||
data: deliveredAt
|
||||
@@ -752,8 +776,16 @@ export async function bulkSetManualDelivery(
|
||||
manualDeliveredAt: deliveredAt,
|
||||
manualDeliveredById: session.user.id,
|
||||
manualDeliveryNote: trimmedNote,
|
||||
manualDeliveryUrl: uploadUrl,
|
||||
manualDeliverySharedWith: sharedWith,
|
||||
}
|
||||
: { manualDeliveredAt: null, manualDeliveredById: null, manualDeliveryNote: null },
|
||||
: {
|
||||
manualDeliveredAt: null,
|
||||
manualDeliveredById: null,
|
||||
manualDeliveryNote: null,
|
||||
manualDeliveryUrl: null,
|
||||
manualDeliverySharedWith: null,
|
||||
},
|
||||
});
|
||||
|
||||
for (const pid of [...new Set(shots.map((s) => s.projectId))]) {
|
||||
@@ -762,7 +794,7 @@ export async function bulkSetManualDelivery(
|
||||
revalidatePath(`/shot-status`);
|
||||
revalidatePath(`/dashboard`);
|
||||
|
||||
return { success: true, updated: shots.length };
|
||||
return { success: true as const, updated: shots.length };
|
||||
}
|
||||
|
||||
// ── Bulk Delete Shots ─────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user