Added logging of bulk pallet
This commit is contained in:
parent
62b9008814
commit
031ada530b
30
src/app/api/warehouse/log-bulk/route.ts
Normal file
30
src/app/api/warehouse/log-bulk/route.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
@ -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}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user