diff --git a/src/app/admin/route-trace/lots/new/page.tsx b/src/app/admin/route-trace/lots/new/page.tsx
index 103599f..2e9e3d0 100644
--- a/src/app/admin/route-trace/lots/new/page.tsx
+++ b/src/app/admin/route-trace/lots/new/page.tsx
@@ -1,38 +1,6 @@
import { redirect } from "next/navigation";
-import { cookies } from "next/headers";
-import { getAdminUser } from "@/lib/admin-permissions";
-import { isFeatureEnabled } from "@/lib/feature-flags";
-import LotCreateForm from "@/components/route-trace/LotCreateForm";
-import RouteTraceNav from "@/components/route-trace/RouteTraceNav";
-export const metadata = {
- title: "Create New Lot | Route Trace",
- description: "Create a new harvest lot for traceability tracking. Record crop type, field location, worker, quantity, and harvest date.",
- keywords: ["create lot", "new lot", "harvest entry", "lot creation", "traceability", "harvest tracking"],
-};
-
-export default async function NewLotPage() {
- const adminUser = await getAdminUser();
- if (!adminUser) redirect("/login");
-
- const cookieStore = await cookies();
- const devSession = cookieStore.get("dev_session")?.value;
- const isDevMode = !!devSession;
-
- const effectiveBrandId = adminUser.brand_id ?? "64294306-5f42-463d-a5e8-2ad6c81a96de";
-
- const enabled = isDevMode ? true : await isFeatureEnabled(effectiveBrandId, "route_trace");
- if (!enabled) redirect("/admin/settings/apps?reason=route_trace");
-
- return (
-
- );
+export default function NewLotPage() {
+ // New lot creation is now handled via modal in the Lots tab
+ redirect("/admin/route-trace/lots");
}
\ No newline at end of file
diff --git a/src/components/route-trace/LotCreateModal.tsx b/src/components/route-trace/LotCreateModal.tsx
new file mode 100644
index 0000000..1c96644
--- /dev/null
+++ b/src/components/route-trace/LotCreateModal.tsx
@@ -0,0 +1,455 @@
+"use client";
+
+import { useState, useTransition, useEffect } from "react";
+import { useRouter } from "next/navigation";
+import { createHarvestLot } from "@/actions/route-trace/lots";
+
+type Props = {
+ isOpen: boolean;
+ onClose: () => void;
+ brandId: string;
+};
+
+export default function LotCreateModal({ isOpen, onClose, brandId }: Props) {
+ const router = useRouter();
+ const [isPending, startTransition] = useTransition();
+ const [error, setError] = useState(null);
+ const [notesOpen, setNotesOpen] = useState(false);
+
+ const [crop_type, setCropType] = useState("");
+ const [variety, setVariety] = useState("");
+ const [harvest_date, setHarvestDate] = useState(new Date().toISOString().split("T")[0]);
+ const [field_location, setFieldLocation] = useState("");
+ const [field_block, setFieldBlock] = useState("");
+ const [worker_name, setWorkerName] = useState("");
+ const [packer_name, setPackerName] = useState("");
+ const [quantity_lbs, setQuantityLbs] = useState("");
+ const [yield_estimate_lbs, setYieldEstimateLbs] = useState("");
+ const [yield_unit, setYieldUnit] = useState("lbs");
+ const [customYieldUnit, setCustomYieldUnit] = useState("");
+ const [bin_id, setBinId] = useState("");
+ const [container_id, setContainerId] = useState("");
+ const [pallets, setPallets] = useState("");
+ const [notes, setNotes] = useState("");
+
+ // Reset form when modal opens
+ useEffect(() => {
+ if (isOpen) {
+ setCropType("");
+ setVariety("");
+ setHarvestDate(new Date().toISOString().split("T")[0]);
+ setFieldLocation("");
+ setFieldBlock("");
+ setWorkerName("");
+ setPackerName("");
+ setQuantityLbs("");
+ setYieldEstimateLbs("");
+ setYieldUnit("lbs");
+ setCustomYieldUnit("");
+ setBinId("");
+ setContainerId("");
+ setPallets("");
+ setNotes("");
+ setError(null);
+ setNotesOpen(false);
+ }
+ }, [isOpen]);
+
+ if (!isOpen) return null;
+
+ function handleSubmit(e: React.FormEvent) {
+ e.preventDefault();
+ setError(null);
+ startTransition(async () => {
+ const result = await createHarvestLot(brandId, {
+ crop_type,
+ variety: variety || undefined,
+ harvest_date,
+ field_location: field_location || undefined,
+ worker_name: worker_name || undefined,
+ packer_name: packer_name || undefined,
+ quantity_lbs: quantity_lbs ? Number(quantity_lbs) : undefined,
+ notes: notes || undefined,
+ bin_id: bin_id || undefined,
+ container_id: container_id || undefined,
+ field_block: field_block || undefined,
+ yield_estimate_lbs: yield_estimate_lbs ? Number(yield_estimate_lbs) : undefined,
+ yield_unit: yield_unit === "custom" ? customYieldUnit.trim() || undefined : yield_unit,
+ pallets: pallets ? Number(pallets) : undefined,
+ });
+ if (result.success && result.lot) {
+ onClose();
+ router.push(`/admin/route-trace/lots/${result.lot.id}`);
+ } else {
+ setError(result.error ?? "Failed to create lot");
+ }
+ });
+ }
+
+ return (
+
+ {/* Backdrop */}
+
+
+ {/* Modal */}
+
+
+
+
+
+
New Harvest Lot
+
Quick entry — scan or fill in the fields below
+
+
+
+
+
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/src/components/route-trace/LotListTable.tsx b/src/components/route-trace/LotListTable.tsx
index 3289651..b1d843a 100644
--- a/src/components/route-trace/LotListTable.tsx
+++ b/src/components/route-trace/LotListTable.tsx
@@ -89,9 +89,11 @@ function getAgeStatus(harvestDate: string): { label: string; className: string;
export default function LotListTable({
initialLots,
brandId,
+ onCreateNew,
}: {
initialLots: HaulingLot[];
brandId: string;
+ onCreateNew?: () => void;
}) {
const [filter, setFilter] = useState("");
const [query, setQuery] = useState("");
@@ -180,13 +182,13 @@ export default function LotListTable({
{filtered.length} lot{filtered.length !== 1 ? "s" : ""}
-
{Icons.plus("h-4 w-4")}
New Lot
-
+
diff --git a/src/components/route-trace/RouteTracePage.tsx b/src/components/route-trace/RouteTracePage.tsx
index b34ec1b..6a4f953 100644
--- a/src/components/route-trace/RouteTracePage.tsx
+++ b/src/components/route-trace/RouteTracePage.tsx
@@ -5,6 +5,7 @@ import Link from "next/link";
import RouteTraceDashboard from "./RouteTraceDashboard";
import AdminLookupPage from "./AdminLookupPage";
import LotListTable from "./LotListTable";
+import LotCreateModal from "./LotCreateModal";
import RouteTraceSettings from "./RouteTraceSettings";
import {
RouteTraceStats,
@@ -94,9 +95,17 @@ export default function RouteTracePage({
lots,
}: Props) {
const [activeTab, setActiveTab] = useState
("dashboard");
+ const [showCreateModal, setShowCreateModal] = useState(false);
return (
+ {/* Modal */}
+
setShowCreateModal(false)}
+ brandId={brandId}
+ />
+
{/* Tab navigation */}