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