From df3a0bbbd4beef09f6b7be397f2103125c3615e0 Mon Sep 17 00:00:00 2001 From: naveen prabhu Date: Thu, 7 May 2026 15:47:49 +0530 Subject: [PATCH] weight filed --- .../pages/Admin/configuration/IsicHsCodes.jsx | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/ipi-survey-platform/src/pages/Admin/configuration/IsicHsCodes.jsx b/ipi-survey-platform/src/pages/Admin/configuration/IsicHsCodes.jsx index 03a130d..315c4c8 100644 --- a/ipi-survey-platform/src/pages/Admin/configuration/IsicHsCodes.jsx +++ b/ipi-survey-platform/src/pages/Admin/configuration/IsicHsCodes.jsx @@ -20,6 +20,7 @@ const createEmptyCodeForm = () => ({ code: '', product: '', unit: '', + weight: '', status: 'Active', is_active: true, createdBy: '', @@ -28,6 +29,8 @@ const createEmptyCodeForm = () => ({ description: '' }); +const WEIGHT_REGEX = /^\d{1,2}\.\d{1,10}$/; + // Toast notification component const Toast = ({ message, type = 'success', onClose, position = 'page' }) => { React.useEffect(() => { @@ -896,19 +899,14 @@ const IsicHsCodes = () => { const handleFormChange = (field) => (event) => { const value = event?.target?.value ?? event; - if (field === "weight") { - // Allow only numbers + optional decimal - if (!/^\d*\.?\d*$/.test(value)) return; + if (field === "weight") { + if (value === '') { + setForm((prev) => ({ ...prev, [field]: value })); + return; + } - // Split integer & decimal parts - const [intPart = "", decPart = ""] = value.split("."); - - - if (intPart.length > 2) return; - - - if (decPart.length > 10) return; - } + if (!/^\d{0,2}(\.\d{0,10})?$/.test(value)) return; + } setForm((prev) => ({ ...prev, [field]: value })); }; @@ -987,13 +985,20 @@ const handleExportCSV = () => { const handleSaveForm = async () => { - if (!form.code || !form.product) { + if (!form.code || !form.product || !form.unit || !form.weight) { const errorMsg = 'Please fill in all required fields'; console.error(errorMsg); setToast({ show: true, message: errorMsg, type: 'error' }); return; } + if (!WEIGHT_REGEX.test(form.weight)) { + const errorMsg = 'Weight must be in the format 12.1234567890 with up to 2 digits before the decimal and up to 10 digits after it'; + console.error(errorMsg); + setToast({ show: true, message: errorMsg, type: 'error' }); + return; + } + try { setError(''); @@ -1625,19 +1630,21 @@ const handleExportCSV = () => { )} - {/*
+
-
*/} +