Add frontend loading imporvements
This commit is contained in:
@@ -131,68 +131,27 @@ export const useTenantInitializer = () => {
|
||||
console.log('✅ [TenantInitializer] Set API client tenant ID:', virtualTenantId);
|
||||
});
|
||||
|
||||
// For enterprise demos, wait for session to be ready, then load tenants
|
||||
// For enterprise demos, load child tenants immediately (session is already ready when we navigate here)
|
||||
if (demoAccountType === 'enterprise') {
|
||||
console.log('🔄 [TenantInitializer] Waiting for enterprise demo session to be ready...');
|
||||
console.log('🔄 [TenantInitializer] Loading available tenants for enterprise demo...');
|
||||
const mockUserId = 'demo-user';
|
||||
|
||||
// Poll session status until ready
|
||||
const pollSessionStatus = async (sessionId: string, maxAttempts = 30) => {
|
||||
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
||||
try {
|
||||
const response = await fetch(`/api/v1/demo-sessions/${sessionId}/status`);
|
||||
if (response.ok) {
|
||||
const status = await response.json();
|
||||
console.log(`⏳ [TenantInitializer] Session status poll ${attempt}/${maxAttempts}:`, status.status);
|
||||
|
||||
if (status.status === 'ready') {
|
||||
console.log('✅ [TenantInitializer] Demo session is ready!');
|
||||
return true;
|
||||
} else if (status.status === 'failed') {
|
||||
console.error('❌ [TenantInitializer] Demo session failed:', status);
|
||||
return false;
|
||||
}
|
||||
// Status is 'initializing' or 'cloning_data' - continue polling
|
||||
import('../api/services/tenant').then(({ TenantService }) => {
|
||||
const tenantService = new TenantService();
|
||||
tenantService.getUserTenants(mockUserId)
|
||||
.then(tenants => {
|
||||
console.log('📋 [TenantInitializer] Loaded available tenants:', tenants.length);
|
||||
if (tenants.length === 0) {
|
||||
console.warn('⚠️ [TenantInitializer] No child tenants found yet - they may still be cloning');
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`⚠️ [TenantInitializer] Status poll ${attempt} failed:`, error);
|
||||
}
|
||||
|
||||
// Wait 1 second before next poll (except on last attempt)
|
||||
if (attempt < maxAttempts) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
console.error('❌ [TenantInitializer] Session readiness timeout after 30 seconds');
|
||||
return false;
|
||||
};
|
||||
|
||||
// Wait for session to be ready, then load tenants
|
||||
pollSessionStatus(demoSessionId).then(isReady => {
|
||||
if (isReady) {
|
||||
console.log('🔄 [TenantInitializer] Loading available tenants for enterprise demo...');
|
||||
const mockUserId = 'demo-user';
|
||||
|
||||
import('../api/services/tenant').then(({ TenantService }) => {
|
||||
const tenantService = new TenantService();
|
||||
tenantService.getUserTenants(mockUserId)
|
||||
.then(tenants => {
|
||||
console.log('📋 [TenantInitializer] Loaded available tenants:', tenants.length);
|
||||
if (tenants.length === 0) {
|
||||
console.warn('⚠️ [TenantInitializer] Session ready but no tenants found - possible sync issue');
|
||||
}
|
||||
// Update the tenant store with available tenants
|
||||
import('../stores/tenant.store').then(({ useTenantStore }) => {
|
||||
useTenantStore.getState().setAvailableTenants(tenants);
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('❌ [TenantInitializer] Failed to load available tenants:', error);
|
||||
});
|
||||
// Update the tenant store with available tenants
|
||||
import('../stores/tenant.store').then(({ useTenantStore }) => {
|
||||
useTenantStore.getState().setAvailableTenants(tenants);
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('❌ [TenantInitializer] Failed to load available tenants:', error);
|
||||
});
|
||||
} else {
|
||||
console.error('❌ [TenantInitializer] Cannot load tenants - session not ready');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user