diff --git a/inventory/src/index.css b/inventory/src/index.css index 765e381..da07460 100644 --- a/inventory/src/index.css +++ b/inventory/src/index.css @@ -26,7 +26,7 @@ --accent-foreground: 222.2 47.4% 11.2%; --destructive: 0 84.2% 60.2%; - --destructive-foreground: 222.2 47.4% 11.2%; + --destructive-foreground: 210 40% 98%; --info: 217.2 91.2% 59.8%; --info-foreground: 222.2 47.4% 11.2%; diff --git a/inventory/src/pages/Import.tsx b/inventory/src/pages/Import.tsx index 7866c43..7cdfe35 100644 --- a/inventory/src/pages/Import.tsx +++ b/inventory/src/pages/Import.tsx @@ -46,17 +46,28 @@ const isRecord = (value: unknown): value is Record => const extractBackendPayload = ( data: SubmitNewProductsResponse["data"], -): { created: BackendProductResult[]; errored: BackendProductResult[] } => { +): { created: BackendProductResult[]; errored: BackendProductResult[]; queryId: string | null } => { if (!isRecord(data)) { - return { created: [], errored: [] }; + return { created: [], errored: [], queryId: null }; } + const payloadRecord = data as Record; const toList = (value: unknown): BackendProductResult[] => Array.isArray(value) ? (value.filter(isRecord) as BackendProductResult[]) : []; + const queryIdSource = payloadRecord.query_id ?? payloadRecord.queryId ?? payloadRecord.queryID; + let queryId: string | null = null; + + if (typeof queryIdSource === "string") { + const trimmed = queryIdSource.trim(); + queryId = trimmed.length ? trimmed : null; + } else if (typeof queryIdSource === "number") { + queryId = queryIdSource.toString(); + } return { - created: toList((data as Record).created), - errored: toList((data as Record).errored), + created: toList(payloadRecord.created), + errored: toList(payloadRecord.errored), + queryId, }; }; @@ -406,6 +417,7 @@ export function Import() { // }, // }, // ], + // query_id: "1234567890", // }, // }; @@ -784,7 +796,12 @@ export function Import() { } }; - const backendPayload = importOutcome ? extractBackendPayload(importOutcome.response.data) : { created: [], errored: [] }; + const backendPayload = importOutcome + ? extractBackendPayload(importOutcome.response.data) + : { created: [] as BackendProductResult[], errored: [] as BackendProductResult[], queryId: null }; + const productToolUrl = backendPayload.queryId + ? `https://backend.acherryontop.com/product_tool/${backendPayload.queryId}` + : null; const createdProducts = importOutcome ? backendPayload.created.map((entry) => { @@ -966,8 +983,8 @@ export function Import() { {importOutcome.response.success === false ? ( - Error - + Error + {summaryMessage ?? "Products not created - please review details and fix."} @@ -1003,7 +1020,17 @@ export function Import() { {createdProducts.length > 0 && (
-

Created Products

+
+

Created Products

+ {productToolUrl && ( + + )} +
{createdProducts.map((product, index) => { const key = product.pid ?? product.upc ?? product.itemNumber ?? index;