Fix new services implementation 7
This commit is contained in:
@@ -104,17 +104,36 @@ export const useTenantId = () => {
|
||||
const fetchTenantIdFromAPI = useCallback(async (): Promise<string | null> => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
console.log('🔍 useTenantId: Fetching tenants from API...');
|
||||
const tenants = await tenantService.getUserTenants();
|
||||
console.log('📋 useTenantId: Received tenants:', tenants);
|
||||
console.log('📊 useTenantId: Tenants array length:', tenants?.length);
|
||||
|
||||
if (tenants.length > 0) {
|
||||
const firstTenantId = tenants[0].id;
|
||||
// Handle both array and object responses
|
||||
let tenantsArray;
|
||||
if (Array.isArray(tenants)) {
|
||||
tenantsArray = tenants;
|
||||
} else if (tenants && typeof tenants === 'object') {
|
||||
// Convert object with numeric keys to array
|
||||
tenantsArray = Object.values(tenants);
|
||||
} else {
|
||||
tenantsArray = [];
|
||||
}
|
||||
|
||||
console.log('🔄 useTenantId: Converted to array:', tenantsArray);
|
||||
console.log('📏 useTenantId: Array length:', tenantsArray.length);
|
||||
|
||||
if (tenantsArray && tenantsArray.length > 0) {
|
||||
const firstTenantId = tenantsArray[0].id;
|
||||
console.log('🎯 useTenantId: First tenant ID:', firstTenantId);
|
||||
storeTenantId(firstTenantId);
|
||||
return firstTenantId;
|
||||
}
|
||||
|
||||
console.log('❌ useTenantId: No tenants found or empty array');
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch tenant ID from API:', error);
|
||||
console.error('❌ useTenantId: Failed to fetch tenant ID from API:', error);
|
||||
setError('Failed to fetch tenant information');
|
||||
return null;
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user