Added My Schedule tab in attendance screen
Allow 1 Day, Whole Week and Date Range swapping
This commit is contained in:
@@ -34,6 +34,17 @@ import '../theme/m3_motion.dart';
|
||||
|
||||
import '../utils/navigation.dart';
|
||||
|
||||
String _defaultRouteForRole(String? role) {
|
||||
switch (role) {
|
||||
case 'it_staff':
|
||||
return '/tasks';
|
||||
case 'standard':
|
||||
return '/tickets';
|
||||
default:
|
||||
return '/dashboard';
|
||||
}
|
||||
}
|
||||
|
||||
final appRouterProvider = Provider<GoRouter>((ref) {
|
||||
final notifier = RouterNotifier(ref);
|
||||
ref.onDispose(notifier.dispose);
|
||||
@@ -71,7 +82,19 @@ final appRouterProvider = Provider<GoRouter>((ref) {
|
||||
return '/login';
|
||||
}
|
||||
if (isSignedIn && isAuthRoute) {
|
||||
return '/dashboard';
|
||||
// If role already loaded, redirect directly and clear any pending flag
|
||||
if (role != null) notifier._needsRoleRedirect = false;
|
||||
return _defaultRouteForRole(role);
|
||||
}
|
||||
// Deferred post-login redirect: profile loaded after the initial redirect
|
||||
// (which fell back to /dashboard because role was null). Only fires once
|
||||
// per sign-in and only when the user is still on /dashboard.
|
||||
if (isSignedIn &&
|
||||
notifier._needsRoleRedirect &&
|
||||
role != null &&
|
||||
state.matchedLocation == '/dashboard') {
|
||||
notifier._needsRoleRedirect = false;
|
||||
return _defaultRouteForRole(role);
|
||||
}
|
||||
if (isAdminRoute && !isAdmin) {
|
||||
return '/tickets';
|
||||
@@ -274,8 +297,9 @@ class RouterNotifier extends ChangeNotifier {
|
||||
? previous.value?.session
|
||||
: null;
|
||||
if (session != null && previousSession == null) {
|
||||
// User just signed in; enforce lock check
|
||||
// User just signed in; enforce lock check and flag for role-based redirect
|
||||
_enforceLockAsync();
|
||||
_needsRoleRedirect = true;
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
@@ -290,6 +314,10 @@ class RouterNotifier extends ChangeNotifier {
|
||||
late final ProviderSubscription _profileSub;
|
||||
bool _lockEnforcementInProgress = false;
|
||||
|
||||
/// Set on new sign-in. Consumed by the redirect function to send the user
|
||||
/// to their role-appropriate landing page once the profile has loaded.
|
||||
bool _needsRoleRedirect = false;
|
||||
|
||||
/// Safely enforce lock in the background, preventing concurrent calls
|
||||
void _enforceLockAsync() {
|
||||
// Prevent concurrent enforcement calls
|
||||
|
||||
Reference in New Issue
Block a user