Fix issues

This commit is contained in:
Urtzi Alfaro
2025-08-17 10:28:58 +02:00
parent 8914786973
commit 109961ef6e
10 changed files with 450 additions and 176 deletions

View File

@@ -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>
);
}

View File

@@ -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">