From 5ae30b41785e6ded9234ad23ac83d564c22c3f07 Mon Sep 17 00:00:00 2001 From: Tim Howitz Date: Tue, 3 Jun 2025 15:55:56 +0100 Subject: [PATCH] Added earthquake code validation to warehouse log modal --- src/app/warehouse/page.tsx | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/app/warehouse/page.tsx b/src/app/warehouse/page.tsx index 4523f16..e01a26c 100644 --- a/src/app/warehouse/page.tsx +++ b/src/app/warehouse/page.tsx @@ -10,6 +10,12 @@ import { ExtendedArtefact } from "@appTypes/ApiTypes"; import { fetcher } from "@utils/axiosHelpers"; +// Function to validate earthquake code format +const validateEarthquakeCode = (code: string): boolean => { + const pattern = /^E[A-Z]-[0-9]\.[0-9]-[A-Za-z]+-[0-9]{5}$/; + return pattern.test(code); +}; + // Filter Component function FilterInput({ value, @@ -33,14 +39,13 @@ function FilterInput({ >
{options ? (
@@ -96,6 +101,10 @@ function LogModal({ onClose }: { onClose: () => void }) { setError("All fields are required."); return; } + if (!validateEarthquakeCode(earthquakeCode)) { + setError("Earthquake Code must be in format: EX-M.M-Country-##### (e.g., EC-3.9-Belgium-05467)"); + return; + } setIsSubmitting(true); try { await axios.post("/api/warehouse/log", { @@ -107,7 +116,6 @@ function LogModal({ onClose }: { onClose: () => void }) { warehouseLocation, }); - // todo replace with better alert alert(`Logged ${name} to storage: ${warehouseLocation}`); onClose(); } catch { @@ -137,7 +145,7 @@ function LogModal({ onClose }: { onClose: () => void }) { /> 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" @@ -163,9 +171,8 @@ function LogModal({ onClose }: { onClose: () => void }) { /> 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" aria-label="Earthquake ID" @@ -259,7 +266,6 @@ function BulkLogModal({ onClose }: { onClose: () => void }) { warehouseLocation, }); - // todo replace with better alert alert(`Logged bulk pallet to storage: ${warehouseLocation}`); onClose(); } catch { @@ -362,8 +368,13 @@ function EditModal({ artefact, onClose }: { artefact: ExtendedArtefact; onClose: setError("All fields are required."); return; } + if (!validateEarthquakeCode(earthquakeCode)) { + setError("Earthquake Code must be in format: XX-M.M-Country-##### (e.g., EC-3.9-Belgium-05467)"); + return; + } setIsSubmitting(true); try { + // todo add api route await new Promise((resolve) => setTimeout(resolve, 500)); // Simulated API call alert(`Updated artefact ${name}`); onClose(); @@ -430,7 +441,7 @@ function EditModal({ artefact, onClose }: { artefact: ExtendedArtefact; onClose: type="checkbox" checked={isSold} onChange={(e) => setIsSold(e.target.checked)} - className="h-4 w-4 text-blue-600 border-neutral-300 rounded focus:ring-blue-500" + className="w-4 h-4 text-blue-600 border-neutral-300 rounded focus:ring-blue-500" aria-label="Sold Artefact" disabled={isSubmitting} /> @@ -483,7 +494,7 @@ function EditModal({ artefact, onClose }: { artefact: ExtendedArtefact; onClose: Saving...