feat: Integrate staff name retrieval and display in home header
This commit is contained in:
@@ -11,7 +11,6 @@ extension TimestampExt on Timestamp {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class HomeRepositoryImpl implements HomeRepository {
|
||||
HomeRepositoryImpl();
|
||||
|
||||
@@ -73,6 +72,12 @@ class HomeRepositoryImpl implements HomeRepository {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String?> 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.
|
||||
|
||||
|
||||
@@ -14,4 +14,7 @@ abstract class HomeRepository {
|
||||
|
||||
/// Retrieves shifts recommended for the worker based on their profile.
|
||||
Future<List<Shift>> getRecommendedShifts();
|
||||
|
||||
/// Retrieves the current staff member's name.
|
||||
Future<String?> getStaffName();
|
||||
}
|
||||
|
||||
@@ -10,9 +10,11 @@ part 'home_state.dart';
|
||||
/// Simple Cubit to manage home page state (shifts + loading/error).
|
||||
class HomeCubit extends Cubit<HomeState> {
|
||||
final GetHomeShifts _getHomeShifts;
|
||||
final HomeRepository _repository;
|
||||
|
||||
HomeCubit(HomeRepository repository)
|
||||
: _getHomeShifts = GetHomeShifts(repository),
|
||||
_repository = repository,
|
||||
super(const HomeState.initial());
|
||||
|
||||
Future<void> loadShifts() async {
|
||||
@@ -20,6 +22,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
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<HomeState> {
|
||||
todayShifts: result.today,
|
||||
tomorrowShifts: result.tomorrow,
|
||||
recommendedShifts: result.recommended,
|
||||
staffName: name,
|
||||
// Mock profile status for now, ideally fetched from a user repository
|
||||
isProfileComplete: false,
|
||||
),
|
||||
|
||||
@@ -9,6 +9,7 @@ class HomeState extends Equatable {
|
||||
final List<Shift> 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<Shift>? 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<Object?> get props => [
|
||||
status,
|
||||
todayShifts,
|
||||
tomorrowShifts,
|
||||
recommendedShifts,
|
||||
autoMatchEnabled,
|
||||
isProfileComplete,
|
||||
errorMessage,
|
||||
];
|
||||
}
|
||||
status,
|
||||
todayShifts,
|
||||
tomorrowShifts,
|
||||
recommendedShifts,
|
||||
autoMatchEnabled,
|
||||
isProfileComplete,
|
||||
staffName,
|
||||
errorMessage,
|
||||
];
|
||||
}
|
||||
@@ -48,7 +48,12 @@ class WorkerHomePage extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const HomeHeader(),
|
||||
BlocBuilder<HomeCubit, HomeState>(
|
||||
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(
|
||||
|
||||
@@ -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),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user