Implement profile completion checks in shift details flow and update UI accordingly
This commit is contained in:
@@ -20,7 +20,6 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
|
||||
@override
|
||||
Future<bool> getProfileCompletion() async {
|
||||
return true;
|
||||
return _service.run(() async {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:krow_core/core.dart';
|
||||
import 'package:krow_data_connect/krow_data_connect.dart';
|
||||
import '../../../domain/usecases/apply_for_shift_usecase.dart';
|
||||
import '../../../domain/usecases/decline_shift_usecase.dart';
|
||||
import '../../../domain/usecases/get_shift_details_usecase.dart';
|
||||
@@ -12,11 +13,13 @@ class ShiftDetailsBloc extends Bloc<ShiftDetailsEvent, ShiftDetailsState>
|
||||
final GetShiftDetailsUseCase getShiftDetails;
|
||||
final ApplyForShiftUseCase applyForShift;
|
||||
final DeclineShiftUseCase declineShift;
|
||||
final GetProfileCompletionUseCase getProfileCompletion;
|
||||
|
||||
ShiftDetailsBloc({
|
||||
required this.getShiftDetails,
|
||||
required this.applyForShift,
|
||||
required this.declineShift,
|
||||
required this.getProfileCompletion,
|
||||
}) : super(ShiftDetailsInitial()) {
|
||||
on<LoadShiftDetailsEvent>(_onLoadDetails);
|
||||
on<BookShiftDetailsEvent>(_onBookShift);
|
||||
@@ -34,8 +37,9 @@ class ShiftDetailsBloc extends Bloc<ShiftDetailsEvent, ShiftDetailsState>
|
||||
final shift = await getShiftDetails(
|
||||
GetShiftDetailsArguments(shiftId: event.shiftId, roleId: event.roleId),
|
||||
);
|
||||
final isProfileComplete = await getProfileCompletion();
|
||||
if (shift != null) {
|
||||
emit(ShiftDetailsLoaded(shift));
|
||||
emit(ShiftDetailsLoaded(shift, isProfileComplete: isProfileComplete));
|
||||
} else {
|
||||
emit(const ShiftDetailsError("Shift not found"));
|
||||
}
|
||||
|
||||
@@ -14,10 +14,11 @@ class ShiftDetailsLoading extends ShiftDetailsState {}
|
||||
|
||||
class ShiftDetailsLoaded extends ShiftDetailsState {
|
||||
final Shift shift;
|
||||
const ShiftDetailsLoaded(this.shift);
|
||||
final bool isProfileComplete;
|
||||
const ShiftDetailsLoaded(this.shift, {this.isProfileComplete = false});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [shift];
|
||||
List<Object?> get props => [shift, isProfileComplete];
|
||||
}
|
||||
|
||||
class ShiftDetailsError extends ShiftDetailsState {
|
||||
|
||||
@@ -125,6 +125,9 @@ class _ShiftDetailsPageState extends State<ShiftDetailsPage> {
|
||||
|
||||
final Shift displayShift = widget.shift;
|
||||
final i18n = Translations.of(context).staff_shifts.shift_details;
|
||||
final isProfileComplete = state is ShiftDetailsLoaded
|
||||
? state.isProfileComplete
|
||||
: false;
|
||||
|
||||
final duration = _calculateDuration(displayShift);
|
||||
final estimatedTotal =
|
||||
@@ -142,6 +145,16 @@ class _ShiftDetailsPageState extends State<ShiftDetailsPage> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (!isProfileComplete)
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(UiConstants.space6),
|
||||
child: UiNoticeBanner(
|
||||
title: 'Complete Your Account',
|
||||
description:
|
||||
'Complete your account to book this shift and start earning',
|
||||
icon: UiIcons.sparkles,
|
||||
),
|
||||
),
|
||||
ShiftDetailsHeader(shift: displayShift),
|
||||
const Divider(height: 1, thickness: 0.5),
|
||||
ShiftStatsRow(
|
||||
@@ -194,20 +207,21 @@ class _ShiftDetailsPageState extends State<ShiftDetailsPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
ShiftDetailsBottomBar(
|
||||
shift: displayShift,
|
||||
onApply: () => _bookShift(context, displayShift),
|
||||
onDecline: () => BlocProvider.of<ShiftDetailsBloc>(
|
||||
context,
|
||||
).add(DeclineShiftDetailsEvent(displayShift.id)),
|
||||
onAccept: () =>
|
||||
BlocProvider.of<ShiftDetailsBloc>(context).add(
|
||||
BookShiftDetailsEvent(
|
||||
displayShift.id,
|
||||
roleId: displayShift.roleId,
|
||||
if (isProfileComplete)
|
||||
ShiftDetailsBottomBar(
|
||||
shift: displayShift,
|
||||
onApply: () => _bookShift(context, displayShift),
|
||||
onDecline: () => BlocProvider.of<ShiftDetailsBloc>(
|
||||
context,
|
||||
).add(DeclineShiftDetailsEvent(displayShift.id)),
|
||||
onAccept: () =>
|
||||
BlocProvider.of<ShiftDetailsBloc>(context).add(
|
||||
BookShiftDetailsEvent(
|
||||
displayShift.id,
|
||||
roleId: displayShift.roleId,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter_modular/flutter_modular.dart';
|
||||
import 'package:krow_data_connect/krow_data_connect.dart';
|
||||
import 'domain/repositories/shifts_repository_interface.dart';
|
||||
import 'data/repositories_impl/shifts_repository_impl.dart';
|
||||
import 'domain/usecases/get_shift_details_usecase.dart';
|
||||
@@ -14,11 +15,21 @@ class ShiftDetailsModule extends Module {
|
||||
// Repository
|
||||
i.add<ShiftsRepositoryInterface>(ShiftsRepositoryImpl.new);
|
||||
|
||||
// StaffConnectorRepository for profile completion
|
||||
i.addLazySingleton<StaffConnectorRepository>(
|
||||
() => StaffConnectorRepositoryImpl(),
|
||||
);
|
||||
|
||||
// UseCases
|
||||
i.add(GetShiftDetailsUseCase.new);
|
||||
i.add(AcceptShiftUseCase.new);
|
||||
i.add(DeclineShiftUseCase.new);
|
||||
i.add(ApplyForShiftUseCase.new);
|
||||
i.addLazySingleton<GetProfileCompletionUseCase>(
|
||||
() => GetProfileCompletionUseCase(
|
||||
repository: i.get<StaffConnectorRepository>(),
|
||||
),
|
||||
);
|
||||
|
||||
// Bloc
|
||||
i.add(ShiftDetailsBloc.new);
|
||||
|
||||
@@ -32,18 +32,18 @@ class StaffShiftsModule extends Module {
|
||||
);
|
||||
|
||||
// Repository
|
||||
i.add<ShiftsRepositoryInterface>(ShiftsRepositoryImpl.new);
|
||||
i.addLazySingleton<ShiftsRepositoryInterface>(ShiftsRepositoryImpl.new);
|
||||
|
||||
// UseCases
|
||||
i.add(GetMyShiftsUseCase.new);
|
||||
i.add(GetAvailableShiftsUseCase.new);
|
||||
i.add(GetPendingAssignmentsUseCase.new);
|
||||
i.add(GetCancelledShiftsUseCase.new);
|
||||
i.add(GetHistoryShiftsUseCase.new);
|
||||
i.add(AcceptShiftUseCase.new);
|
||||
i.add(DeclineShiftUseCase.new);
|
||||
i.add(ApplyForShiftUseCase.new);
|
||||
i.add(GetShiftDetailsUseCase.new);
|
||||
i.addLazySingleton(GetMyShiftsUseCase.new);
|
||||
i.addLazySingleton(GetAvailableShiftsUseCase.new);
|
||||
i.addLazySingleton(GetPendingAssignmentsUseCase.new);
|
||||
i.addLazySingleton(GetCancelledShiftsUseCase.new);
|
||||
i.addLazySingleton(GetHistoryShiftsUseCase.new);
|
||||
i.addLazySingleton(AcceptShiftUseCase.new);
|
||||
i.addLazySingleton(DeclineShiftUseCase.new);
|
||||
i.addLazySingleton(ApplyForShiftUseCase.new);
|
||||
i.addLazySingleton(GetShiftDetailsUseCase.new);
|
||||
|
||||
// Bloc
|
||||
i.add(
|
||||
|
||||
Reference in New Issue
Block a user