|
|
|
@@ -69,6 +69,7 @@ const TruckLaneDetail: React.FC = () => { |
|
|
|
const [uniqueRemarks, setUniqueRemarks] = useState<string[]>([]); |
|
|
|
const [uniqueShopCodes, setUniqueShopCodes] = useState<string[]>([]); |
|
|
|
const [uniqueShopNames, setUniqueShopNames] = useState<string[]>([]); |
|
|
|
const [shopNameByCodeMap, setShopNameByCodeMap] = useState<Map<string, string>>(new Map()); |
|
|
|
const [addShopDialogOpen, setAddShopDialogOpen] = useState<boolean>(false); |
|
|
|
const [newShop, setNewShop] = useState({ |
|
|
|
shopName: "", |
|
|
|
@@ -86,11 +87,12 @@ const TruckLaneDetail: React.FC = () => { |
|
|
|
useEffect(() => { |
|
|
|
const fetchAutocompleteData = async () => { |
|
|
|
try { |
|
|
|
const [shopData, remarks, codes, names] = await Promise.all([ |
|
|
|
const [shopData, remarks, codes, names, allShopsFromShopTable] = await Promise.all([ |
|
|
|
findAllUniqueShopNamesAndCodesFromTrucksClient() as Promise<Array<{ name: string; code: string }>>, |
|
|
|
findAllUniqueRemarksFromTrucksClient() as Promise<string[]>, |
|
|
|
findAllUniqueShopCodesFromTrucksClient() as Promise<string[]>, |
|
|
|
findAllUniqueShopNamesFromTrucksClient() as Promise<string[]>, |
|
|
|
fetchAllShopsClient() as Promise<ShopAndTruck[]>, |
|
|
|
]); |
|
|
|
|
|
|
|
// Convert to Shop format (id will be 0 since we don't have shop IDs from truck table) |
|
|
|
@@ -105,6 +107,15 @@ const TruckLaneDetail: React.FC = () => { |
|
|
|
setUniqueRemarks(remarks || []); |
|
|
|
setUniqueShopCodes(codes || []); |
|
|
|
setUniqueShopNames(names || []); |
|
|
|
|
|
|
|
// Create lookup map: shopCode -> shopName from shop table |
|
|
|
const shopNameMap = new Map<string, string>(); |
|
|
|
(allShopsFromShopTable || []).forEach((shop) => { |
|
|
|
if (shop.code) { |
|
|
|
shopNameMap.set(String(shop.code).trim().toLowerCase(), String(shop.name || "").trim()); |
|
|
|
} |
|
|
|
}); |
|
|
|
setShopNameByCodeMap(shopNameMap); |
|
|
|
} catch (err) { |
|
|
|
console.error("Failed to load autocomplete data:", err); |
|
|
|
} |
|
|
|
@@ -700,6 +711,7 @@ const TruckLaneDetail: React.FC = () => { |
|
|
|
<TableHead> |
|
|
|
<TableRow> |
|
|
|
<TableCell>{t("Shop Name")}</TableCell> |
|
|
|
<TableCell>{t("Shop Branch")}</TableCell> |
|
|
|
<TableCell>{t("Shop Code")}</TableCell> |
|
|
|
<TableCell>{t("Remark")}</TableCell> |
|
|
|
<TableCell>{t("Loading Sequence")}</TableCell> |
|
|
|
@@ -709,7 +721,7 @@ const TruckLaneDetail: React.FC = () => { |
|
|
|
<TableBody> |
|
|
|
{shopsData.length === 0 ? ( |
|
|
|
<TableRow> |
|
|
|
<TableCell colSpan={5} align="center"> |
|
|
|
<TableCell colSpan={6} align="center"> |
|
|
|
<Typography variant="body2" color="text.secondary"> |
|
|
|
{t("No shops found using this truck lane")} |
|
|
|
</Typography> |
|
|
|
@@ -719,6 +731,14 @@ const TruckLaneDetail: React.FC = () => { |
|
|
|
shopsData.map((shop, index) => ( |
|
|
|
<TableRow key={shop.id ?? `shop-${index}`}> |
|
|
|
<TableCell> |
|
|
|
{/* Shop Name from shop table (read-only, looked up by shop code) */} |
|
|
|
{(() => { |
|
|
|
const shopCode = String(shop.code || "").trim().toLowerCase(); |
|
|
|
return shopNameByCodeMap.get(shopCode) || "-"; |
|
|
|
})()} |
|
|
|
</TableCell> |
|
|
|
<TableCell> |
|
|
|
{/* Shop Branch from truck table (editable) */} |
|
|
|
{editingRowIndex === index ? ( |
|
|
|
<Autocomplete |
|
|
|
freeSolo |
|
|
|
|