Add product tool link to import results

This commit is contained in:
2025-10-24 13:55:42 -04:00
parent d56beb5143
commit 217abd41af
2 changed files with 36 additions and 9 deletions

View File

@@ -26,7 +26,7 @@
--accent-foreground: 222.2 47.4% 11.2%; --accent-foreground: 222.2 47.4% 11.2%;
--destructive: 0 84.2% 60.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: 217.2 91.2% 59.8%;
--info-foreground: 222.2 47.4% 11.2%; --info-foreground: 222.2 47.4% 11.2%;

View File

@@ -46,17 +46,28 @@ const isRecord = (value: unknown): value is Record<string, unknown> =>
const extractBackendPayload = ( const extractBackendPayload = (
data: SubmitNewProductsResponse["data"], data: SubmitNewProductsResponse["data"],
): { created: BackendProductResult[]; errored: BackendProductResult[] } => { ): { created: BackendProductResult[]; errored: BackendProductResult[]; queryId: string | null } => {
if (!isRecord(data)) { if (!isRecord(data)) {
return { created: [], errored: [] }; return { created: [], errored: [], queryId: null };
} }
const payloadRecord = data as Record<string, unknown>;
const toList = (value: unknown): BackendProductResult[] => const toList = (value: unknown): BackendProductResult[] =>
Array.isArray(value) ? (value.filter(isRecord) as 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 { return {
created: toList((data as Record<string, unknown>).created), created: toList(payloadRecord.created),
errored: toList((data as Record<string, unknown>).errored), 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 const createdProducts = importOutcome
? backendPayload.created.map((entry) => { ? backendPayload.created.map((entry) => {
@@ -966,8 +983,8 @@ export function Import() {
{importOutcome.response.success === false ? ( {importOutcome.response.success === false ? (
<Alert className="border-destructive bg-destructive/10"> <Alert className="border-destructive bg-destructive/10">
<AlertCircle className="h-4 w-4" style={{ color: 'hsl(var(--destructive))' }} /> <AlertCircle className="h-4 w-4" style={{ color: 'hsl(var(--destructive))' }} />
<AlertTitle className="text-destructive-foreground">Error</AlertTitle> <AlertTitle className="text-destructive">Error</AlertTitle>
<AlertDescription className="text-destructive-foreground"> <AlertDescription className="text-destructive">
{summaryMessage ?? "Products not created - please review details and fix."} {summaryMessage ?? "Products not created - please review details and fix."}
</AlertDescription> </AlertDescription>
</Alert> </Alert>
@@ -1003,7 +1020,17 @@ export function Import() {
{createdProducts.length > 0 && ( {createdProducts.length > 0 && (
<div className="space-y-3"> <div className="space-y-3">
<h3 className="text-lg font-semibold">Created Products</h3> <div className="flex items-center justify-between gap-3">
<h3 className="text-lg font-semibold">Created Products</h3>
{productToolUrl && (
<Button asChild size="sm" variant="default">
<a href={productToolUrl} target="_blank" rel="noreferrer">
View in Product Tool
<ExternalLink />
</a>
</Button>
)}
</div>
<div className="grid gap-3"> <div className="grid gap-3">
{createdProducts.map((product, index) => { {createdProducts.map((product, index) => {
const key = product.pid ?? product.upc ?? product.itemNumber ?? index; const key = product.pid ?? product.upc ?? product.itemNumber ?? index;