Compare commits

..

No commits in common. "031ada530b175d855416aec869c9ad983d535232" and "f3ad2c8ed8f53242f18d95a1b656ff23d8c5ae67" have entirely different histories.

4 changed files with 23 additions and 119 deletions

View File

@ -1,30 +0,0 @@
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

@ -1,41 +0,0 @@
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 { name, type, description, location, earthquakeCode, warehouseLocation } = body;
const authResult = await apiAuthMiddleware();
if ("user" in authResult === false) return authResult; // Handle error response
const { user } = authResult;
if (!name || !type || !description || !location || !earthquakeCode || !warehouseLocation) {
return NextResponse.json({ error: "Missing fields" }, { status: 400 });
}
const linkedEarthquake = await prisma.earthquake.findUnique({ where: { code: earthquakeCode } });
if (!linkedEarthquake) {
return NextResponse.json({ error: "Earthquake code not found" }, { status: 400 });
}
await prisma.artefact.create({
data: {
name,
type,
description,
earthquakeId: linkedEarthquake.id,
warehouseArea: warehouseLocation,
imageName: "NoImageFound.PNG",
creatorId: user.id,
},
});
return NextResponse.json({ message: "Artefact logged successfully" }, { status: 200 });
} catch (e: any) {
return NextResponse.json({ error: e.message }, { status: 500 });
}
}

View File

@ -291,6 +291,7 @@ export default function Shop() {
}
// remove all artefacts that were bought (works for both cart and single)
setHiddenArtefactIds((ids) => [...ids, ...artefactsToBuy.map((a) => a.id)]);
//!! todo create receiving api route
const genOrder = () =>
"#" + Math.random().toString(24).substring(2, 10).toUpperCase() + new Date().toLocaleDateString("en-GB");
const orderNum = genOrder();

View File

@ -1,5 +1,4 @@
"use client";
import axios from "axios";
import useSWR from "swr";
import { Dispatch, SetStateAction, useMemo, useState } from "react";
import { FaTimes } from "react-icons/fa";
@ -75,11 +74,10 @@ function FilterInput({
// Modal Component for Logging Artefact
function LogModal({ onClose }: { onClose: () => void }) {
const [name, setName] = useState("");
const [type, setType] = useState("");
const [description, setDescription] = useState("");
const [location, setLocation] = useState("");
const [earthquakeCode, setEarthquakeCode] = useState("");
const [warehouseLocation, setWarehouseLocation] = useState("");
const [earthquakeId, setEarthquakeId] = useState("");
const [storageLocation, setStorageLocation] = useState("");
const [isRequired, setIsRequired] = useState(true);
const [error, setError] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
@ -90,32 +88,23 @@ function LogModal({ onClose }: { onClose: () => void }) {
}
};
// todo add uploading image
async function handleLog() {
if (!name || !type || !description || !location || !earthquakeCode || !warehouseLocation) {
const handleLog = async () => {
if (!name || !description || !location || !earthquakeId || !storageLocation) {
setError("All fields are required.");
return;
}
setIsSubmitting(true);
try {
await axios.post("/api/warehouse/log", {
name,
type,
description,
location,
earthquakeCode,
warehouseLocation,
});
// todo replace with better alert
alert(`Logged ${name} to storage: ${warehouseLocation}`);
// todo!! add log api route
await new Promise((resolve) => setTimeout(resolve, 500)); // Simulated API call
alert(`Logged ${name} to storage: ${storageLocation}`);
onClose();
} catch {
setError("Failed to log artefact. Please try again.");
} finally {
setIsSubmitting(false);
}
}
};
return (
<div
@ -135,15 +124,6 @@ function LogModal({ onClose }: { onClose: () => void }) {
aria-label="Artefact Name"
disabled={isSubmitting}
/>
<input
type="text"
placeholder="Type (e.g., Lava, Tephra, Ash"
value={type}
onChange={(e) => setType(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="Artefact Type"
disabled={isSubmitting}
/>
<textarea
placeholder="Description"
value={description}
@ -163,19 +143,18 @@ function LogModal({ onClose }: { onClose: () => void }) {
/>
<input
type="text"
placeholder="Earthquake Code"
value={earthquakeCode}
// todo check code is correct format
onChange={(e) => setEarthquakeCode(e.target.value)}
placeholder="Earthquake ID"
value={earthquakeId}
onChange={(e) => setEarthquakeId(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="Earthquake ID"
disabled={isSubmitting}
/>
<input
type="text"
placeholder="Warehouse Location (e.g., A-12)"
value={warehouseLocation}
onChange={(e) => setWarehouseLocation(e.target.value)}
placeholder="Storage Location (e.g., A-12)"
value={storageLocation}
onChange={(e) => setStorageLocation(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}
@ -237,7 +216,7 @@ function LogModal({ onClose }: { onClose: () => void }) {
// Modal Component for Bulk Logging
function BulkLogModal({ onClose }: { onClose: () => void }) {
const [palletNote, setPalletNote] = useState("");
const [warehouseLocation, setWarehouseLocation] = useState("");
const [storageLocation, setStorageLocation] = useState("");
const [error, setError] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
@ -247,27 +226,22 @@ function BulkLogModal({ onClose }: { onClose: () => void }) {
}
};
async function handleLog() {
if (!palletNote || !warehouseLocation) {
const handleLog = async () => {
if (!palletNote || !storageLocation) {
setError("All fields are required.");
return;
}
setIsSubmitting(true);
try {
await axios.post("/api/warehouse/log-bulk", {
palletNote,
warehouseLocation,
});
// todo replace with better alert
alert(`Logged bulk pallet to storage: ${warehouseLocation}`);
await new Promise((resolve) => setTimeout(resolve, 500)); // Simulated API call
alert(`Logged bulk pallet to storage: ${storageLocation}`);
onClose();
} catch {
setError("Failed to log pallet. Please try again.");
} finally {
setIsSubmitting(false);
}
}
};
return (
<div
@ -289,8 +263,8 @@ function BulkLogModal({ onClose }: { onClose: () => void }) {
<input
type="text"
placeholder="Storage Location (e.g., B-05)"
value={warehouseLocation}
onChange={(e) => setWarehouseLocation(e.target.value)}
value={storageLocation}
onChange={(e) => setStorageLocation(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}