feat: Refactor StaffSession to remove user field and update related session handling
This commit is contained in:
@@ -76,7 +76,41 @@ class HomeRepositoryImpl
|
||||
@override
|
||||
Future<String?> getStaffName() async {
|
||||
final session = StaffSessionStore.instance.session;
|
||||
return session?.staff?.name;
|
||||
|
||||
// If session data is available, return staff name immediately
|
||||
if (session?.staff?.name != null) {
|
||||
return session!.staff!.name;
|
||||
}
|
||||
|
||||
// If session is not initialized, attempt to fetch staff data to populate session
|
||||
return await _service.run(() async {
|
||||
final staffId = await _service.getStaffId();
|
||||
final response = await _service.connector
|
||||
.getStaffById(id: staffId)
|
||||
.execute();
|
||||
|
||||
if (response.data.staff == null) {
|
||||
throw Exception('Staff data not found for ID: $staffId');
|
||||
}
|
||||
|
||||
final staff = response.data.staff!;
|
||||
final updatedSession = StaffSession(
|
||||
staff: Staff(
|
||||
id: staff.id,
|
||||
authProviderId: staff.userId,
|
||||
name: staff.fullName,
|
||||
email: staff.email ?? '',
|
||||
phone: staff.phone,
|
||||
status: StaffStatus.completedProfile,
|
||||
address: staff.addres,
|
||||
avatar: staff.photoUrl,
|
||||
),
|
||||
ownerId: session?.ownerId,
|
||||
);
|
||||
StaffSessionStore.instance.setSession(updatedSession);
|
||||
|
||||
return staff.fullName;
|
||||
});
|
||||
}
|
||||
|
||||
// Mappers specific to Home's Domain Entity 'Shift'
|
||||
|
||||
Reference in New Issue
Block a user