Added logging of bulk pallet

This commit is contained in:
Tim Howitz 2025-06-02 08:44:55 +01:00
parent 62b9008814
commit 031ada530b
2 changed files with 43 additions and 8 deletions

View File

@ -0,0 +1,30 @@
import { NextRequest, NextResponse } from "next/server";
import { apiAuthMiddleware } from "@utils/apiAuthMiddleware";
import { prisma } from "@utils/prisma";
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { palletNote, warehouseLocation } = body;
const authResult = await apiAuthMiddleware();
if ("user" in authResult === false) return authResult; // Handle error response
const { user } = authResult;
if (!palletNote || !warehouseLocation) {
return NextResponse.json({ error: "Missing fields" }, { status: 400 });
}
await prisma.pallet.create({
data: {
palletNote,
warehouseArea: warehouseLocation,
},
});
return NextResponse.json({ message: "Pallet logged successfully" }, { status: 200 });
} catch (e: any) {
return NextResponse.json({ error: e.message }, { status: 500 });
}
}

View File

@ -237,7 +237,7 @@ function LogModal({ onClose }: { onClose: () => void }) {
// Modal Component for Bulk Logging // Modal Component for Bulk Logging
function BulkLogModal({ onClose }: { onClose: () => void }) { function BulkLogModal({ onClose }: { onClose: () => void }) {
const [palletNote, setPalletNote] = useState(""); const [palletNote, setPalletNote] = useState("");
const [storageLocation, setStorageLocation] = useState(""); const [warehouseLocation, setWarehouseLocation] = useState("");
const [error, setError] = useState(""); const [error, setError] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false);
@ -247,22 +247,27 @@ function BulkLogModal({ onClose }: { onClose: () => void }) {
} }
}; };
const handleLog = async () => { async function handleLog() {
if (!palletNote || !storageLocation) { if (!palletNote || !warehouseLocation) {
setError("All fields are required."); setError("All fields are required.");
return; return;
} }
setIsSubmitting(true); setIsSubmitting(true);
try { try {
await new Promise((resolve) => setTimeout(resolve, 500)); // Simulated API call await axios.post("/api/warehouse/log-bulk", {
alert(`Logged bulk pallet to storage: ${storageLocation}`); palletNote,
warehouseLocation,
});
// todo replace with better alert
alert(`Logged bulk pallet to storage: ${warehouseLocation}`);
onClose(); onClose();
} catch { } catch {
setError("Failed to log pallet. Please try again."); setError("Failed to log pallet. Please try again.");
} finally { } finally {
setIsSubmitting(false); setIsSubmitting(false);
} }
}; }
return ( return (
<div <div
@ -284,8 +289,8 @@ function BulkLogModal({ onClose }: { onClose: () => void }) {
<input <input
type="text" type="text"
placeholder="Storage Location (e.g., B-05)" placeholder="Storage Location (e.g., B-05)"
value={storageLocation} value={warehouseLocation}
onChange={(e) => setStorageLocation(e.target.value)} onChange={(e) => setWarehouseLocation(e.target.value)}
className="w-full p-2 border border-neutral-300 rounded-md placeholder-neutral-400 focus:ring-2 focus:ring-blue-500" className="w-full p-2 border border-neutral-300 rounded-md placeholder-neutral-400 focus:ring-2 focus:ring-blue-500"
aria-label="Storage Location" aria-label="Storage Location"
disabled={isSubmitting} disabled={isSubmitting}