Add full project files
This commit is contained in:
@@ -0,0 +1,249 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useSortable } from "@dnd-kit/sortable";
|
||||
import { CSS } from "@dnd-kit/utilities";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { GripVertical, ChevronDown, ChevronRight, Trash2, Pencil, Plus, Film, Clock, Hash, RefreshCw } from "lucide-react";
|
||||
import { updatePrevis, deleteLineItem, createLineItem } from "@/actions/shots-assets";
|
||||
import { toast } from "sonner";
|
||||
import { LineItemsTable } from "@/components/line-items/line-items-table";
|
||||
import { PrevisDialog } from "./previs-dialog";
|
||||
import { LineItemDialog } from "@/components/line-items/line-item-dialog";
|
||||
import { calcLineItem, sumLineItems, formatCurrency } from "@/lib/calculations";
|
||||
import { PREVIS_LINE_ITEM_FLAT } from "@/lib/constants";
|
||||
|
||||
interface Previs {
|
||||
id: string;
|
||||
sequenceName: string;
|
||||
previsCode: string | null;
|
||||
sequenceType: string;
|
||||
description: string | null;
|
||||
duration: string | null;
|
||||
frameRange: string | null;
|
||||
revisionCount: number;
|
||||
deliveryStage: string;
|
||||
complexityMultiplier: any;
|
||||
notes: string | null;
|
||||
lineItems: any[];
|
||||
}
|
||||
|
||||
interface Props {
|
||||
previs: Previs;
|
||||
jobId: string;
|
||||
currency: string;
|
||||
rateCards: any[];
|
||||
onDelete: (id: string) => void;
|
||||
onUpdate: (previs: any) => void;
|
||||
}
|
||||
|
||||
const STAGE_COLORS: Record<string, string> = {
|
||||
"Blocking": "bg-zinc-700 text-zinc-300",
|
||||
"First Pass": "bg-blue-900/40 text-blue-300",
|
||||
"Client Review": "bg-amber-900/40 text-amber-300",
|
||||
"Final Previs": "bg-violet-900/40 text-violet-300",
|
||||
"Approved": "bg-green-900/40 text-green-300",
|
||||
};
|
||||
|
||||
export function PrevisCard({ previs, jobId, currency, rateCards, onDelete, onUpdate }: Props) {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const [editOpen, setEditOpen] = useState(false);
|
||||
const [addLineOpen, setAddLineOpen] = useState(false);
|
||||
const [lineItems, setLineItems] = useState(previs.lineItems);
|
||||
|
||||
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id: previs.id });
|
||||
const style = { transform: CSS.Transform.toString(transform), transition, opacity: isDragging ? 0.5 : 1 };
|
||||
|
||||
const totals = sumLineItems(
|
||||
lineItems.map((li) =>
|
||||
calcLineItem({
|
||||
quantityHours: li.quantityHours?.toString() ?? "0",
|
||||
dailyRate: li.dailyRate?.toString() ?? "0",
|
||||
hoursPerDay: li.hoursPerDay?.toString() ?? "8",
|
||||
numArtists: li.numArtists?.toString() ?? "1",
|
||||
numDays: li.numDays?.toString() ?? "0",
|
||||
manualHourlyRate: li.manualHourlyRate?.toString(),
|
||||
manualSubtotal: li.manualSubtotal?.toString(),
|
||||
markupPercent: li.markupPercent?.toString() ?? "0",
|
||||
discountPercent: li.discountPercent?.toString() ?? "0",
|
||||
taxPercent: li.taxPercent?.toString() ?? "0",
|
||||
}, previs.complexityMultiplier?.toString() ?? "1")
|
||||
)
|
||||
);
|
||||
|
||||
const handleEdit = async (data: any) => {
|
||||
try {
|
||||
const result = await updatePrevis(previs.id, jobId, data);
|
||||
onUpdate(result.previs);
|
||||
setEditOpen(false);
|
||||
toast.success("Previs updated");
|
||||
} catch {
|
||||
toast.error("Failed to update previs");
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddLineItem = async (data: any) => {
|
||||
try {
|
||||
const result = await createLineItem(previs.id, "previs", jobId, data);
|
||||
setLineItems((prev) => [...prev, result.lineItem]);
|
||||
setAddLineOpen(false);
|
||||
toast.success("Line item added");
|
||||
} catch {
|
||||
toast.error("Failed to add line item");
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteLineItem = async (id: string) => {
|
||||
try {
|
||||
await deleteLineItem(id, jobId);
|
||||
setLineItems((prev) => prev.filter((li) => li.id !== id));
|
||||
toast.success("Line item removed");
|
||||
} catch {
|
||||
toast.error("Failed to delete line item");
|
||||
}
|
||||
};
|
||||
|
||||
const handleLineItemUpdate = (updated: any) => {
|
||||
setLineItems((prev) => prev.map((li) => (li.id === updated.id ? updated : li)));
|
||||
};
|
||||
|
||||
const stageColor = STAGE_COLORS[previs.deliveryStage] ?? "bg-zinc-700 text-zinc-300";
|
||||
|
||||
return (
|
||||
<div ref={setNodeRef} style={style} className="border border-zinc-800 rounded-xl overflow-hidden bg-zinc-900">
|
||||
{/* Header */}
|
||||
<div className="flex items-center gap-2 px-4 py-3 bg-zinc-900">
|
||||
<button {...attributes} {...listeners} className="text-zinc-600 hover:text-zinc-400 cursor-grab">
|
||||
<GripVertical className="h-4 w-4" />
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => setExpanded(!expanded)}
|
||||
className="flex items-center gap-2 flex-1 min-w-0 text-left"
|
||||
>
|
||||
{expanded ? (
|
||||
<ChevronDown className="h-4 w-4 text-zinc-400 shrink-0" />
|
||||
) : (
|
||||
<ChevronRight className="h-4 w-4 text-zinc-400 shrink-0" />
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<span className="font-semibold text-white truncate">{previs.sequenceName}</span>
|
||||
{previs.previsCode && (
|
||||
<span className="inline-flex items-center gap-0.5 text-xs text-zinc-500 font-mono">
|
||||
<Hash className="h-3 w-3" />{previs.previsCode}
|
||||
</span>
|
||||
)}
|
||||
<span className="inline-flex items-center gap-0.5 text-xs text-violet-400">
|
||||
<Film className="h-3 w-3" />{previs.sequenceType}
|
||||
</span>
|
||||
<span className={`text-xs px-1.5 py-0.5 rounded-full ${stageColor}`}>
|
||||
{previs.deliveryStage}
|
||||
</span>
|
||||
{previs.duration && (
|
||||
<span className="inline-flex items-center gap-0.5 text-xs text-zinc-500">
|
||||
<Clock className="h-3 w-3" />{previs.duration}
|
||||
</span>
|
||||
)}
|
||||
{previs.frameRange && (
|
||||
<span className="text-xs text-zinc-500 font-mono">{previs.frameRange}</span>
|
||||
)}
|
||||
{previs.revisionCount > 0 && (
|
||||
<span className="inline-flex items-center gap-0.5 text-xs text-zinc-400">
|
||||
<RefreshCw className="h-3 w-3" />{previs.revisionCount} rev{previs.revisionCount !== 1 ? "s" : ""}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{previs.description && (
|
||||
<p className="text-xs text-zinc-500 truncate mt-0.5">{previs.description}</p>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<span className="text-sm font-mono font-semibold text-violet-400 shrink-0">
|
||||
{formatCurrency(totals.total, currency)}
|
||||
</span>
|
||||
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 p-0 text-zinc-400 hover:text-white"
|
||||
onClick={() => setEditOpen(true)}
|
||||
>
|
||||
<Pencil className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 p-0 text-zinc-600 hover:text-red-400"
|
||||
onClick={() => onDelete(previs.id)}
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Expanded content */}
|
||||
{expanded && (
|
||||
<div className="border-t border-zinc-800">
|
||||
{/* Line items */}
|
||||
<div className="px-4 py-3">
|
||||
<div className="flex items-center justify-between mb-2">
|
||||
<span className="text-xs font-semibold text-zinc-400 uppercase tracking-wider">
|
||||
Line Items ({lineItems.length})
|
||||
</span>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() => setAddLineOpen(true)}
|
||||
className="h-7 text-xs text-violet-400 hover:text-violet-300"
|
||||
>
|
||||
<Plus className="h-3.5 w-3.5 mr-1" /> Add
|
||||
</Button>
|
||||
</div>
|
||||
{lineItems.length > 0 ? (
|
||||
<LineItemsTable
|
||||
lineItems={lineItems}
|
||||
complexityMultiplier={previs.complexityMultiplier?.toString() ?? "1"}
|
||||
currency={currency}
|
||||
parentId={previs.id}
|
||||
parentType="previs"
|
||||
jobId={jobId}
|
||||
rateCards={rateCards}
|
||||
onDelete={handleDeleteLineItem}
|
||||
onUpdate={handleLineItemUpdate}
|
||||
/>
|
||||
) : (
|
||||
<p className="text-xs text-zinc-600 py-2">No line items yet.</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<PrevisDialog
|
||||
open={editOpen}
|
||||
onOpenChange={setEditOpen}
|
||||
onSubmit={handleEdit}
|
||||
initialData={{
|
||||
sequenceName: previs.sequenceName,
|
||||
previsCode: previs.previsCode ?? undefined,
|
||||
sequenceType: previs.sequenceType,
|
||||
description: previs.description ?? undefined,
|
||||
duration: previs.duration ?? undefined,
|
||||
frameRange: previs.frameRange ?? undefined,
|
||||
revisionCount: previs.revisionCount,
|
||||
deliveryStage: previs.deliveryStage,
|
||||
complexityMultiplier: Number(previs.complexityMultiplier),
|
||||
notes: previs.notes ?? undefined,
|
||||
}}
|
||||
/>
|
||||
|
||||
<LineItemDialog
|
||||
open={addLineOpen}
|
||||
onOpenChange={setAddLineOpen}
|
||||
onSubmit={handleAddLineItem}
|
||||
rateCards={rateCards}
|
||||
defaultTasks={PREVIS_LINE_ITEM_FLAT as unknown as string[]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
"use client";
|
||||
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { previsSchema, type PrevisFormValues } from "@/lib/validations";
|
||||
import type { Resolver } from "react-hook-form";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { PREVIS_SEQUENCE_TYPES, PREVIS_DELIVERY_STAGES } from "@/lib/constants";
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
onSubmit: (data: PrevisFormValues) => Promise<void>;
|
||||
initialData?: Partial<PrevisFormValues>;
|
||||
}
|
||||
|
||||
export function PrevisDialog({ open, onOpenChange, onSubmit, initialData }: Props) {
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
reset,
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm<PrevisFormValues>({
|
||||
resolver: zodResolver(previsSchema) as Resolver<PrevisFormValues>,
|
||||
defaultValues: {
|
||||
sequenceType: "Previs",
|
||||
deliveryStage: "Blocking",
|
||||
revisionCount: 0,
|
||||
complexityMultiplier: 1,
|
||||
...initialData,
|
||||
},
|
||||
});
|
||||
|
||||
const handleClose = () => { reset(); onOpenChange(false); };
|
||||
const submit = async (data: PrevisFormValues) => { await onSubmit(data); reset(); };
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleClose}>
|
||||
<DialogContent className="bg-zinc-900 border-zinc-800 max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-white">
|
||||
{initialData?.sequenceName ? "Edit Previs Sequence" : "Add Previs Sequence"}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<form onSubmit={handleSubmit(submit as Parameters<typeof handleSubmit>[0])} className="space-y-4">
|
||||
{/* Sequence name + code */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-1.5">
|
||||
<Label>Sequence Name *</Label>
|
||||
<Input
|
||||
{...register("sequenceName")}
|
||||
className="bg-zinc-800 border-zinc-700"
|
||||
placeholder="e.g. Highway Chase"
|
||||
/>
|
||||
{errors.sequenceName && <p className="text-red-400 text-xs">{errors.sequenceName.message}</p>}
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label>Previs Code</Label>
|
||||
<Input
|
||||
{...register("previsCode")}
|
||||
className="bg-zinc-800 border-zinc-700"
|
||||
placeholder="e.g. PV_SEQ_010"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sequence type + delivery stage */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-1.5">
|
||||
<Label>Sequence Type</Label>
|
||||
<select
|
||||
{...register("sequenceType")}
|
||||
className="w-full h-9 rounded-md bg-zinc-800 border border-zinc-700 text-white text-sm px-3"
|
||||
>
|
||||
{PREVIS_SEQUENCE_TYPES.map((t) => (
|
||||
<option key={t} value={t}>{t}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label>Delivery Stage</Label>
|
||||
<select
|
||||
{...register("deliveryStage")}
|
||||
className="w-full h-9 rounded-md bg-zinc-800 border border-zinc-700 text-white text-sm px-3"
|
||||
>
|
||||
{PREVIS_DELIVERY_STAGES.map((s) => (
|
||||
<option key={s} value={s}>{s}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Duration + frame range + revisions + complexity */}
|
||||
<div className="grid grid-cols-4 gap-3">
|
||||
<div className="space-y-1.5">
|
||||
<Label>Duration</Label>
|
||||
<Input
|
||||
{...register("duration")}
|
||||
className="bg-zinc-800 border-zinc-700"
|
||||
placeholder="e.g. 2:30"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label>Frame Range</Label>
|
||||
<Input
|
||||
{...register("frameRange")}
|
||||
className="bg-zinc-800 border-zinc-700"
|
||||
placeholder="e.g. 1001-1250"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label>Revisions</Label>
|
||||
<Input
|
||||
{...register("revisionCount")}
|
||||
type="number"
|
||||
min="0"
|
||||
className="bg-zinc-800 border-zinc-700"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label>Complexity ×</Label>
|
||||
<Input
|
||||
{...register("complexityMultiplier")}
|
||||
type="number"
|
||||
step="0.1"
|
||||
min="0.1"
|
||||
max="10"
|
||||
className="bg-zinc-800 border-zinc-700"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Description + Notes */}
|
||||
<div className="space-y-1.5">
|
||||
<Label>Description</Label>
|
||||
<Input
|
||||
{...register("description")}
|
||||
className="bg-zinc-800 border-zinc-700"
|
||||
placeholder="Brief overview of the sequence"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label>Notes</Label>
|
||||
<Textarea {...register("notes")} className="bg-zinc-800 border-zinc-700" rows={2} />
|
||||
</div>
|
||||
|
||||
<div className="flex gap-3 justify-end pt-2">
|
||||
<Button type="button" variant="outline" className="border-zinc-700" onClick={handleClose}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={isSubmitting}
|
||||
className="bg-violet-600 hover:bg-violet-500 text-white font-semibold"
|
||||
>
|
||||
{isSubmitting && <Loader2 className="h-4 w-4 mr-2 animate-spin" />}
|
||||
{initialData?.sequenceName ? "Save Changes" : "Add Previs"}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Plus } from "lucide-react";
|
||||
import { createPrevis, deletePrevis, reorderPrevises } from "@/actions/shots-assets";
|
||||
import { PrevisCard } from "./previs-card";
|
||||
import { PrevisDialog } from "./previs-dialog";
|
||||
import {
|
||||
DndContext,
|
||||
closestCenter,
|
||||
PointerSensor,
|
||||
useSensor,
|
||||
useSensors,
|
||||
DragEndEvent,
|
||||
} from "@dnd-kit/core";
|
||||
import {
|
||||
SortableContext,
|
||||
verticalListSortingStrategy,
|
||||
arrayMove,
|
||||
} from "@dnd-kit/sortable";
|
||||
|
||||
interface Props {
|
||||
job: {
|
||||
id: string;
|
||||
previses: any[];
|
||||
currency?: string;
|
||||
[key: string]: any;
|
||||
};
|
||||
rateCards: any[];
|
||||
}
|
||||
|
||||
export function PrevisEditor({ job, rateCards }: Props) {
|
||||
const [previews, setPreviews] = useState(job.previses ?? []);
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
|
||||
const sensors = useSensors(useSensor(PointerSensor));
|
||||
|
||||
const handleDragEnd = async (event: DragEndEvent) => {
|
||||
const { active, over } = event;
|
||||
if (!over || active.id === over.id) return;
|
||||
const oldIndex = previews.findIndex((p) => p.id === active.id);
|
||||
const newIndex = previews.findIndex((p) => p.id === over.id);
|
||||
const reordered = arrayMove(previews, oldIndex, newIndex);
|
||||
setPreviews(reordered);
|
||||
await reorderPrevises(job.id, reordered.map((p) => p.id));
|
||||
};
|
||||
|
||||
const handleCreate = async (data: any) => {
|
||||
try {
|
||||
const result = await createPrevis(job.id, data);
|
||||
setPreviews((prev) => [...prev, result.previs]);
|
||||
setDialogOpen(false);
|
||||
toast.success("Previs sequence added");
|
||||
} catch {
|
||||
toast.error("Failed to add previs");
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = async (previsId: string) => {
|
||||
try {
|
||||
await deletePrevis(previsId, job.id);
|
||||
setPreviews((prev) => prev.filter((p) => p.id !== previsId));
|
||||
toast.success("Previs deleted");
|
||||
} catch {
|
||||
toast.error("Failed to delete previs");
|
||||
}
|
||||
};
|
||||
|
||||
const handleUpdate = (updated: any) => {
|
||||
setPreviews((prev) => prev.map((p) => (p.id === updated.id ? updated : p)));
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold text-white">Previs ({previews.length})</h2>
|
||||
<p className="text-xs text-zinc-500 mt-0.5">Storyboard animation, techvis, stuntvis, pitchvis, virtual camera blocking</p>
|
||||
</div>
|
||||
<Button
|
||||
onClick={() => setDialogOpen(true)}
|
||||
size="sm"
|
||||
className="bg-violet-600 hover:bg-violet-500 text-white font-semibold"
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-1" /> Add Previs
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{previews.length === 0 ? (
|
||||
<div className="text-center py-12 rounded-xl border border-dashed border-zinc-700 text-zinc-500">
|
||||
<p className="mb-1">No previs sequences yet.</p>
|
||||
<p className="text-sm">Add previs, techvis, stuntvis, pitchvis or postvis sequences.</p>
|
||||
</div>
|
||||
) : (
|
||||
<DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={handleDragEnd}>
|
||||
<SortableContext
|
||||
items={previews.map((p) => p.id)}
|
||||
strategy={verticalListSortingStrategy}
|
||||
>
|
||||
<div className="space-y-2">
|
||||
{previews.map((previs) => (
|
||||
<PrevisCard
|
||||
key={previs.id}
|
||||
previs={previs}
|
||||
jobId={job.id}
|
||||
currency={job.currency ?? "ZAR"}
|
||||
rateCards={rateCards}
|
||||
onDelete={handleDelete}
|
||||
onUpdate={handleUpdate}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
)}
|
||||
|
||||
<PrevisDialog
|
||||
open={dialogOpen}
|
||||
onOpenChange={setDialogOpen}
|
||||
onSubmit={handleCreate}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user