From 24da0a4d040d4731acc765c5a194d7c64fcaa04b Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Sat, 24 Jan 2026 11:48:40 -0500 Subject: [PATCH] refactor(staff_main): enforce strict architecture and clean code - Added StaffMainRoutes constants to avoid magic strings - Enhanced StaffMainNavigator with typed tab navigation - Updated StaffMainCubit to use typed navigation - Updated StaffMainModule to use route constants --- .../presentation/blocs/staff_main_cubit.dart | 22 ++++++++------- .../constants/staff_main_routes.dart | 16 +++++++++++ .../navigation/staff_main_navigator.dart | 28 ++++++++++++++++++- .../staff_main/lib/src/staff_main_module.dart | 11 ++++---- 4 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 apps/mobile/packages/features/staff/staff_main/lib/src/presentation/constants/staff_main_routes.dart diff --git a/apps/mobile/packages/features/staff/staff_main/lib/src/presentation/blocs/staff_main_cubit.dart b/apps/mobile/packages/features/staff/staff_main/lib/src/presentation/blocs/staff_main_cubit.dart index ae3dc5f8..8031c056 100644 --- a/apps/mobile/packages/features/staff/staff_main/lib/src/presentation/blocs/staff_main_cubit.dart +++ b/apps/mobile/packages/features/staff/staff_main/lib/src/presentation/blocs/staff_main_cubit.dart @@ -1,6 +1,8 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_modular/flutter_modular.dart'; import 'package:staff_main/src/presentation/blocs/staff_main_state.dart'; +import 'package:staff_main/src/presentation/constants/staff_main_routes.dart'; +import 'package:staff_main/src/presentation/navigation/staff_main_navigator.dart'; class StaffMainCubit extends Cubit implements Disposable { StaffMainCubit() : super(const StaffMainState()) { @@ -14,15 +16,15 @@ class StaffMainCubit extends Cubit implements Disposable { // Detect which tab is active based on the route path // Using contains() to handle child routes and trailing slashes - if (path.contains('/staff-main/shifts')) { + if (path.contains(StaffMainRoutes.shiftsFull)) { newIndex = 0; - } else if (path.contains('/staff-main/payments')) { + } else if (path.contains(StaffMainRoutes.paymentsFull)) { newIndex = 1; - } else if (path.contains('/staff-main/home')) { + } else if (path.contains(StaffMainRoutes.homeFull)) { newIndex = 2; - } else if (path.contains('/staff-main/clock-in')) { + } else if (path.contains(StaffMainRoutes.clockInFull)) { newIndex = 3; - } else if (path.contains('/staff-main/profile')) { + } else if (path.contains(StaffMainRoutes.profileFull)) { newIndex = 4; } @@ -36,19 +38,19 @@ class StaffMainCubit extends Cubit implements Disposable { switch (index) { case 0: - Modular.to.navigate('/staff-main/shifts'); + Modular.to.navigateToShifts(); break; case 1: - Modular.to.navigate('/staff-main/payments'); + Modular.to.navigateToPayments(); break; case 2: - Modular.to.navigate('/staff-main/home'); + Modular.to.navigateToHome(); break; case 3: - Modular.to.navigate('/staff-main/clock-in'); + Modular.to.navigateToClockIn(); break; case 4: - Modular.to.navigate('/staff-main/profile'); + Modular.to.navigateToProfile(); break; } // State update will happen via _onRouteChanged diff --git a/apps/mobile/packages/features/staff/staff_main/lib/src/presentation/constants/staff_main_routes.dart b/apps/mobile/packages/features/staff/staff_main/lib/src/presentation/constants/staff_main_routes.dart new file mode 100644 index 00000000..f56d23bd --- /dev/null +++ b/apps/mobile/packages/features/staff/staff_main/lib/src/presentation/constants/staff_main_routes.dart @@ -0,0 +1,16 @@ +abstract class StaffMainRoutes { + static const String modulePath = '/staff-main'; + + static const String shifts = '/shifts'; + static const String payments = '/payments'; + static const String home = '/home'; + static const String clockIn = '/clock-in'; + static const String profile = '/profile'; + + // Full paths + static const String shiftsFull = '$modulePath$shifts'; + static const String paymentsFull = '$modulePath$payments'; + static const String homeFull = '$modulePath$home'; + static const String clockInFull = '$modulePath$clockIn'; + static const String profileFull = '$modulePath$profile'; +} diff --git a/apps/mobile/packages/features/staff/staff_main/lib/src/presentation/navigation/staff_main_navigator.dart b/apps/mobile/packages/features/staff/staff_main/lib/src/presentation/navigation/staff_main_navigator.dart index a904d5dc..1db3b7f5 100644 --- a/apps/mobile/packages/features/staff/staff_main/lib/src/presentation/navigation/staff_main_navigator.dart +++ b/apps/mobile/packages/features/staff/staff_main/lib/src/presentation/navigation/staff_main_navigator.dart @@ -1,10 +1,36 @@ import 'package:flutter_modular/flutter_modular.dart'; +import '../constants/staff_main_routes.dart'; /// Extension to provide typed navigation for the Staff Main feature. extension StaffMainNavigator on IModularNavigator { /// Navigates to the Staff Main Shell (Home). /// This replaces the current navigation stack. void navigateStaffMain() { - navigate('/staff-main/'); + navigate('${StaffMainRoutes.modulePath}/'); + } + + /// Navigates to the Shifts tab. + void navigateToShifts() { + navigate(StaffMainRoutes.shiftsFull); + } + + /// Navigates to the Payments tab. + void navigateToPayments() { + navigate(StaffMainRoutes.paymentsFull); + } + + /// Navigates to the Home tab. + void navigateToHome() { + navigate(StaffMainRoutes.homeFull); + } + + /// Navigates to the Clock In tab. + void navigateToClockIn() { + navigate(StaffMainRoutes.clockInFull); + } + + /// Navigates to the Profile tab. + void navigateToProfile() { + navigate(StaffMainRoutes.profileFull); } } diff --git a/apps/mobile/packages/features/staff/staff_main/lib/src/staff_main_module.dart b/apps/mobile/packages/features/staff/staff_main/lib/src/staff_main_module.dart index 74b5cec6..c922e6bf 100644 --- a/apps/mobile/packages/features/staff/staff_main/lib/src/staff_main_module.dart +++ b/apps/mobile/packages/features/staff/staff_main/lib/src/staff_main_module.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_modular/flutter_modular.dart'; import 'package:staff_main/src/presentation/blocs/staff_main_cubit.dart'; +import 'package:staff_main/src/presentation/constants/staff_main_routes.dart'; import 'package:staff_main/src/presentation/pages/placeholder_page.dart'; import 'package:staff_main/src/presentation/pages/staff_main_page.dart'; @@ -18,26 +19,26 @@ class StaffMainModule extends Module { child: (BuildContext context) => const StaffMainPage(), children: >[ ChildRoute( - '/shifts', + StaffMainRoutes.shifts, child: (BuildContext context) => const PlaceholderPage(title: 'Shifts'), ), ChildRoute( - '/payments', + StaffMainRoutes.payments, child: (BuildContext context) => const PlaceholderPage(title: 'Payments'), ), ChildRoute( - '/home', + StaffMainRoutes.home, child: (BuildContext context) => const PlaceholderPage(title: 'Home'), ), ChildRoute( - '/clock-in', + StaffMainRoutes.clockIn, child: (BuildContext context) => const PlaceholderPage(title: 'Clock In'), ), ChildRoute( - '/profile', + StaffMainRoutes.profile, child: (BuildContext context) => const PlaceholderPage(title: 'Profile'), ),