From 3ed1add2cc356beabda5713299f6f4ff154846d7 Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Sun, 1 Feb 2026 02:38:28 -0500 Subject: [PATCH] feat: Integrate staff name retrieval and display in home header --- .../repositories/home_repository_impl.dart | 7 +- .../domain/repositories/home_repository.dart | 3 + .../src/presentation/blocs/home_cubit.dart | 4 + .../src/presentation/blocs/home_state.dart | 23 +++--- .../presentation/pages/worker_home_page.dart | 7 +- .../widgets/home_page/home_header.dart | 77 ++++++++++--------- 6 files changed, 74 insertions(+), 47 deletions(-) diff --git a/apps/mobile/packages/features/staff/home/lib/src/data/repositories/home_repository_impl.dart b/apps/mobile/packages/features/staff/home/lib/src/data/repositories/home_repository_impl.dart index 4798952c..d2d61c63 100644 --- a/apps/mobile/packages/features/staff/home/lib/src/data/repositories/home_repository_impl.dart +++ b/apps/mobile/packages/features/staff/home/lib/src/data/repositories/home_repository_impl.dart @@ -11,7 +11,6 @@ extension TimestampExt on Timestamp { } } - class HomeRepositoryImpl implements HomeRepository { HomeRepositoryImpl(); @@ -73,6 +72,12 @@ class HomeRepositoryImpl implements HomeRepository { } } + @override + Future getStaffName() async { + final session = StaffSessionStore.instance.session; + return session?.staff?.name; + } + // Mappers specific to Home's Domain Entity 'Shift' // Note: Home's 'Shift' entity might differ slightly from 'StaffPayment' Shift. diff --git a/apps/mobile/packages/features/staff/home/lib/src/domain/repositories/home_repository.dart b/apps/mobile/packages/features/staff/home/lib/src/domain/repositories/home_repository.dart index 320061d6..df35f9d2 100644 --- a/apps/mobile/packages/features/staff/home/lib/src/domain/repositories/home_repository.dart +++ b/apps/mobile/packages/features/staff/home/lib/src/domain/repositories/home_repository.dart @@ -14,4 +14,7 @@ abstract class HomeRepository { /// Retrieves shifts recommended for the worker based on their profile. Future> getRecommendedShifts(); + + /// Retrieves the current staff member's name. + Future getStaffName(); } diff --git a/apps/mobile/packages/features/staff/home/lib/src/presentation/blocs/home_cubit.dart b/apps/mobile/packages/features/staff/home/lib/src/presentation/blocs/home_cubit.dart index 85a16eca..792a32eb 100644 --- a/apps/mobile/packages/features/staff/home/lib/src/presentation/blocs/home_cubit.dart +++ b/apps/mobile/packages/features/staff/home/lib/src/presentation/blocs/home_cubit.dart @@ -10,9 +10,11 @@ part 'home_state.dart'; /// Simple Cubit to manage home page state (shifts + loading/error). class HomeCubit extends Cubit { final GetHomeShifts _getHomeShifts; + final HomeRepository _repository; HomeCubit(HomeRepository repository) : _getHomeShifts = GetHomeShifts(repository), + _repository = repository, super(const HomeState.initial()); Future loadShifts() async { @@ -20,6 +22,7 @@ class HomeCubit extends Cubit { emit(state.copyWith(status: HomeStatus.loading)); try { final result = await _getHomeShifts.call(); + final name = await _repository.getStaffName(); if (isClosed) return; emit( state.copyWith( @@ -27,6 +30,7 @@ class HomeCubit extends Cubit { todayShifts: result.today, tomorrowShifts: result.tomorrow, recommendedShifts: result.recommended, + staffName: name, // Mock profile status for now, ideally fetched from a user repository isProfileComplete: false, ), diff --git a/apps/mobile/packages/features/staff/home/lib/src/presentation/blocs/home_state.dart b/apps/mobile/packages/features/staff/home/lib/src/presentation/blocs/home_state.dart index e67f454b..0713d7a1 100644 --- a/apps/mobile/packages/features/staff/home/lib/src/presentation/blocs/home_state.dart +++ b/apps/mobile/packages/features/staff/home/lib/src/presentation/blocs/home_state.dart @@ -9,6 +9,7 @@ class HomeState extends Equatable { final List recommendedShifts; final bool autoMatchEnabled; final bool isProfileComplete; + final String? staffName; final String? errorMessage; const HomeState({ @@ -18,6 +19,7 @@ class HomeState extends Equatable { this.recommendedShifts = const [], this.autoMatchEnabled = false, this.isProfileComplete = false, + this.staffName, this.errorMessage, }); @@ -30,6 +32,7 @@ class HomeState extends Equatable { List? recommendedShifts, bool? autoMatchEnabled, bool? isProfileComplete, + String? staffName, String? errorMessage, }) { return HomeState( @@ -39,18 +42,20 @@ class HomeState extends Equatable { recommendedShifts: recommendedShifts ?? this.recommendedShifts, autoMatchEnabled: autoMatchEnabled ?? this.autoMatchEnabled, isProfileComplete: isProfileComplete ?? this.isProfileComplete, + staffName: staffName ?? this.staffName, errorMessage: errorMessage ?? this.errorMessage, ); } @override List get props => [ - status, - todayShifts, - tomorrowShifts, - recommendedShifts, - autoMatchEnabled, - isProfileComplete, - errorMessage, - ]; -} + status, + todayShifts, + tomorrowShifts, + recommendedShifts, + autoMatchEnabled, + isProfileComplete, + staffName, + errorMessage, + ]; +} \ No newline at end of file diff --git a/apps/mobile/packages/features/staff/home/lib/src/presentation/pages/worker_home_page.dart b/apps/mobile/packages/features/staff/home/lib/src/presentation/pages/worker_home_page.dart index 61ff3d9e..1cbb51fc 100644 --- a/apps/mobile/packages/features/staff/home/lib/src/presentation/pages/worker_home_page.dart +++ b/apps/mobile/packages/features/staff/home/lib/src/presentation/pages/worker_home_page.dart @@ -48,7 +48,12 @@ class WorkerHomePage extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const HomeHeader(), + BlocBuilder( + buildWhen: (previous, current) => previous.staffName != current.staffName, + builder: (context, state) { + return HomeHeader(userName: state.staffName); + }, + ), Padding( padding: const EdgeInsets.symmetric(horizontal: UiConstants.space4), child: Column( diff --git a/apps/mobile/packages/features/staff/home/lib/src/presentation/widgets/home_page/home_header.dart b/apps/mobile/packages/features/staff/home/lib/src/presentation/widgets/home_page/home_header.dart index ea85d499..247d380e 100644 --- a/apps/mobile/packages/features/staff/home/lib/src/presentation/widgets/home_page/home_header.dart +++ b/apps/mobile/packages/features/staff/home/lib/src/presentation/widgets/home_page/home_header.dart @@ -2,15 +2,21 @@ import 'package:core_localization/core_localization.dart'; import 'package:design_system/design_system.dart'; import 'package:flutter/material.dart'; - /// Header widget for the staff home page, using design system tokens. class HomeHeader extends StatelessWidget { + final String? userName; + /// Creates a [HomeHeader]. - const HomeHeader({super.key}); + const HomeHeader({super.key, this.userName}); @override Widget build(BuildContext context) { final headerI18n = t.staff.home.header; + final nameToDisplay = userName ?? headerI18n.user_name_placeholder; + final initial = nameToDisplay.isNotEmpty + ? nameToDisplay[0].toUpperCase() + : 'K'; + return Padding( padding: EdgeInsets.fromLTRB( UiConstants.space4, @@ -18,45 +24,44 @@ class HomeHeader extends StatelessWidget { UiConstants.space4, UiConstants.space3, ), - child:Row( + child: Row( + spacing: UiConstants.space3, + children: [ + Container( + width: 48, + height: 48, + decoration: BoxDecoration( + shape: BoxShape.circle, + border: Border.all( + color: UiColors.primary.withOpacity(0.2), + width: 2, + ), + ), + child: CircleAvatar( + backgroundColor: UiColors.primary.withOpacity(0.1), + child: Text( + initial, + style: const TextStyle( + color: UiColors.primary, + fontWeight: FontWeight.bold, + ), + ), + ), + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Container( - width: 48, - height: 48, - decoration: BoxDecoration( - shape: BoxShape.circle, - border: Border.all( - color: UiColors.primary.withOpacity(0.2), - width: 2, - ), - ), - child: CircleAvatar( - backgroundColor: UiColors.primary.withOpacity(0.1), - child: const Text( - 'K', - style: TextStyle( - color: UiColors.primary, - fontWeight: FontWeight.bold, - ), - ), + Text( + headerI18n.welcome_back, + style: UiTypography.body3r.copyWith( + color: UiColors.mutedForeground, ), ), - const SizedBox(width: UiConstants.space3), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - headerI18n.welcome_back, - style: UiTypography.body3r.copyWith(color: UiColors.mutedForeground), - ), - Text( - headerI18n.user_name_placeholder, - style: UiTypography.headline4m, - ), - ], - ), + Text(nameToDisplay, style: UiTypography.headline4m), ], ), + ], + ), ); } }