Fix issues
This commit is contained in:
@@ -120,7 +120,20 @@ export class TenantService {
|
||||
console.log('📦 TenantService: API response:', result);
|
||||
console.log('📏 TenantService: Response length:', Array.isArray(result) ? result.length : 'Not an array');
|
||||
|
||||
if (Array.isArray(result) && result.length > 0) {
|
||||
// Ensure we always return an array
|
||||
if (!Array.isArray(result)) {
|
||||
console.warn('⚠️ TenantService: Response is not an array, converting...');
|
||||
// If it's an object with numeric keys, convert to array
|
||||
if (result && typeof result === 'object') {
|
||||
const converted = Object.values(result);
|
||||
console.log('🔄 TenantService: Converted to array:', converted);
|
||||
return converted as TenantInfo[];
|
||||
}
|
||||
console.log('🔄 TenantService: Returning empty array');
|
||||
return [];
|
||||
}
|
||||
|
||||
if (result.length > 0) {
|
||||
console.log('✅ TenantService: First tenant:', result[0]);
|
||||
console.log('🆔 TenantService: First tenant ID:', result[0]?.id);
|
||||
}
|
||||
|
||||
@@ -327,6 +327,7 @@ export default function SimplifiedTrainingProgress({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{/* Benefits Preview */}
|
||||
<div className="bg-white rounded-3xl shadow-lg p-6 mb-6">
|
||||
<h3 className="text-xl font-bold text-gray-900 mb-4 text-center">
|
||||
@@ -408,6 +409,7 @@ export default function SimplifiedTrainingProgress({
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -25,6 +25,20 @@ export const TenantSelector: React.FC = () => {
|
||||
}
|
||||
}, [user, getUserTenants]);
|
||||
|
||||
// Auto-select tenant based on localStorage or default to first one
|
||||
useEffect(() => {
|
||||
if (Array.isArray(tenants) && tenants.length > 0 && !currentTenant) {
|
||||
const savedTenantId = localStorage.getItem('selectedTenantId');
|
||||
const tenantToSelect = savedTenantId
|
||||
? tenants.find(t => t.id === savedTenantId) || tenants[0]
|
||||
: tenants[0];
|
||||
|
||||
console.log('🎯 Auto-selecting tenant:', tenantToSelect);
|
||||
dispatch(setCurrentTenant(tenantToSelect));
|
||||
localStorage.setItem('selectedTenantId', tenantToSelect.id);
|
||||
}
|
||||
}, [tenants, currentTenant, dispatch]);
|
||||
|
||||
const handleTenantChange = async (tenant: any) => {
|
||||
try {
|
||||
dispatch(setCurrentTenant(tenant));
|
||||
@@ -40,8 +54,32 @@ export const TenantSelector: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading || tenants.length <= 1) {
|
||||
return null;
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="text-sm text-gray-500">
|
||||
Cargando panaderías...
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Show current tenant name even if there's only one
|
||||
if (!Array.isArray(tenants) || tenants.length === 0) {
|
||||
return (
|
||||
<div className="text-sm text-gray-500">
|
||||
No hay panaderías disponibles
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// If there's only one tenant, just show its name without dropdown
|
||||
if (tenants.length === 1) {
|
||||
const tenant = tenants[0];
|
||||
return (
|
||||
<div className="flex items-center text-sm">
|
||||
<Building className="h-4 w-4 text-gray-400 mr-2" />
|
||||
<span className="font-medium text-gray-900">{tenant.name}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -74,7 +112,7 @@ export const TenantSelector: React.FC = () => {
|
||||
</div>
|
||||
|
||||
<div className="max-h-64 overflow-y-auto">
|
||||
{tenants.map((tenant) => (
|
||||
{Array.isArray(tenants) ? tenants.map((tenant) => (
|
||||
<button
|
||||
key={tenant.id}
|
||||
onClick={() => handleTenantChange(tenant)}
|
||||
@@ -105,7 +143,11 @@ export const TenantSelector: React.FC = () => {
|
||||
<Check className="h-4 w-4 text-primary-600 flex-shrink-0" />
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
)) : (
|
||||
<div className="px-4 py-3 text-sm text-gray-500">
|
||||
No hay panaderías disponibles
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="px-4 py-2 border-t border-gray-100">
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { ChevronLeft, ChevronRight, Upload, MapPin, Store, Check, Brain, Clock, CheckCircle, AlertTriangle, Loader, TrendingUp } from 'lucide-react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useSelector } from 'react-redux';
|
||||
import toast from 'react-hot-toast';
|
||||
|
||||
import SimplifiedTrainingProgress from '../../components/SimplifiedTrainingProgress';
|
||||
@@ -16,10 +18,11 @@ import {
|
||||
import { useTraining } from '../../api/hooks/useTraining';
|
||||
|
||||
import { OnboardingRouter } from '../../utils/onboardingRouter';
|
||||
import type { RootState } from '../../store';
|
||||
|
||||
interface OnboardingPageProps {
|
||||
user: any;
|
||||
onComplete: () => void;
|
||||
user?: any;
|
||||
onComplete?: () => void;
|
||||
}
|
||||
|
||||
interface BakeryData {
|
||||
@@ -48,7 +51,16 @@ const MADRID_PRODUCTS = [
|
||||
'Chocolate caliente', 'Zumos', 'Bocadillos', 'Empanadas', 'Tartas'
|
||||
];
|
||||
|
||||
const OnboardingPage: React.FC<OnboardingPageProps> = ({ user, onComplete }) => {
|
||||
const OnboardingPage: React.FC<OnboardingPageProps> = ({ user: propUser, onComplete: propOnComplete }) => {
|
||||
const navigate = useNavigate();
|
||||
const { user: reduxUser } = useSelector((state: RootState) => state.auth);
|
||||
|
||||
// Use prop user if provided, otherwise use Redux user
|
||||
const user = propUser || reduxUser;
|
||||
|
||||
// Use prop onComplete if provided, otherwise navigate to dashboard
|
||||
const onComplete = propOnComplete || (() => navigate('/app/dashboard'));
|
||||
|
||||
const [currentStep, setCurrentStep] = useState(1);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const manualNavigation = useRef(false);
|
||||
|
||||
Reference in New Issue
Block a user