Start integrating the onboarding flow with backend 14

This commit is contained in:
Urtzi Alfaro
2025-09-07 22:54:14 +02:00
parent 05898d504d
commit 0060b9cccb
13 changed files with 668 additions and 487 deletions

View File

@@ -120,7 +120,20 @@ export const SmartInventorySetupStep: React.FC<OnboardingStepProps> = ({
const tenantCreatedSuccessfully = tenantCreation.isSuccess;
const tenantCreatedInOnboarding = data.bakery?.tenantCreated === true;
return Boolean(hasAuth && (hasTenantId || tenantCreatedSuccessfully || tenantCreatedInOnboarding));
const result = Boolean(hasAuth && (hasTenantId || tenantCreatedSuccessfully || tenantCreatedInOnboarding));
console.log('🔄 SmartInventorySetup - isTenantAvailable check:', {
hasAuth,
authLoading,
hasUser: !!user,
hasTenantId,
tenantId: getTenantId(),
tenantCreatedSuccessfully,
tenantCreatedInOnboarding,
finalResult: result
});
return result;
};
// Local state
@@ -144,7 +157,14 @@ export const SmartInventorySetupStep: React.FC<OnboardingStepProps> = ({
// Update products when suggestions change
useEffect(() => {
console.log('🔄 SmartInventorySetup - suggestions effect:', {
suggestionsLength: suggestions?.length || 0,
productsLength: products.length,
suggestions: suggestions,
});
if (suggestions && suggestions.length > 0 && products.length === 0) {
console.log('✅ Converting suggestions to products and setting stage to review');
const newProducts = convertSuggestionsToCards(suggestions);
setProducts(newProducts);
setLocalStage('review');
@@ -157,6 +177,17 @@ export const SmartInventorySetupStep: React.FC<OnboardingStepProps> = ({
: (onboardingStage === 'completed' ? 'review' : onboardingStage || localStage);
const progress = onboardingProgress || 0;
const currentMessage = onboardingMessage || '';
// Debug current stage
useEffect(() => {
console.log('🔄 SmartInventorySetup - Stage debug:', {
localStage,
onboardingStage,
finalStage: stage,
productsLength: products.length,
suggestionsLength: suggestions?.length || 0
});
}, [localStage, onboardingStage, stage, products.length, suggestions?.length]);
// Product stats
const stats = useMemo(() => ({
@@ -247,15 +278,20 @@ export const SmartInventorySetupStep: React.FC<OnboardingStepProps> = ({
setLocalStage('validating');
try {
console.log('🔄 SmartInventorySetup - Processing file:', file.name);
const success = await processSalesFile(file);
console.log('🔄 SmartInventorySetup - Processing result:', { success });
if (success) {
console.log('✅ File processed successfully, setting stage to review');
setLocalStage('review');
toast.addToast('El archivo se procesó correctamente. Revisa los productos detectados.', {
title: 'Procesamiento completado',
type: 'success'
});
} else {
console.error('❌ File processing failed - processSalesFile returned false');
throw new Error('Error procesando el archivo');
}
} catch (error) {