changes: Remove default SKU hardcoded to show real data

This commit is contained in:
2025-10-13 08:39:48 -06:00
parent 3c6c41e8ed
commit 5094423282
3 changed files with 25 additions and 3 deletions

View File

@@ -362,7 +362,10 @@ function HomePageContent() {
}
};
const handleHistoryItemClick = () => {
const handleHistoryItemClick = (shoe: Shoe) => {
console.log('📜 Click en historial:', shoe.name, '- SKU:', shoe.sku);
// Update detectedSKU with the shoe's SKU from history
setDetectedSKU(shoe.sku || null);
setHistoryOpen(false);
setPopupOpen(true);
};

View File

@@ -31,11 +31,28 @@ export default function ShoeResultsPopup({ isOpen, onOpenChange, detectedSKU }:
const [lastPromptTime, setLastPromptTime] = useState(0);
const [wasPopupOpenBeforeChat, setWasPopupOpenBeforeChat] = useState(false);
// Reset product when detectedSKU changes
useEffect(() => {
if (detectedSKU) {
console.log('🔄 SKU cambió, reseteando producto...');
setProduct(null);
setSelectedVariant('');
setSelectedSize('');
}
}, [detectedSKU]);
// Fetch product data when popup opens
useEffect(() => {
if (isOpen && !product) {
setLoading(true);
fetchProduct().then((data) => {
// Extract productId from detectedSKU (first 6 characters)
// Example: "18047409" → "180474"
const productId = detectedSKU?.substring(0, 6);
console.log('🔍 ShoeResultsPopup: Buscando producto con SKU:', detectedSKU);
console.log('📦 ProductId extraído:', productId);
fetchProduct(productId).then((data) => {
if (data) {
setProduct(data);
const images = getProductImages(data);
@@ -54,7 +71,7 @@ export default function ShoeResultsPopup({ isOpen, onOpenChange, detectedSKU }:
setLoading(false);
});
}
}, [isOpen, product]);
}, [isOpen, product, detectedSKU]);
// Show chat prompt when popup opens (contextual message)
useEffect(() => {

View File

@@ -92,6 +92,8 @@ export interface Product {
Disciplina?: string[];
}
// Fallback product ID used only when no productId is provided
// This should rarely happen - normally productId comes from SKU detection or history
const FIXED_PRODUCT_ID = '180474';
export async function fetchProduct(productId: string = FIXED_PRODUCT_ID): Promise<Product | null> {