From 8e219ca277d9c8f769e0f8cb139fca9988181d7a Mon Sep 17 00:00:00 2001 From: sriram Date: Mon, 17 Aug 2026 15:33:17 +0530 Subject: [PATCH] updates in frontend based on product DB --- src/pages/UserPage.jsx | 99 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 12 deletions(-) diff --git a/src/pages/UserPage.jsx b/src/pages/UserPage.jsx index 9d56ce8..8ed3a68 100644 --- a/src/pages/UserPage.jsx +++ b/src/pages/UserPage.jsx @@ -8,7 +8,7 @@ import { ErrorBoundary } from '../components/ErrorBoundary'; import { PlusCircle, Upload, CheckCircle2, Database, Sparkles, RefreshCw, Search, FileSpreadsheet, Download, ShoppingBag, - Store, LayoutGrid, Filter, ArrowRight + Store, LayoutGrid, Filter, ArrowRight, AlertTriangle } from 'lucide-react'; const STORES_SAMPLE = [ @@ -293,6 +293,16 @@ export function UserPage() { setUploadingBatch(false); if (data.added_products && Array.isArray(data.added_products)) { + // Re-read the brand from the API rather than trusting the response, so + // the panel below is showing what the database actually holds. A card + // built purely from the upload response is what made a failed import + // look successful. + const firstBrand = data.added_products[0]?.brand; + if (firstBrand) { + setBrandSearch(firstBrand); + fetchBrandCatalog(firstBrand); + } + const newBatchCards = data.added_products.map((item, idx) => ({ image_id: String(item.image_id || `batch_${Date.now()}_${idx}`), product_name: String(item.product_name || 'Batch Product'), @@ -421,6 +431,13 @@ export function UserPage() { return Array.from(setB); }, [allCardProducts]); + // A spreadsheet import can genuinely half-succeed, and that must not be + // painted the same green as a clean one - the whole complaint was a success + // panel over rows that never landed. + const batchHadErrors = Boolean( + batchResult && ((batchResult.error_count ?? 0) > 0 || batchResult.status === 'partial') + ); + return (
@@ -752,20 +769,78 @@ export function UserPage() { )} {batchResult && ( -
-
- -

Batch Products Processed

+
+
+ {batchHadErrors ? : } +

+ {batchHadErrors ? 'Batch Partially Imported' : 'Batch Products Saved to Database'} +

+

{batchResult.message}

- + {/* Counts, so "success" is never a claim without a number + behind it. added_count is the number of rows verified + present in the database, not the number attempted. */} +
+
+

{batchResult.added_count ?? 0}

+

Saved

+
+
+

{batchResult.error_count ?? 0}

+

Failed

+
+
+

{batchResult.skipped_blank_rows ?? 0}

+

Blank Rows

+
+
+ + {Array.isArray(batchResult.warnings) && batchResult.warnings.length > 0 && ( +
    + {batchResult.warnings.map((w, idx) => ( +
  • + + {w} +
  • + ))} +
+ )} + + {Array.isArray(batchResult.errors) && batchResult.errors.length > 0 && ( +
+

Rows that were not saved

+ {batchResult.errors.map((e, idx) => ( +

+ {e.row ? `Row ${e.row}: ` : ''} + {e.product_name ? `${e.product_name} - ` : ''} + {e.error} +

+ ))} + {batchResult.errors_truncated > 0 && ( +

+ +{batchResult.errors_truncated} more not shown +

+ )} +
+ )} + + {(batchResult.added_count ?? 0) > 0 && ( + + )}
)}