This commit is contained in:
NotII
2025-03-19 14:06:58 +01:00
parent 6bdcb15552
commit 57e196cc6a
3 changed files with 499 additions and 902 deletions

View File

@@ -132,11 +132,17 @@ export default function OrderDetailsPage() {
const results = await Promise.all(responses.map((res) => res));
results.forEach((product, index) => {
productNamesMap[productIds[index]] = product.name || "Unknown Product";
productNamesMap[productIds[index]] = product.name || "Unknown Product (Deleted)";
});
} catch (err) {
console.error("Failed to fetch product names:", err);
// Initialize product names that failed to load
productIds.forEach(id => {
if (!productNamesMap[id]) {
productNamesMap[id] = "Unknown Product (Deleted)";
}
});
}
return productNamesMap;
};
@@ -323,6 +329,20 @@ export default function OrderDetailsPage() {
const productIds = data.products.map((product) => product.productId);
const productNamesMap = await fetchProductNames(productIds, authToken);
setProductNames(productNamesMap);
// Add a short timeout to ensure any products still showing as loading
// are marked as deleted/unknown
setTimeout(() => {
setProductNames(prev => {
const newMap = {...prev};
productIds.forEach(id => {
if (!newMap[id] || newMap[id] === "Loading...") {
newMap[id] = "Unknown Product (Deleted)";
}
});
return newMap;
});
}, 3000); // 3 second timeout
if (data.status === "paid") {
setIsPaid(true);
@@ -603,7 +623,7 @@ export default function OrderDetailsPage() {
{order?.products.map((product) => (
<TableRow key={product._id}>
<TableCell>
{productNames[product.productId] || "Loading..."}
{productNames[product.productId] || "Unknown Product (Deleted)"}
</TableCell>
<TableCell>{product.quantity}</TableCell>
<TableCell>£{product.pricePerUnit.toFixed(2)}</TableCell>