modification hubs to dont call businees again and use session

This commit is contained in:
José Salazar
2026-01-22 18:21:44 -05:00
parent a70468ceb4
commit 41175109ee

View File

@@ -79,6 +79,30 @@ class HubRepositoryImpl implements HubRepositoryInterface {
}
Future<dc.GetBusinessesByUserIdBusinesses> _getBusinessForCurrentUser() async {
final session = dc.ClientSessionStore.instance.session;
final cachedBusiness = session?.business;
if (cachedBusiness != null) {
return dc.GetBusinessesByUserIdBusinesses(
id: cachedBusiness.id,
businessName: cachedBusiness.businessName,
userId: _firebaseAuth.currentUser?.uid ?? '',
rateGroup: dc.Known(dc.BusinessRateGroup.STANDARD),
status: dc.Known(dc.BusinessStatus.ACTIVE),
contactName: cachedBusiness.contactName,
companyLogoUrl: cachedBusiness.companyLogoUrl,
phone: null,
email: cachedBusiness.email,
hubBuilding: null,
address: null,
city: cachedBusiness.city,
area: null,
sector: null,
notes: null,
createdAt: null,
updatedAt: null,
);
}
final user = _firebaseAuth.currentUser;
if (user == null) {
throw Exception('User is not authenticated.');
@@ -92,7 +116,25 @@ class HubRepositoryImpl implements HubRepositoryInterface {
throw Exception('No business found for this user. Please sign in again.');
}
return result.data.businesses.first;
final business = result.data.businesses.first;
if (session != null) {
dc.ClientSessionStore.instance.setSession(
dc.ClientSession(
user: session.user,
userPhotoUrl: session.userPhotoUrl,
business: dc.ClientBusinessSession(
id: business.id,
businessName: business.businessName,
email: business.email,
city: business.city,
contactName: business.contactName,
companyLogoUrl: business.companyLogoUrl,
),
),
);
}
return business;
}
Future<String> _getOrCreateTeamId(