weight filed
This commit is contained in:
parent
360eb6630c
commit
df3a0bbbd4
@ -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 = () => {
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* <div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-[#374151] mb-1">
|
||||
Weight
|
||||
Weight <span className="text-[#EF4444]">*</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
inputMode="decimal"
|
||||
value={form.weight || ''}
|
||||
onChange={handleFormChange("weight")}
|
||||
disabled={modalMode === "view"}
|
||||
className="w-full px-3 py-2 text-sm border border-[#CBA344] rounded-md focus:outline-none focus:ring-1 focus:ring-[#92722A] focus:border-[#92722A]"
|
||||
placeholder="Enter weight"
|
||||
placeholder="e.g. 12.1234567890"
|
||||
maxLength={13}
|
||||
/>
|
||||
</div> */}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-4">
|
||||
<label className="block text-sm font-medium text-[#374151] mb-1">
|
||||
@ -1669,9 +1676,9 @@ const handleExportCSV = () => {
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleSaveForm}
|
||||
disabled={!form.code || !form.product || !form.unit}
|
||||
disabled={!form.code || !form.product || !form.unit || !WEIGHT_REGEX.test(form.weight || '')}
|
||||
className={`h-10 px-6 text-sm font-medium text-white rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-[#92722A] ${
|
||||
!form.code || !form.product || !form.unit
|
||||
!form.code || !form.product || !form.unit || !WEIGHT_REGEX.test(form.weight || '')
|
||||
? 'bg-gray-300 cursor-not-allowed'
|
||||
: 'bg-[#92722A] hover:bg-[#7a5f22]'
|
||||
}`}
|
||||
@ -1736,4 +1743,4 @@ const handleExportCSV = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default IsicHsCodes;
|
||||
export default IsicHsCodes;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user