Update page.tsx

This commit is contained in:
NotII
2025-03-19 14:15:37 +01:00
parent 57e196cc6a
commit 3d9e46e4d3

View File

@@ -121,29 +121,24 @@ export default function OrderDetailsPage() {
authToken: string authToken: string
): Promise<Record<string, string>> => { ): Promise<Record<string, string>> => {
const productNamesMap: Record<string, string> = {}; const productNamesMap: Record<string, string> = {};
try {
const promises = productIds.map((id) => // Process each product ID independently
fetchData(`${process.env.NEXT_PUBLIC_API_URL}/products/${id}`, { const fetchPromises = productIds.map(async (id) => {
try {
const product = await fetchData(`${process.env.NEXT_PUBLIC_API_URL}/products/${id}`, {
method: "GET", method: "GET",
headers: { Authorization: `Bearer ${authToken}` }, headers: { Authorization: `Bearer ${authToken}` },
}) });
); productNamesMap[id] = product?.name || "Unknown Product (Deleted)";
const responses = await Promise.all(promises); } catch (err) {
const results = await Promise.all(responses.map((res) => res)); console.error(`Failed to fetch product ${id}:`, err);
productNamesMap[id] = "Unknown Product (Deleted)";
results.forEach((product, index) => { }
productNamesMap[productIds[index]] = product.name || "Unknown Product (Deleted)"; });
});
// Wait for all fetch operations to complete (successful or failed)
} catch (err) { await Promise.all(fetchPromises);
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; return productNamesMap;
}; };
@@ -767,4 +762,4 @@ export default function OrderDetailsPage() {
</div> </div>
</Layout> </Layout>
); );
} }