diff --git a/src/components/Shop/TruckLane.tsx b/src/components/Shop/TruckLane.tsx index c1ae0ce..efe0bc5 100644 --- a/src/components/Shop/TruckLane.tsx +++ b/src/components/Shop/TruckLane.tsx @@ -188,6 +188,18 @@ const TruckLane: React.FC = () => { return; } + // Check if truckLanceCode already exists + const trimmedCode = newTruck.truckLanceCode.trim(); + const existingTruck = truckData.find( + (truck) => String(truck.truckLanceCode || "").trim().toLowerCase() === trimmedCode.toLowerCase() + ); + + if (existingTruck) { + setSnackbarMessage(t("Truck lane code already exists. Please use a different code.")); + setSnackbarOpen(true); + return; + } + setSaving(true); setError(null); try { diff --git a/src/components/Shop/TruckLaneDetail.tsx b/src/components/Shop/TruckLaneDetail.tsx index 80398d7..21b5536 100644 --- a/src/components/Shop/TruckLaneDetail.tsx +++ b/src/components/Shop/TruckLaneDetail.tsx @@ -407,12 +407,14 @@ const TruckLaneDetail: React.FC = () => { shopCode: String(matchingShop.code || ""), }); } else { + // If no matching shop found, allow free text input for shop name setNewShop({ ...newShop, shopName: newValue, }); } - } else if (newValue === null) { + } else { + // Clear shop name when selection is cleared (but keep shop code if it exists) setNewShop({ ...newShop, shopName: "", @@ -431,14 +433,17 @@ const TruckLaneDetail: React.FC = () => { shopName: String(matchingShop.name || ""), }); } else { + // If no matching shop found, still set the code (shouldn't happen with restricted selection) setNewShop({ ...newShop, shopCode: newValue, }); } - } else if (newValue === null) { + } else { + // Clear both fields when selection is cleared setNewShop({ ...newShop, + shopName: "", shopCode: "", }); } @@ -633,7 +638,7 @@ const TruckLaneDetail: React.FC = () => { - + {t("TruckLance Code")} @@ -642,7 +647,7 @@ const TruckLaneDetail: React.FC = () => { - + {t("Departure Time")} @@ -655,7 +660,7 @@ const TruckLaneDetail: React.FC = () => { - + {t("Store ID")} @@ -943,12 +948,13 @@ const TruckLaneDetail: React.FC = () => { { handleNewShopNameChange(newValue); }} onInputChange={(event, newInputValue, reason) => { if (reason === 'input') { + // Allow free text input for shop name setNewShop({ ...newShop, shopName: newInputValue }); } }} @@ -966,17 +972,11 @@ const TruckLaneDetail: React.FC = () => { { handleNewShopCodeChange(newValue); }} - onInputChange={(event, newInputValue, reason) => { - if (reason === 'input') { - setNewShop({ ...newShop, shopCode: newInputValue }); - } - }} renderInput={(params) => (