Sfoglia il codice sorgente

Make Truck Deatil better

master
Tommy\2Fi-Staff 1 mese fa
parent
commit
a0070e025e
4 ha cambiato i file con 29 aggiunte e 15 eliminazioni
  1. +12
    -0
      src/components/Shop/TruckLane.tsx
  2. +13
    -13
      src/components/Shop/TruckLaneDetail.tsx
  3. +2
    -1
      src/i18n/en/common.json
  4. +2
    -1
      src/i18n/zh/common.json

+ 12
- 0
src/components/Shop/TruckLane.tsx Vedi File

@@ -188,6 +188,18 @@ const TruckLane: React.FC = () => {
return; 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); setSaving(true);
setError(null); setError(null);
try { try {


+ 13
- 13
src/components/Shop/TruckLaneDetail.tsx Vedi File

@@ -407,12 +407,14 @@ const TruckLaneDetail: React.FC = () => {
shopCode: String(matchingShop.code || ""), shopCode: String(matchingShop.code || ""),
}); });
} else { } else {
// If no matching shop found, allow free text input for shop name
setNewShop({ setNewShop({
...newShop, ...newShop,
shopName: newValue, shopName: newValue,
}); });
} }
} else if (newValue === null) {
} else {
// Clear shop name when selection is cleared (but keep shop code if it exists)
setNewShop({ setNewShop({
...newShop, ...newShop,
shopName: "", shopName: "",
@@ -431,14 +433,17 @@ const TruckLaneDetail: React.FC = () => {
shopName: String(matchingShop.name || ""), shopName: String(matchingShop.name || ""),
}); });
} else { } else {
// If no matching shop found, still set the code (shouldn't happen with restricted selection)
setNewShop({ setNewShop({
...newShop, ...newShop,
shopCode: newValue, shopCode: newValue,
}); });
} }
} else if (newValue === null) {
} else {
// Clear both fields when selection is cleared
setNewShop({ setNewShop({
...newShop, ...newShop,
shopName: "",
shopCode: "", shopCode: "",
}); });
} }
@@ -633,7 +638,7 @@ const TruckLaneDetail: React.FC = () => {
<CardContent> <CardContent>
<Paper sx={{ p: 3 }}> <Paper sx={{ p: 3 }}>
<Grid container spacing={3}> <Grid container spacing={3}>
<Grid item xs={12} sm={6}>
<Grid item xs={12} sm={4}>
<Typography variant="subtitle2" color="text.secondary"> <Typography variant="subtitle2" color="text.secondary">
{t("TruckLance Code")} {t("TruckLance Code")}
</Typography> </Typography>
@@ -642,7 +647,7 @@ const TruckLaneDetail: React.FC = () => {
</Typography> </Typography>
</Grid> </Grid>


<Grid item xs={12} sm={6}>
<Grid item xs={12} sm={4}>
<Typography variant="subtitle2" color="text.secondary"> <Typography variant="subtitle2" color="text.secondary">
{t("Departure Time")} {t("Departure Time")}
</Typography> </Typography>
@@ -655,7 +660,7 @@ const TruckLaneDetail: React.FC = () => {
</Typography> </Typography>
</Grid> </Grid>


<Grid item xs={12} sm={6}>
<Grid item xs={12} sm={4}>
<Typography variant="subtitle2" color="text.secondary"> <Typography variant="subtitle2" color="text.secondary">
{t("Store ID")} {t("Store ID")}
</Typography> </Typography>
@@ -943,12 +948,13 @@ const TruckLaneDetail: React.FC = () => {
<Autocomplete <Autocomplete
freeSolo freeSolo
options={uniqueShopNames} options={uniqueShopNames}
value={newShop.shopName}
value={newShop.shopName || null}
onChange={(event, newValue) => { onChange={(event, newValue) => {
handleNewShopNameChange(newValue); handleNewShopNameChange(newValue);
}} }}
onInputChange={(event, newInputValue, reason) => { onInputChange={(event, newInputValue, reason) => {
if (reason === 'input') { if (reason === 'input') {
// Allow free text input for shop name
setNewShop({ ...newShop, shopName: newInputValue }); setNewShop({ ...newShop, shopName: newInputValue });
} }
}} }}
@@ -966,17 +972,11 @@ const TruckLaneDetail: React.FC = () => {
</Grid> </Grid>
<Grid item xs={12}> <Grid item xs={12}>
<Autocomplete <Autocomplete
freeSolo
options={uniqueShopCodes} options={uniqueShopCodes}
value={newShop.shopCode}
value={newShop.shopCode || null}
onChange={(event, newValue) => { onChange={(event, newValue) => {
handleNewShopCodeChange(newValue); handleNewShopCodeChange(newValue);
}} }}
onInputChange={(event, newInputValue, reason) => {
if (reason === 'input') {
setNewShop({ ...newShop, shopCode: newInputValue });
}
}}
renderInput={(params) => ( renderInput={(params) => (
<TextField <TextField
{...params} {...params}


+ 2
- 1
src/i18n/en/common.json Vedi File

@@ -29,5 +29,6 @@
"Search or select shop code": "Search or select shop code", "Search or select shop code": "Search or select shop code",
"Search or select remark": "Search or select remark", "Search or select remark": "Search or select remark",
"Edit shop details": "Edit shop details", "Edit shop details": "Edit shop details",
"Add Shop to Truck Lane": "Add Shop to Truck Lane"
"Add Shop to Truck Lane": "Add Shop to Truck Lane",
"Truck lane code already exists. Please use a different code.": "Truck lane code already exists. Please use a different code."
} }

+ 2
- 1
src/i18n/zh/common.json Vedi File

@@ -400,5 +400,6 @@
"Search or select shop code": "搜尋或選擇店鋪編號", "Search or select shop code": "搜尋或選擇店鋪編號",
"Search or select remark": "搜尋或選擇備註", "Search or select remark": "搜尋或選擇備註",
"Edit shop details": "編輯店鋪詳情", "Edit shop details": "編輯店鋪詳情",
"Add Shop to Truck Lane": "新增店鋪至卡車路線"
"Add Shop to Truck Lane": "新增店鋪至卡車路線",
"Truck lane code already exists. Please use a different code.": "卡車路線編號已存在,請使用其他編號。"
} }

Caricamento…
Annulla
Salva