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) // remove all artefacts that were bought (works for both cart and single)
setHiddenArtefactIds((ids) => [...ids, ...artefactsToBuy.map((a) => a.id)]); setHiddenArtefactIds((ids) => [...ids, ...artefactsToBuy.map((a) => a.id)]);
//!! todo create receiving api route
const genOrder = () => const genOrder = () =>
"#" + Math.random().toString(24).substring(2, 10).toUpperCase() + new Date().toLocaleDateString("en-GB"); "#" + Math.random().toString(24).substring(2, 10).toUpperCase() + new Date().toLocaleDateString("en-GB");
const orderNum = genOrder(); const orderNum = genOrder();

View File

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