feat: Display staff profile completion status on the home screen.
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:krow_core/core.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import 'package:krow_data_connect/krow_data_connect.dart';
|
||||
|
||||
import 'package:staff_home/src/domain/usecases/get_home_shifts.dart';
|
||||
import 'package:staff_home/src/domain/repositories/home_repository.dart';
|
||||
@@ -13,10 +14,19 @@ class HomeCubit extends Cubit<HomeState> with BlocErrorHandler<HomeState> {
|
||||
final GetHomeShifts _getHomeShifts;
|
||||
final HomeRepository _repository;
|
||||
|
||||
HomeCubit(HomeRepository repository)
|
||||
: _getHomeShifts = GetHomeShifts(repository),
|
||||
_repository = repository,
|
||||
super(const HomeState.initial());
|
||||
/// Use case that checks whether the staff member's personal info is complete.
|
||||
///
|
||||
/// Used to determine whether profile-gated features (such as shift browsing)
|
||||
/// should be enabled on the home screen.
|
||||
final GetPersonalInfoCompletionUseCase _getPersonalInfoCompletion;
|
||||
|
||||
HomeCubit({
|
||||
required HomeRepository repository,
|
||||
required GetPersonalInfoCompletionUseCase getPersonalInfoCompletion,
|
||||
}) : _getHomeShifts = GetHomeShifts(repository),
|
||||
_repository = repository,
|
||||
_getPersonalInfoCompletion = getPersonalInfoCompletion,
|
||||
super(const HomeState.initial());
|
||||
|
||||
Future<void> loadShifts() async {
|
||||
if (isClosed) return;
|
||||
@@ -24,24 +34,30 @@ class HomeCubit extends Cubit<HomeState> with BlocErrorHandler<HomeState> {
|
||||
await handleError(
|
||||
emit: emit,
|
||||
action: () async {
|
||||
final result = await _getHomeShifts.call();
|
||||
// Fetch shifts, name, and profile completion status concurrently
|
||||
final shiftsAndProfile = await Future.wait([
|
||||
_getHomeShifts.call(),
|
||||
_getPersonalInfoCompletion.call(),
|
||||
]);
|
||||
|
||||
final homeResult = shiftsAndProfile[0] as HomeShifts;
|
||||
final isProfileComplete = shiftsAndProfile[1] as bool;
|
||||
final name = await _repository.getStaffName();
|
||||
|
||||
if (isClosed) return;
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: HomeStatus.loaded,
|
||||
todayShifts: result.today,
|
||||
tomorrowShifts: result.tomorrow,
|
||||
recommendedShifts: result.recommended,
|
||||
todayShifts: homeResult.today,
|
||||
tomorrowShifts: homeResult.tomorrow,
|
||||
recommendedShifts: homeResult.recommended,
|
||||
staffName: name,
|
||||
// Mock profile status for now, ideally fetched from a user repository
|
||||
isProfileComplete: false,
|
||||
isProfileComplete: isProfileComplete,
|
||||
),
|
||||
);
|
||||
},
|
||||
onError: (String errorKey) {
|
||||
if (isClosed)
|
||||
return state; // Avoid state emission if closed, though emit handles it gracefully usually
|
||||
if (isClosed) return state;
|
||||
return state.copyWith(status: HomeStatus.error, errorMessage: errorKey);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
import 'package:krow_core/core.dart';
|
||||
import 'package:krow_data_connect/krow_data_connect.dart';
|
||||
import 'package:staff_home/src/data/repositories/home_repository_impl.dart';
|
||||
import 'package:staff_home/src/domain/repositories/home_repository.dart';
|
||||
import 'package:staff_home/src/presentation/blocs/home_cubit.dart';
|
||||
@@ -14,11 +15,28 @@ import 'package:staff_home/src/presentation/pages/worker_home_page.dart';
|
||||
class StaffHomeModule extends Module {
|
||||
@override
|
||||
void binds(Injector i) {
|
||||
// Repository
|
||||
// Repository - provides home data (shifts, staff name)
|
||||
i.addLazySingleton<HomeRepository>(() => HomeRepositoryImpl());
|
||||
|
||||
// StaffConnectorRepository for profile completion queries
|
||||
i.addLazySingleton<StaffConnectorRepository>(
|
||||
() => StaffConnectorRepositoryImpl(),
|
||||
);
|
||||
|
||||
// Use case for checking personal info profile completion
|
||||
i.addLazySingleton<GetPersonalInfoCompletionUseCase>(
|
||||
() => GetPersonalInfoCompletionUseCase(
|
||||
repository: i.get<StaffConnectorRepository>(),
|
||||
),
|
||||
);
|
||||
|
||||
// Presentation layer - Cubit
|
||||
i.addSingleton(HomeCubit.new);
|
||||
i.addSingleton(
|
||||
() => HomeCubit(
|
||||
repository: i.get<HomeRepository>(),
|
||||
getPersonalInfoCompletion: i.get<GetPersonalInfoCompletionUseCase>(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user