Added earthquake code validation to warehouse log modal
This commit is contained in:
parent
051b5e002d
commit
5ae30b4178
@ -10,6 +10,12 @@ import { ExtendedArtefact } from "@appTypes/ApiTypes";
|
|||||||
|
|
||||||
import { fetcher } from "@utils/axiosHelpers";
|
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
|
// Filter Component
|
||||||
function FilterInput({
|
function FilterInput({
|
||||||
value,
|
value,
|
||||||
@ -33,8 +39,7 @@ function FilterInput({
|
|||||||
>
|
>
|
||||||
<IoFilter
|
<IoFilter
|
||||||
className={`cursor-pointer text-neutral-500 font-bold group-hover:text-blue-600
|
className={`cursor-pointer text-neutral-500 font-bold group-hover:text-blue-600
|
||||||
${!showSelectedFilter && value && "text-blue-600"}
|
${!showSelectedFilter && value && "text-blue-600"}`}
|
||||||
`}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@ -96,6 +101,10 @@ function LogModal({ onClose }: { onClose: () => void }) {
|
|||||||
setError("All fields are required.");
|
setError("All fields are required.");
|
||||||
return;
|
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);
|
setIsSubmitting(true);
|
||||||
try {
|
try {
|
||||||
await axios.post("/api/warehouse/log", {
|
await axios.post("/api/warehouse/log", {
|
||||||
@ -107,7 +116,6 @@ function LogModal({ onClose }: { onClose: () => void }) {
|
|||||||
warehouseLocation,
|
warehouseLocation,
|
||||||
});
|
});
|
||||||
|
|
||||||
// todo replace with better alert
|
|
||||||
alert(`Logged ${name} to storage: ${warehouseLocation}`);
|
alert(`Logged ${name} to storage: ${warehouseLocation}`);
|
||||||
onClose();
|
onClose();
|
||||||
} catch {
|
} catch {
|
||||||
@ -137,7 +145,7 @@ function LogModal({ onClose }: { onClose: () => void }) {
|
|||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Type (e.g., Lava, Tephra, Ash"
|
placeholder="Type (e.g., Lava, Tephra, Ash)"
|
||||||
value={type}
|
value={type}
|
||||||
onChange={(e) => setType(e.target.value)}
|
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"
|
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 }) {
|
|||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Earthquake Code"
|
placeholder="Earthquake Code (e.g., EC-3.9-Belgium-05467)"
|
||||||
value={earthquakeCode}
|
value={earthquakeCode}
|
||||||
// todo check code is correct format
|
|
||||||
onChange={(e) => setEarthquakeCode(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"
|
||||||
@ -259,7 +266,6 @@ function BulkLogModal({ onClose }: { onClose: () => void }) {
|
|||||||
warehouseLocation,
|
warehouseLocation,
|
||||||
});
|
});
|
||||||
|
|
||||||
// todo replace with better alert
|
|
||||||
alert(`Logged bulk pallet to storage: ${warehouseLocation}`);
|
alert(`Logged bulk pallet to storage: ${warehouseLocation}`);
|
||||||
onClose();
|
onClose();
|
||||||
} catch {
|
} catch {
|
||||||
@ -362,8 +368,13 @@ function EditModal({ artefact, onClose }: { artefact: ExtendedArtefact; onClose:
|
|||||||
setError("All fields are required.");
|
setError("All fields are required.");
|
||||||
return;
|
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);
|
setIsSubmitting(true);
|
||||||
try {
|
try {
|
||||||
|
// todo add api route
|
||||||
await new Promise((resolve) => setTimeout(resolve, 500)); // Simulated API call
|
await new Promise((resolve) => setTimeout(resolve, 500)); // Simulated API call
|
||||||
alert(`Updated artefact ${name}`);
|
alert(`Updated artefact ${name}`);
|
||||||
onClose();
|
onClose();
|
||||||
@ -430,7 +441,7 @@ function EditModal({ artefact, onClose }: { artefact: ExtendedArtefact; onClose:
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={isSold}
|
checked={isSold}
|
||||||
onChange={(e) => setIsSold(e.target.checked)}
|
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"
|
aria-label="Sold Artefact"
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
/>
|
/>
|
||||||
@ -483,7 +494,7 @@ function EditModal({ artefact, onClose }: { artefact: ExtendedArtefact; onClose:
|
|||||||
<path
|
<path
|
||||||
className="opacity-75"
|
className="opacity-75"
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
d="M4 12a8 8 0 018-8V723C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||||
></path>
|
></path>
|
||||||
</svg>
|
</svg>
|
||||||
Saving...
|
Saving...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user