Compare commits
6 Commits
26675388dd
...
e6238ca5b0
Author | SHA1 | Date | |
---|---|---|---|
e6238ca5b0 | |||
d5a8d08e63 | |||
041b62ca2f | |||
d1d48b1a74 | |||
7e75431feb | |||
45bc492683 |
@ -14,6 +14,7 @@ class LoginController extends MyController {
|
|||||||
final RxBool isLoading = false.obs;
|
final RxBool isLoading = false.obs;
|
||||||
final RxBool showPassword = false.obs;
|
final RxBool showPassword = false.obs;
|
||||||
final RxBool isChecked = false.obs;
|
final RxBool isChecked = false.obs;
|
||||||
|
final RxBool showSplash = false.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -40,18 +41,14 @@ class LoginController extends MyController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onChangeCheckBox(bool? value) {
|
void onChangeCheckBox(bool? value) => isChecked.value = value ?? false;
|
||||||
isChecked.value = value ?? false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void onChangeShowPassword() {
|
void onChangeShowPassword() => showPassword.toggle();
|
||||||
showPassword.toggle();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> onLogin() async {
|
Future<void> onLogin() async {
|
||||||
if (!basicValidator.validateForm()) return;
|
if (!basicValidator.validateForm()) return;
|
||||||
|
|
||||||
isLoading.value = true;
|
showSplash.value = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final loginData = basicValidator.getData();
|
final loginData = basicValidator.getData();
|
||||||
@ -60,49 +57,30 @@ class LoginController extends MyController {
|
|||||||
final errors = await AuthService.loginUser(loginData);
|
final errors = await AuthService.loginUser(loginData);
|
||||||
|
|
||||||
if (errors != null) {
|
if (errors != null) {
|
||||||
logSafe(
|
|
||||||
"Login failed for user: ${loginData['username']} with errors: $errors",
|
|
||||||
level: LogLevel.warning);
|
|
||||||
|
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Login Failed",
|
title: "Login Failed",
|
||||||
message: "Username or password is incorrect",
|
message: "Username or password is incorrect",
|
||||||
type: SnackbarType.error,
|
type: SnackbarType.error,
|
||||||
);
|
);
|
||||||
|
|
||||||
basicValidator.addErrors(errors);
|
basicValidator.addErrors(errors);
|
||||||
basicValidator.validateForm();
|
basicValidator.validateForm();
|
||||||
basicValidator.clearErrors();
|
basicValidator.clearErrors();
|
||||||
} else {
|
} else {
|
||||||
await _handleRememberMe();
|
await _handleRememberMe();
|
||||||
// ✅ Enable remote logging after successful login
|
|
||||||
enableRemoteLogging();
|
enableRemoteLogging();
|
||||||
logSafe("✅ Remote logging enabled after login.");
|
|
||||||
|
|
||||||
final fcmToken = await LocalStorage.getFcmToken();
|
|
||||||
if (fcmToken?.isNotEmpty ?? false) {
|
|
||||||
final success = await AuthService.registerDeviceToken(fcmToken!);
|
|
||||||
logSafe(
|
|
||||||
success
|
|
||||||
? "✅ FCM token registered after login."
|
|
||||||
: "⚠️ Failed to register FCM token after login.",
|
|
||||||
level: LogLevel.warning);
|
|
||||||
}
|
|
||||||
|
|
||||||
logSafe("Login successful for user: ${loginData['username']}");
|
logSafe("Login successful for user: ${loginData['username']}");
|
||||||
|
Get.offNamed('/select-tenant');
|
||||||
Get.toNamed('/select_tenant');
|
|
||||||
}
|
}
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stacktrace) {
|
||||||
logSafe("Exception during login",
|
|
||||||
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Login Error",
|
title: "Login Error",
|
||||||
message: "An unexpected error occurred",
|
message: "An unexpected error occurred",
|
||||||
type: SnackbarType.error,
|
type: SnackbarType.error,
|
||||||
);
|
);
|
||||||
|
logSafe("Exception during login",
|
||||||
|
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false;
|
showSplash.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,11 +112,7 @@ class LoginController extends MyController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void goToForgotPassword() {
|
void goToForgotPassword() => Get.toNamed('/auth/forgot_password');
|
||||||
Get.toNamed('/auth/forgot_password');
|
|
||||||
}
|
|
||||||
|
|
||||||
void gotoRegister() {
|
void gotoRegister() => Get.offAndToNamed('/auth/register_account');
|
||||||
Get.offAndToNamed('/auth/register_account');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,10 @@ import 'package:marco/helpers/services/auth_service.dart';
|
|||||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||||
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
||||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||||
import 'package:marco/view/dashboard/dashboard_screen.dart';
|
|
||||||
import 'package:marco/helpers/services/app_logger.dart';
|
import 'package:marco/helpers/services/app_logger.dart';
|
||||||
import 'package:marco/helpers/services/firebase/firebase_messaging_service.dart';
|
import 'package:marco/helpers/services/firebase/firebase_messaging_service.dart';
|
||||||
|
import 'package:marco/controller/permission_controller.dart';
|
||||||
|
import 'package:marco/controller/project_controller.dart';
|
||||||
|
|
||||||
class MPINController extends GetxController {
|
class MPINController extends GetxController {
|
||||||
final MyFormValidator basicValidator = MyFormValidator();
|
final MyFormValidator basicValidator = MyFormValidator();
|
||||||
@ -138,16 +139,17 @@ class MPINController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Navigate to dashboard
|
/// Navigate to dashboard
|
||||||
void _navigateToDashboard({String? message}) {
|
/// Navigate to tenant selection after MPIN verification
|
||||||
|
void _navigateToTenantSelection({String? message}) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
logSafe("Navigating to Dashboard with message: $message");
|
logSafe("Navigating to Tenant Selection with message: $message");
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Success",
|
title: "Success",
|
||||||
message: message,
|
message: message,
|
||||||
type: SnackbarType.success,
|
type: SnackbarType.success,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Get.offAll(() => const DashboardScreen());
|
Get.offAllNamed('/select-tenant');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear the primary MPIN fields
|
/// Clear the primary MPIN fields
|
||||||
@ -239,15 +241,12 @@ class MPINController extends GetxController {
|
|||||||
logSafe("verifyMPIN triggered");
|
logSafe("verifyMPIN triggered");
|
||||||
|
|
||||||
final enteredMPIN = digitControllers.map((c) => c.text).join();
|
final enteredMPIN = digitControllers.map((c) => c.text).join();
|
||||||
logSafe("Entered MPIN: $enteredMPIN");
|
|
||||||
|
|
||||||
if (enteredMPIN.length < 4) {
|
if (enteredMPIN.length < 4) {
|
||||||
_showError("Please enter all 4 digits.");
|
_showError("Please enter all 4 digits.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final mpinToken = await LocalStorage.getMpinToken();
|
final mpinToken = await LocalStorage.getMpinToken();
|
||||||
|
|
||||||
if (mpinToken == null || mpinToken.isEmpty) {
|
if (mpinToken == null || mpinToken.isEmpty) {
|
||||||
_showError("Missing MPIN token. Please log in again.");
|
_showError("Missing MPIN token. Please log in again.");
|
||||||
return;
|
return;
|
||||||
@ -270,12 +269,25 @@ class MPINController extends GetxController {
|
|||||||
logSafe("MPIN verified successfully");
|
logSafe("MPIN verified successfully");
|
||||||
await LocalStorage.setBool('mpin_verified', true);
|
await LocalStorage.setBool('mpin_verified', true);
|
||||||
|
|
||||||
|
// 🔹 Ensure controllers are injected and loaded
|
||||||
|
final token = await LocalStorage.getJwtToken();
|
||||||
|
if (token != null && token.isNotEmpty) {
|
||||||
|
if (!Get.isRegistered<PermissionController>()) {
|
||||||
|
Get.put(PermissionController());
|
||||||
|
await Get.find<PermissionController>().loadData(token);
|
||||||
|
}
|
||||||
|
if (!Get.isRegistered<ProjectController>()) {
|
||||||
|
Get.put(ProjectController(), permanent: true);
|
||||||
|
await Get.find<ProjectController>().fetchProjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Success",
|
title: "Success",
|
||||||
message: "MPIN Verified Successfully",
|
message: "MPIN Verified Successfully",
|
||||||
type: SnackbarType.success,
|
type: SnackbarType.success,
|
||||||
);
|
);
|
||||||
_navigateToDashboard();
|
_navigateToTenantSelection();
|
||||||
} else {
|
} else {
|
||||||
final errorMessage = response["error"] ?? "Invalid MPIN";
|
final errorMessage = response["error"] ?? "Invalid MPIN";
|
||||||
logSafe("MPIN verification failed: $errorMessage",
|
logSafe("MPIN verification failed: $errorMessage",
|
||||||
@ -291,11 +303,7 @@ class MPINController extends GetxController {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
logSafe("Exception in verifyMPIN", level: LogLevel.error, error: e);
|
logSafe("Exception in verifyMPIN", level: LogLevel.error, error: e);
|
||||||
showAppSnackbar(
|
_showError("Something went wrong. Please try again.");
|
||||||
title: "Error",
|
|
||||||
message: "Something went wrong. Please try again.",
|
|
||||||
type: SnackbarType.error,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,8 @@ class OTPController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void onOTPChanged(String value, int index) {
|
void onOTPChanged(String value, int index) {
|
||||||
logSafe("[OTPController] OTP field changed: index=$index", level: LogLevel.debug);
|
logSafe("[OTPController] OTP field changed: index=$index",
|
||||||
|
level: LogLevel.debug);
|
||||||
if (value.isNotEmpty) {
|
if (value.isNotEmpty) {
|
||||||
if (index < otpControllers.length - 1) {
|
if (index < otpControllers.length - 1) {
|
||||||
focusNodes[index + 1].requestFocus();
|
focusNodes[index + 1].requestFocus();
|
||||||
@ -125,30 +126,24 @@ class OTPController extends GetxController {
|
|||||||
|
|
||||||
Future<void> verifyOTP() async {
|
Future<void> verifyOTP() async {
|
||||||
final enteredOTP = otpControllers.map((c) => c.text).join();
|
final enteredOTP = otpControllers.map((c) => c.text).join();
|
||||||
logSafe("[OTPController] Verifying OTP");
|
|
||||||
|
|
||||||
final result = await AuthService.verifyOtp(
|
final result = await AuthService.verifyOtp(
|
||||||
email: email.value,
|
email: email.value,
|
||||||
otp: enteredOTP,
|
otp: enteredOTP,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
logSafe("[OTPController] OTP verified successfully");
|
// ✅ Handle remember-me like in LoginController
|
||||||
showAppSnackbar(
|
final remember = LocalStorage.getBool('remember_me') ?? false;
|
||||||
title: "Success",
|
if (remember) await LocalStorage.setToken('otp_email', email.value);
|
||||||
message: "OTP verified successfully",
|
|
||||||
type: SnackbarType.success,
|
|
||||||
);
|
|
||||||
final bool isMpinEnabled = LocalStorage.getIsMpin();
|
|
||||||
logSafe("[OTPController] MPIN Enabled: $isMpinEnabled");
|
|
||||||
|
|
||||||
Get.offAllNamed('/home');
|
// ✅ Enable remote logging
|
||||||
|
enableRemoteLogging();
|
||||||
|
|
||||||
|
Get.offAllNamed('/select-tenant');
|
||||||
} else {
|
} else {
|
||||||
final error = result['error'] ?? "Failed to verify OTP";
|
|
||||||
logSafe("[OTPController] OTP verification failed", level: LogLevel.warning, error: error);
|
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Error",
|
title: "Error",
|
||||||
message: error,
|
message: result['error']!,
|
||||||
type: SnackbarType.error,
|
type: SnackbarType.error,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -215,7 +210,8 @@ class OTPController extends GetxController {
|
|||||||
final savedEmail = LocalStorage.getToken('otp_email') ?? '';
|
final savedEmail = LocalStorage.getToken('otp_email') ?? '';
|
||||||
emailController.text = savedEmail;
|
emailController.text = savedEmail;
|
||||||
email.value = savedEmail;
|
email.value = savedEmail;
|
||||||
logSafe("[OTPController] Loaded saved email from local storage: $savedEmail");
|
logSafe(
|
||||||
|
"[OTPController] Loaded saved email from local storage: $savedEmail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,8 @@ class ResetPasswordController extends MyController {
|
|||||||
basicValidator.clearErrors();
|
basicValidator.clearErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
logSafe("[ResetPasswordController] Navigating to /home");
|
logSafe("[ResetPasswordController] Navigating to /dashboard");
|
||||||
Get.toNamed('/home');
|
Get.toNamed('/dashboard');
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
logSafe("[ResetPasswordController] Form validation failed", level: LogLevel.warning);
|
logSafe("[ResetPasswordController] Form validation failed", level: LogLevel.warning);
|
||||||
|
@ -46,8 +46,9 @@ class DashboardController extends GetxController {
|
|||||||
// Common ranges
|
// Common ranges
|
||||||
final List<String> ranges = ['7D', '15D', '30D'];
|
final List<String> ranges = ['7D', '15D', '30D'];
|
||||||
|
|
||||||
// Inject ProjectController
|
// Inside your DashboardController
|
||||||
final ProjectController projectController = Get.find<ProjectController>();
|
final ProjectController projectController =
|
||||||
|
Get.put(ProjectController(), permanent: true);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
|
@ -13,6 +13,7 @@ class PermissionController extends GetxController {
|
|||||||
var employeeInfo = Rxn<EmployeeInfo>();
|
var employeeInfo = Rxn<EmployeeInfo>();
|
||||||
var projectsInfo = <ProjectInfo>[].obs;
|
var projectsInfo = <ProjectInfo>[].obs;
|
||||||
Timer? _refreshTimer;
|
Timer? _refreshTimer;
|
||||||
|
var isLoading = true.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -26,7 +27,8 @@ class PermissionController extends GetxController {
|
|||||||
await loadData(token!);
|
await loadData(token!);
|
||||||
_startAutoRefresh();
|
_startAutoRefresh();
|
||||||
} else {
|
} else {
|
||||||
logSafe("Token is null or empty. Skipping API load and auto-refresh.", level: LogLevel.warning);
|
logSafe("Token is null or empty. Skipping API load and auto-refresh.",
|
||||||
|
level: LogLevel.warning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,19 +39,24 @@ class PermissionController extends GetxController {
|
|||||||
logSafe("Auth token retrieved: $token", level: LogLevel.debug);
|
logSafe("Auth token retrieved: $token", level: LogLevel.debug);
|
||||||
return token;
|
return token;
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stacktrace) {
|
||||||
logSafe("Error retrieving auth token", level: LogLevel.error, error: e, stackTrace: stacktrace);
|
logSafe("Error retrieving auth token",
|
||||||
|
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> loadData(String token) async {
|
Future<void> loadData(String token) async {
|
||||||
try {
|
try {
|
||||||
|
isLoading.value = true;
|
||||||
final userData = await PermissionService.fetchAllUserData(token);
|
final userData = await PermissionService.fetchAllUserData(token);
|
||||||
_updateState(userData);
|
_updateState(userData);
|
||||||
await _storeData();
|
await _storeData();
|
||||||
logSafe("Data loaded and state updated successfully.");
|
logSafe("Data loaded and state updated successfully.");
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stacktrace) {
|
||||||
logSafe("Error loading data from API", level: LogLevel.error, error: e, stackTrace: stacktrace);
|
logSafe("Error loading data from API",
|
||||||
|
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +67,8 @@ class PermissionController extends GetxController {
|
|||||||
projectsInfo.assignAll(userData['projects']);
|
projectsInfo.assignAll(userData['projects']);
|
||||||
logSafe("State updated with user data.");
|
logSafe("State updated with user data.");
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stacktrace) {
|
||||||
logSafe("Error updating state", level: LogLevel.error, error: e, stackTrace: stacktrace);
|
logSafe("Error updating state",
|
||||||
|
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +97,8 @@ class PermissionController extends GetxController {
|
|||||||
|
|
||||||
logSafe("User data successfully stored in SharedPreferences.");
|
logSafe("User data successfully stored in SharedPreferences.");
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stacktrace) {
|
||||||
logSafe("Error storing data", level: LogLevel.error, error: e, stackTrace: stacktrace);
|
logSafe("Error storing data",
|
||||||
|
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,20 +109,23 @@ class PermissionController extends GetxController {
|
|||||||
if (token?.isNotEmpty ?? false) {
|
if (token?.isNotEmpty ?? false) {
|
||||||
await loadData(token!);
|
await loadData(token!);
|
||||||
} else {
|
} else {
|
||||||
logSafe("Token missing during auto-refresh. Skipping.", level: LogLevel.warning);
|
logSafe("Token missing during auto-refresh. Skipping.",
|
||||||
|
level: LogLevel.warning);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasPermission(String permissionId) {
|
bool hasPermission(String permissionId) {
|
||||||
final hasPerm = permissions.any((p) => p.id == permissionId);
|
final hasPerm = permissions.any((p) => p.id == permissionId);
|
||||||
logSafe("Checking permission $permissionId: $hasPerm", level: LogLevel.debug);
|
logSafe("Checking permission $permissionId: $hasPerm",
|
||||||
|
level: LogLevel.debug);
|
||||||
return hasPerm;
|
return hasPerm;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isUserAssignedToProject(String projectId) {
|
bool isUserAssignedToProject(String projectId) {
|
||||||
final assigned = projectsInfo.any((project) => project.id == projectId);
|
final assigned = projectsInfo.any((project) => project.id == projectId);
|
||||||
logSafe("Checking project assignment for $projectId: $assigned", level: LogLevel.debug);
|
logSafe("Checking project assignment for $projectId: $assigned",
|
||||||
|
level: LogLevel.debug);
|
||||||
return assigned;
|
return assigned;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +78,7 @@ class DailyTaskController extends GetxController {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (response != null && response.isNotEmpty) {
|
if (response != null && response.isNotEmpty) {
|
||||||
for (var taskJson in response) {
|
for (var task in response) {
|
||||||
final task = TaskModel.fromJson(taskJson);
|
|
||||||
final assignmentDateKey =
|
final assignmentDateKey =
|
||||||
task.assignmentDate.toIso8601String().split('T')[0];
|
task.assignmentDate.toIso8601String().split('T')[0];
|
||||||
groupedDailyTasks.putIfAbsent(assignmentDateKey, () => []).add(task);
|
groupedDailyTasks.putIfAbsent(assignmentDateKey, () => []).add(task);
|
||||||
|
@ -4,12 +4,22 @@ import 'package:marco/helpers/services/tenant_service.dart';
|
|||||||
import 'package:marco/model/tenant/tenant_list_model.dart';
|
import 'package:marco/model/tenant/tenant_list_model.dart';
|
||||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||||
|
import 'package:marco/controller/permission_controller.dart';
|
||||||
|
|
||||||
class TenantSelectionController extends GetxController {
|
class TenantSelectionController extends GetxController {
|
||||||
final TenantService _tenantService = TenantService();
|
final TenantService _tenantService = TenantService();
|
||||||
|
|
||||||
var tenants = <Tenant>[].obs;
|
// Tenant list
|
||||||
var isLoading = false.obs;
|
final tenants = <Tenant>[].obs;
|
||||||
|
|
||||||
|
// Loading state
|
||||||
|
final isLoading = false.obs;
|
||||||
|
|
||||||
|
// Selected tenant ID
|
||||||
|
final selectedTenantId = RxnString();
|
||||||
|
|
||||||
|
// Flag to indicate auto-selection (for splash screen)
|
||||||
|
final isAutoSelecting = false.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -17,83 +27,97 @@ class TenantSelectionController extends GetxController {
|
|||||||
loadTenants();
|
loadTenants();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load tenants from API
|
/// Load tenants and handle auto-selection
|
||||||
Future<void> loadTenants({bool fromTenantSelectionScreen = false}) async {
|
Future<void> loadTenants() async {
|
||||||
|
isLoading.value = true;
|
||||||
|
isAutoSelecting.value = true; // show splash during auto-selection
|
||||||
try {
|
try {
|
||||||
isLoading.value = true;
|
|
||||||
final data = await _tenantService.getTenants();
|
final data = await _tenantService.getTenants();
|
||||||
if (data != null) {
|
if (data == null || data.isEmpty) {
|
||||||
tenants.value = data.map((e) => Tenant.fromJson(e)).toList();
|
|
||||||
|
|
||||||
final recentTenantId = LocalStorage.getRecentTenantId();
|
|
||||||
|
|
||||||
// ✅ If user came from TenantSelectionScreen & recent tenant exists, auto-select
|
|
||||||
if (fromTenantSelectionScreen && recentTenantId != null) {
|
|
||||||
final tenantExists = tenants.any((t) => t.id == recentTenantId);
|
|
||||||
if (tenantExists) {
|
|
||||||
await onTenantSelected(recentTenantId);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
// if tenant is no longer valid, clear recentTenant
|
|
||||||
await LocalStorage.removeRecentTenantId();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ✅ Auto-select if only one tenant
|
|
||||||
if (tenants.length == 1) {
|
|
||||||
await onTenantSelected(tenants.first.id);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tenants.clear();
|
tenants.clear();
|
||||||
logSafe("⚠️ No tenants found for the user.", level: LogLevel.warning);
|
logSafe("⚠️ No tenants found for the user.", level: LogLevel.warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tenants.value = data.map((e) => Tenant.fromJson(e)).toList();
|
||||||
|
|
||||||
|
final recentTenantId = LocalStorage.getRecentTenantId();
|
||||||
|
|
||||||
|
// Auto-select if only one tenant
|
||||||
|
if (tenants.length == 1) {
|
||||||
|
await _selectTenant(tenants.first.id);
|
||||||
|
}
|
||||||
|
// Auto-select recent tenant if available
|
||||||
|
else if (recentTenantId != null) {
|
||||||
|
final recentTenant =
|
||||||
|
tenants.firstWhereOrNull((t) => t.id == recentTenantId);
|
||||||
|
if (recentTenant != null) {
|
||||||
|
await _selectTenant(recentTenant.id);
|
||||||
|
} else {
|
||||||
|
_clearSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// No auto-selection
|
||||||
|
else {
|
||||||
|
_clearSelection();
|
||||||
}
|
}
|
||||||
} catch (e, st) {
|
} catch (e, st) {
|
||||||
logSafe("❌ Exception in loadTenants",
|
logSafe("❌ Exception in loadTenants",
|
||||||
level: LogLevel.error, error: e, stackTrace: st);
|
level: LogLevel.error, error: e, stackTrace: st);
|
||||||
|
showAppSnackbar(
|
||||||
|
title: "Error",
|
||||||
|
message: "Failed to load organizations. Please try again.",
|
||||||
|
type: SnackbarType.error,
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
|
isAutoSelecting.value = false; // hide splash
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Select tenant
|
/// User manually selects a tenant
|
||||||
Future<void> onTenantSelected(String tenantId) async {
|
Future<void> onTenantSelected(String tenantId) async {
|
||||||
|
isAutoSelecting.value = true;
|
||||||
|
await _selectTenant(tenantId);
|
||||||
|
isAutoSelecting.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Internal tenant selection logic
|
||||||
|
Future<void> _selectTenant(String tenantId) async {
|
||||||
try {
|
try {
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
|
|
||||||
final success = await _tenantService.selectTenant(tenantId);
|
final success = await _tenantService.selectTenant(tenantId);
|
||||||
if (success) {
|
if (!success) {
|
||||||
logSafe("✅ Tenant selection successful: $tenantId");
|
|
||||||
|
|
||||||
// Store selected tenant in memory
|
|
||||||
final selectedTenant = tenants.firstWhere((t) => t.id == tenantId);
|
|
||||||
TenantService.setSelectedTenant(selectedTenant);
|
|
||||||
|
|
||||||
// 🔥 Save in LocalStorage
|
|
||||||
await LocalStorage.setRecentTenantId(tenantId);
|
|
||||||
|
|
||||||
// Navigate to dashboard
|
|
||||||
Get.offAllNamed('/dashboard');
|
|
||||||
|
|
||||||
showAppSnackbar(
|
|
||||||
title: "Success",
|
|
||||||
message: "Organization selected successfully.",
|
|
||||||
type: SnackbarType.success,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
logSafe("❌ Tenant selection failed for: $tenantId",
|
|
||||||
level: LogLevel.warning);
|
|
||||||
|
|
||||||
// Show error snackbar
|
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Error",
|
title: "Error",
|
||||||
message: "Unable to select organization. Please try again.",
|
message: "Unable to select organization. Please try again.",
|
||||||
type: SnackbarType.error,
|
type: SnackbarType.error,
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} catch (e, st) {
|
|
||||||
logSafe("❌ Exception in onTenantSelected",
|
|
||||||
level: LogLevel.error, error: e, stackTrace: st);
|
|
||||||
|
|
||||||
// Show error snackbar for exception
|
// Update tenant & persist
|
||||||
|
final selectedTenant = tenants.firstWhere((t) => t.id == tenantId);
|
||||||
|
TenantService.setSelectedTenant(selectedTenant);
|
||||||
|
selectedTenantId.value = tenantId;
|
||||||
|
await LocalStorage.setRecentTenantId(tenantId);
|
||||||
|
|
||||||
|
// Load permissions if token exists
|
||||||
|
final token = LocalStorage.getJwtToken();
|
||||||
|
if (token != null && token.isNotEmpty) {
|
||||||
|
if (!Get.isRegistered<PermissionController>()) {
|
||||||
|
Get.put(PermissionController());
|
||||||
|
}
|
||||||
|
await Get.find<PermissionController>().loadData(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Navigate **before changing isAutoSelecting**
|
||||||
|
await Get.offAllNamed('/dashboard');
|
||||||
|
|
||||||
|
// Then hide splash
|
||||||
|
isAutoSelecting.value = false;
|
||||||
|
} catch (e) {
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Error",
|
title: "Error",
|
||||||
message: "An unexpected error occurred while selecting organization.",
|
message: "An unexpected error occurred while selecting organization.",
|
||||||
@ -103,4 +127,10 @@ class TenantSelectionController extends GetxController {
|
|||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Clear tenant selection
|
||||||
|
void _clearSelection() {
|
||||||
|
selectedTenantId.value = null;
|
||||||
|
TenantService.currentTenant = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
106
lib/controller/tenant/tenant_switch_controller.dart
Normal file
106
lib/controller/tenant/tenant_switch_controller.dart
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:marco/helpers/services/app_logger.dart';
|
||||||
|
import 'package:marco/helpers/services/tenant_service.dart';
|
||||||
|
import 'package:marco/model/tenant/tenant_list_model.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||||
|
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||||
|
import 'package:marco/controller/permission_controller.dart';
|
||||||
|
|
||||||
|
class TenantSwitchController extends GetxController {
|
||||||
|
final TenantService _tenantService = TenantService();
|
||||||
|
|
||||||
|
final tenants = <Tenant>[].obs;
|
||||||
|
final isLoading = false.obs;
|
||||||
|
final selectedTenantId = RxnString();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onInit() {
|
||||||
|
super.onInit();
|
||||||
|
loadTenants();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Load all tenants for switching (does not auto-select)
|
||||||
|
Future<void> loadTenants() async {
|
||||||
|
isLoading.value = true;
|
||||||
|
try {
|
||||||
|
final data = await _tenantService.getTenants();
|
||||||
|
if (data == null || data.isEmpty) {
|
||||||
|
tenants.clear();
|
||||||
|
logSafe("⚠️ No tenants available for switching.", level: LogLevel.warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
tenants.value = data.map((e) => Tenant.fromJson(e)).toList();
|
||||||
|
|
||||||
|
// Keep current tenant as selected
|
||||||
|
selectedTenantId.value = TenantService.currentTenant?.id;
|
||||||
|
} catch (e, st) {
|
||||||
|
logSafe("❌ Exception in loadTenants", level: LogLevel.error, error: e, stackTrace: st);
|
||||||
|
showAppSnackbar(
|
||||||
|
title: "Error",
|
||||||
|
message: "Failed to load organizations for switching.",
|
||||||
|
type: SnackbarType.error,
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Switch to a different tenant and navigate fully
|
||||||
|
Future<void> switchTenant(String tenantId) async {
|
||||||
|
if (TenantService.currentTenant?.id == tenantId) return;
|
||||||
|
|
||||||
|
isLoading.value = true;
|
||||||
|
try {
|
||||||
|
final success = await _tenantService.selectTenant(tenantId);
|
||||||
|
if (!success) {
|
||||||
|
logSafe("❌ Tenant switch failed: $tenantId", level: LogLevel.warning);
|
||||||
|
showAppSnackbar(
|
||||||
|
title: "Error",
|
||||||
|
message: "Unable to switch organization. Try again.",
|
||||||
|
type: SnackbarType.error,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final selectedTenant = tenants.firstWhere((t) => t.id == tenantId);
|
||||||
|
TenantService.setSelectedTenant(selectedTenant);
|
||||||
|
selectedTenantId.value = tenantId;
|
||||||
|
|
||||||
|
// Persist recent tenant
|
||||||
|
await LocalStorage.setRecentTenantId(tenantId);
|
||||||
|
|
||||||
|
logSafe("✅ Tenant switched successfully: $tenantId");
|
||||||
|
|
||||||
|
// 🔹 Load permissions after tenant switch (null-safe)
|
||||||
|
final token = await LocalStorage.getJwtToken();
|
||||||
|
if (token != null && token.isNotEmpty) {
|
||||||
|
if (!Get.isRegistered<PermissionController>()) {
|
||||||
|
Get.put(PermissionController());
|
||||||
|
logSafe("✅ PermissionController injected after tenant switch.");
|
||||||
|
}
|
||||||
|
await Get.find<PermissionController>().loadData(token);
|
||||||
|
} else {
|
||||||
|
logSafe("⚠️ JWT token is null. Cannot load permissions.", level: LogLevel.warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FULL NAVIGATION: reload app/dashboard
|
||||||
|
Get.offAllNamed('/dashboard');
|
||||||
|
|
||||||
|
showAppSnackbar(
|
||||||
|
title: "Success",
|
||||||
|
message: "Switched to organization: ${selectedTenant.name}",
|
||||||
|
type: SnackbarType.success,
|
||||||
|
);
|
||||||
|
} catch (e, st) {
|
||||||
|
logSafe("❌ Exception in switchTenant", level: LogLevel.error, error: e, stackTrace: st);
|
||||||
|
showAppSnackbar(
|
||||||
|
title: "Error",
|
||||||
|
message: "An unexpected error occurred while switching organization.",
|
||||||
|
type: SnackbarType.error,
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@ import 'package:marco/model/document/document_details_model.dart';
|
|||||||
import 'package:marco/model/document/document_version_model.dart';
|
import 'package:marco/model/document/document_version_model.dart';
|
||||||
import 'package:marco/model/attendance/organization_per_project_list_model.dart';
|
import 'package:marco/model/attendance/organization_per_project_list_model.dart';
|
||||||
import 'package:marco/model/tenant/tenant_services_model.dart';
|
import 'package:marco/model/tenant/tenant_services_model.dart';
|
||||||
|
import 'package:marco/model/dailyTaskPlanning/daily_task_model.dart';
|
||||||
|
|
||||||
class ApiService {
|
class ApiService {
|
||||||
static const bool enableLogs = true;
|
static const bool enableLogs = true;
|
||||||
@ -354,14 +355,24 @@ class ApiService {
|
|||||||
logSafe("Posting logs... count=${logs.length}");
|
logSafe("Posting logs... count=${logs.length}");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final response =
|
// Get token directly without triggering logout or refresh
|
||||||
await _postRequest(endpoint, logs, customTimeout: extendedTimeout);
|
final token = await LocalStorage.getJwtToken();
|
||||||
|
if (token == null) {
|
||||||
if (response == null) {
|
logSafe("No token available. Skipping logs post.",
|
||||||
logSafe("Post logs failed: null response", level: LogLevel.error);
|
level: LogLevel.warning);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final uri = Uri.parse("${ApiEndpoints.baseUrl}$endpoint");
|
||||||
|
final headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer $token',
|
||||||
|
};
|
||||||
|
|
||||||
|
final response = await http
|
||||||
|
.post(uri, headers: headers, body: jsonEncode(logs))
|
||||||
|
.timeout(ApiService.extendedTimeout);
|
||||||
|
|
||||||
logSafe("Post logs response status: ${response.statusCode}");
|
logSafe("Post logs response status: ${response.statusCode}");
|
||||||
logSafe("Post logs response body: ${response.body}");
|
logSafe("Post logs response body: ${response.body}");
|
||||||
|
|
||||||
@ -1761,19 +1772,18 @@ class ApiService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<dynamic>?> getDirectoryComments(
|
static Future<List<dynamic>?> getDirectoryComments(
|
||||||
String contactId, {
|
String contactId, {
|
||||||
bool active = true,
|
bool active = true,
|
||||||
}) async {
|
}) async {
|
||||||
final url = "${ApiEndpoints.getDirectoryNotes}/$contactId?active=$active";
|
final url = "${ApiEndpoints.getDirectoryNotes}/$contactId?active=$active";
|
||||||
final response = await _getRequest(url);
|
final response = await _getRequest(url);
|
||||||
final data = response != null
|
final data = response != null
|
||||||
? _parseResponse(response, label: 'Directory Comments')
|
? _parseResponse(response, label: 'Directory Comments')
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
return data is List ? data : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return data is List ? data : null;
|
||||||
|
}
|
||||||
|
|
||||||
static Future<bool> updateContact(
|
static Future<bool> updateContact(
|
||||||
String contactId, Map<String, dynamic> payload) async {
|
String contactId, Map<String, dynamic> payload) async {
|
||||||
@ -2116,38 +2126,42 @@ static Future<List<dynamic>?> getDirectoryComments(
|
|||||||
|
|
||||||
// === Daily Task APIs ===
|
// === Daily Task APIs ===
|
||||||
|
|
||||||
static Future<List<dynamic>?> getDailyTasks(
|
static Future<List<TaskModel>?> getDailyTasks(
|
||||||
String projectId, {
|
String projectId, {
|
||||||
DateTime? dateFrom,
|
DateTime? dateFrom,
|
||||||
DateTime? dateTo,
|
DateTime? dateTo,
|
||||||
List<String>? serviceIds,
|
List<String>? serviceIds,
|
||||||
int pageNumber = 1,
|
int pageNumber = 1,
|
||||||
int pageSize = 20,
|
int pageSize = 20,
|
||||||
}) async {
|
}) async {
|
||||||
final filterBody = {
|
final filterBody = {
|
||||||
"serviceIds": serviceIds ?? [],
|
"serviceIds": serviceIds ?? [],
|
||||||
};
|
};
|
||||||
|
|
||||||
final query = {
|
final query = {
|
||||||
"projectId": projectId,
|
"projectId": projectId,
|
||||||
"pageNumber": pageNumber.toString(),
|
"pageNumber": pageNumber.toString(),
|
||||||
"pageSize": pageSize.toString(),
|
"pageSize": pageSize.toString(),
|
||||||
if (dateFrom != null)
|
if (dateFrom != null)
|
||||||
"dateFrom": DateFormat('yyyy-MM-dd').format(dateFrom),
|
"dateFrom": DateFormat('yyyy-MM-dd').format(dateFrom),
|
||||||
if (dateTo != null) "dateTo": DateFormat('yyyy-MM-dd').format(dateTo),
|
if (dateTo != null) "dateTo": DateFormat('yyyy-MM-dd').format(dateTo),
|
||||||
"filter": jsonEncode(filterBody),
|
"filter": jsonEncode(filterBody),
|
||||||
};
|
};
|
||||||
|
|
||||||
final uri =
|
final uri =
|
||||||
Uri.parse(ApiEndpoints.getDailyTask).replace(queryParameters: query);
|
Uri.parse(ApiEndpoints.getDailyTask).replace(queryParameters: query);
|
||||||
|
|
||||||
final response = await _getRequest(uri.toString());
|
final response = await _getRequest(uri.toString());
|
||||||
|
final parsed = response != null ? _parseResponse(response, label: 'Daily Tasks') : null;
|
||||||
|
|
||||||
return response != null
|
if (parsed != null && parsed['data'] != null) {
|
||||||
? _parseResponse(response, label: 'Daily Tasks')
|
return (parsed['data'] as List).map((e) => TaskModel.fromJson(e)).toList();
|
||||||
: null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static Future<bool> reportTask({
|
static Future<bool> reportTask({
|
||||||
required String id,
|
required String id,
|
||||||
required int completedTask,
|
required int completedTask,
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:get/get.dart';
|
|
||||||
import 'package:url_strategy/url_strategy.dart';
|
import 'package:url_strategy/url_strategy.dart';
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
|
|
||||||
import 'package:marco/controller/permission_controller.dart';
|
|
||||||
import 'package:marco/controller/project_controller.dart';
|
|
||||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||||
import 'package:marco/helpers/services/app_logger.dart';
|
import 'package:marco/helpers/services/app_logger.dart';
|
||||||
import 'package:marco/helpers/services/auth_service.dart';
|
import 'package:marco/helpers/services/auth_service.dart';
|
||||||
@ -24,9 +20,8 @@ Future<void> initializeApp() async {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
await _setupDeviceInfo();
|
await _setupDeviceInfo();
|
||||||
await _handleAuthTokens();
|
await _handleAuthTokens();
|
||||||
await _setupTheme();
|
await _setupTheme();
|
||||||
await _setupControllers();
|
|
||||||
await _setupFirebaseMessaging();
|
await _setupFirebaseMessaging();
|
||||||
|
|
||||||
_finalizeAppStyle();
|
_finalizeAppStyle();
|
||||||
@ -43,6 +38,19 @@ Future<void> initializeApp() async {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _handleAuthTokens() async {
|
||||||
|
final refreshToken = await LocalStorage.getRefreshToken();
|
||||||
|
if (refreshToken?.isNotEmpty ?? false) {
|
||||||
|
logSafe("🔁 Refresh token found. Attempting to refresh JWT...");
|
||||||
|
final success = await AuthService.refreshToken();
|
||||||
|
if (!success) {
|
||||||
|
logSafe("⚠️ Refresh token invalid or expired. User must login again.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logSafe("❌ No refresh token found. Skipping refresh.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _setupUI() async {
|
Future<void> _setupUI() async {
|
||||||
setPathUrlStrategy();
|
setPathUrlStrategy();
|
||||||
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
@ -69,50 +77,11 @@ Future<void> _setupDeviceInfo() async {
|
|||||||
logSafe("📱 Device Info: ${deviceInfoService.deviceData}");
|
logSafe("📱 Device Info: ${deviceInfoService.deviceData}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handleAuthTokens() async {
|
|
||||||
final refreshToken = await LocalStorage.getRefreshToken();
|
|
||||||
if (refreshToken?.isNotEmpty ?? false) {
|
|
||||||
logSafe("🔁 Refresh token found. Attempting to refresh JWT...");
|
|
||||||
final success = await AuthService.refreshToken();
|
|
||||||
if (!success) {
|
|
||||||
logSafe(
|
|
||||||
"⚠️ Refresh token invalid or expired. Skipping controller injection.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logSafe("❌ No refresh token found. Skipping refresh.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _setupTheme() async {
|
Future<void> _setupTheme() async {
|
||||||
await ThemeCustomizer.init();
|
await ThemeCustomizer.init();
|
||||||
logSafe("💡 Theme customizer initialized.");
|
logSafe("💡 Theme customizer initialized.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _setupControllers() async {
|
|
||||||
final token = LocalStorage.getString('jwt_token');
|
|
||||||
if (token?.isEmpty ?? true) {
|
|
||||||
logSafe("⚠️ No valid JWT token found. Skipping controller initialization.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Get.isRegistered<PermissionController>()) {
|
|
||||||
Get.put(PermissionController());
|
|
||||||
logSafe("💡 PermissionController injected.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Get.isRegistered<ProjectController>()) {
|
|
||||||
Get.put(ProjectController(), permanent: true);
|
|
||||||
logSafe("💡 ProjectController injected as permanent.");
|
|
||||||
}
|
|
||||||
|
|
||||||
await Future.wait([
|
|
||||||
Get.find<PermissionController>().loadData(token!),
|
|
||||||
Get.find<ProjectController>().fetchProjects(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ❌ Commented out Firebase Messaging setup
|
|
||||||
|
|
||||||
Future<void> _setupFirebaseMessaging() async {
|
Future<void> _setupFirebaseMessaging() async {
|
||||||
await FirebaseNotificationService().initialize();
|
await FirebaseNotificationService().initialize();
|
||||||
logSafe("💡 Firebase Messaging initialized.");
|
logSafe("💡 Firebase Messaging initialized.");
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:get/get.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
import 'package:marco/controller/permission_controller.dart';
|
|
||||||
import 'package:marco/controller/project_controller.dart';
|
|
||||||
import 'package:marco/helpers/services/api_endpoints.dart';
|
import 'package:marco/helpers/services/api_endpoints.dart';
|
||||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||||
import 'package:marco/helpers/services/app_logger.dart';
|
import 'package:marco/helpers/services/app_logger.dart';
|
||||||
@ -98,8 +94,8 @@ class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> refreshToken() async {
|
static Future<bool> refreshToken() async {
|
||||||
final accessToken = await LocalStorage.getJwtToken();
|
final accessToken = LocalStorage.getJwtToken();
|
||||||
final refreshToken = await LocalStorage.getRefreshToken();
|
final refreshToken = LocalStorage.getRefreshToken();
|
||||||
|
|
||||||
if ([accessToken, refreshToken].any((t) => t == null || t.isEmpty)) {
|
if ([accessToken, refreshToken].any((t) => t == null || t.isEmpty)) {
|
||||||
logSafe("Missing access or refresh token.", level: LogLevel.warning);
|
logSafe("Missing access or refresh token.", level: LogLevel.warning);
|
||||||
@ -115,7 +111,7 @@ class AuthService {
|
|||||||
logSafe("Token refreshed successfully.");
|
logSafe("Token refreshed successfully.");
|
||||||
|
|
||||||
// 🔹 Retry FCM token registration after token refresh
|
// 🔹 Retry FCM token registration after token refresh
|
||||||
final newFcmToken = await LocalStorage.getFcmToken();
|
final newFcmToken = LocalStorage.getFcmToken();
|
||||||
if (newFcmToken?.isNotEmpty ?? false) {
|
if (newFcmToken?.isNotEmpty ?? false) {
|
||||||
final success = await registerDeviceToken(newFcmToken!);
|
final success = await registerDeviceToken(newFcmToken!);
|
||||||
logSafe(
|
logSafe(
|
||||||
@ -157,7 +153,7 @@ class AuthService {
|
|||||||
}) =>
|
}) =>
|
||||||
_wrapErrorHandling(
|
_wrapErrorHandling(
|
||||||
() async {
|
() async {
|
||||||
final token = await LocalStorage.getJwtToken();
|
final token = LocalStorage.getJwtToken();
|
||||||
return _post(
|
return _post(
|
||||||
"/auth/generate-mpin",
|
"/auth/generate-mpin",
|
||||||
{"employeeId": employeeId, "mpin": mpin},
|
{"employeeId": employeeId, "mpin": mpin},
|
||||||
@ -290,30 +286,6 @@ class AuthService {
|
|||||||
await LocalStorage.setIsMpin(false);
|
await LocalStorage.setIsMpin(false);
|
||||||
await LocalStorage.removeMpinToken();
|
await LocalStorage.removeMpinToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Get.isRegistered<PermissionController>()) {
|
|
||||||
Get.put(PermissionController());
|
|
||||||
logSafe("✅ PermissionController injected after login.");
|
|
||||||
}
|
|
||||||
if (!Get.isRegistered<ProjectController>()) {
|
|
||||||
Get.put(ProjectController(), permanent: true);
|
|
||||||
logSafe("✅ ProjectController injected after login.");
|
|
||||||
}
|
|
||||||
|
|
||||||
await Get.find<PermissionController>().loadData(data['token']);
|
|
||||||
await Get.find<ProjectController>().fetchProjects();
|
|
||||||
|
|
||||||
// 🔹 Always try to register FCM token after login
|
|
||||||
final fcmToken = await LocalStorage.getFcmToken();
|
|
||||||
if (fcmToken?.isNotEmpty ?? false) {
|
|
||||||
final success = await registerDeviceToken(fcmToken!);
|
|
||||||
logSafe(
|
|
||||||
success
|
|
||||||
? "✅ FCM token registered after login."
|
|
||||||
: "⚠️ Failed to register FCM token after login.",
|
|
||||||
level: success ? LogLevel.info : LogLevel.warning);
|
|
||||||
}
|
|
||||||
|
|
||||||
isLoggedIn = true;
|
isLoggedIn = true;
|
||||||
logSafe("✅ Login flow completed and controllers initialized.");
|
logSafe("✅ Login flow completed and controllers initialized.");
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ class FirebaseNotificationService {
|
|||||||
_registerMessageListeners();
|
_registerMessageListeners();
|
||||||
_registerTokenRefreshListener();
|
_registerTokenRefreshListener();
|
||||||
|
|
||||||
// Fetch token on app start (but only register with server if JWT available)
|
// Fetch token on app start (and register with server if JWT available)
|
||||||
await getFcmToken(registerOnServer: true);
|
await getFcmToken(registerOnServer: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,6 +49,7 @@ class FirebaseNotificationService {
|
|||||||
|
|
||||||
FirebaseMessaging.onMessageOpenedApp.listen(_handleNotificationTap);
|
FirebaseMessaging.onMessageOpenedApp.listen(_handleNotificationTap);
|
||||||
|
|
||||||
|
// Background messages
|
||||||
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,8 +112,6 @@ class FirebaseNotificationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Handle tap on notification
|
/// Handle tap on notification
|
||||||
void _handleNotificationTap(RemoteMessage message) {
|
void _handleNotificationTap(RemoteMessage message) {
|
||||||
_logger.i('📌 Notification tapped: ${message.data}');
|
_logger.i('📌 Notification tapped: ${message.data}');
|
||||||
@ -129,7 +128,9 @@ class FirebaseNotificationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Background handler (required by Firebase)
|
/// 🔹 Background handler (required by Firebase)
|
||||||
|
/// Must be a top-level function and annotated for AOT
|
||||||
|
@pragma('vm:entry-point')
|
||||||
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||||
final logger = Logger();
|
final logger = Logger();
|
||||||
logger
|
logger
|
||||||
|
@ -129,6 +129,17 @@ class TenantService implements ITenantService {
|
|||||||
logSafe("⚠️ ProjectController not found while refreshing projects");
|
logSafe("⚠️ ProjectController not found while refreshing projects");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 🔹 Register FCM token after tenant selection
|
||||||
|
final fcmToken = LocalStorage.getFcmToken();
|
||||||
|
if (fcmToken?.isNotEmpty ?? false) {
|
||||||
|
final success = await AuthService.registerDeviceToken(fcmToken!);
|
||||||
|
logSafe(
|
||||||
|
success
|
||||||
|
? "✅ FCM token registered after tenant selection."
|
||||||
|
: "⚠️ Failed to register FCM token after tenant selection.",
|
||||||
|
level: success ? LogLevel.info : LogLevel.warning);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ class AppStyle {
|
|||||||
containerRadius: AppStyle.containerRadius.medium,
|
containerRadius: AppStyle.containerRadius.medium,
|
||||||
cardRadius: AppStyle.cardRadius.medium,
|
cardRadius: AppStyle.cardRadius.medium,
|
||||||
buttonRadius: AppStyle.buttonRadius.medium,
|
buttonRadius: AppStyle.buttonRadius.medium,
|
||||||
defaultBreadCrumbItem: MyBreadcrumbItem(name: 'Marco', route: '/client/home'),
|
defaultBreadCrumbItem: MyBreadcrumbItem(name: 'Marco', route: '/client/dashboard'),
|
||||||
));
|
));
|
||||||
bool isMobile = true;
|
bool isMobile = true;
|
||||||
try {
|
try {
|
||||||
|
@ -60,7 +60,6 @@ class AttendanceDashboardChart extends StatelessWidget {
|
|||||||
|
|
||||||
final filteredData = _getFilteredData();
|
final filteredData = _getFilteredData();
|
||||||
|
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
decoration: _containerDecoration,
|
decoration: _containerDecoration,
|
||||||
padding: EdgeInsets.symmetric(
|
padding: EdgeInsets.symmetric(
|
||||||
@ -254,7 +253,7 @@ class _AttendanceChart extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final dateFormat = DateFormat('d MMMM');
|
final dateFormat = DateFormat('d MMM');
|
||||||
final uniqueDates = data
|
final uniqueDates = data
|
||||||
.map((e) => DateTime.parse(e['date'] as String))
|
.map((e) => DateTime.parse(e['date'] as String))
|
||||||
.toSet()
|
.toSet()
|
||||||
@ -273,10 +272,6 @@ class _AttendanceChart extends StatelessWidget {
|
|||||||
if (allZero) {
|
if (allZero) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 600,
|
height: 600,
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.blueGrey.shade50,
|
|
||||||
borderRadius: BorderRadius.circular(5),
|
|
||||||
),
|
|
||||||
child: const Center(
|
child: const Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
'No attendance data for the selected range.',
|
'No attendance data for the selected range.',
|
||||||
@ -302,7 +297,6 @@ class _AttendanceChart extends StatelessWidget {
|
|||||||
height: 600,
|
height: 600,
|
||||||
padding: const EdgeInsets.all(6),
|
padding: const EdgeInsets.all(6),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.blueGrey.shade50,
|
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
),
|
),
|
||||||
child: SfCartesianChart(
|
child: SfCartesianChart(
|
||||||
@ -317,7 +311,7 @@ class _AttendanceChart extends StatelessWidget {
|
|||||||
return {'date': date, 'present': formattedMap[key] ?? 0};
|
return {'date': date, 'present': formattedMap[key] ?? 0};
|
||||||
})
|
})
|
||||||
.where((d) => (d['present'] ?? 0) > 0)
|
.where((d) => (d['present'] ?? 0) > 0)
|
||||||
.toList(); // ✅ remove 0 bars
|
.toList();
|
||||||
|
|
||||||
return StackedColumnSeries<Map<String, dynamic>, String>(
|
return StackedColumnSeries<Map<String, dynamic>, String>(
|
||||||
dataSource: seriesData,
|
dataSource: seriesData,
|
||||||
@ -358,7 +352,7 @@ class _AttendanceTable extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final dateFormat = DateFormat('d MMMM');
|
final dateFormat = DateFormat('d MMM');
|
||||||
final uniqueDates = data
|
final uniqueDates = data
|
||||||
.map((e) => DateTime.parse(e['date'] as String))
|
.map((e) => DateTime.parse(e['date'] as String))
|
||||||
.toSet()
|
.toSet()
|
||||||
@ -377,10 +371,6 @@ class _AttendanceTable extends StatelessWidget {
|
|||||||
if (allZero) {
|
if (allZero) {
|
||||||
return Container(
|
return Container(
|
||||||
height: 300,
|
height: 300,
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.grey.shade50,
|
|
||||||
borderRadius: BorderRadius.circular(5),
|
|
||||||
),
|
|
||||||
child: const Center(
|
child: const Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
'No attendance data for the selected range.',
|
'No attendance data for the selected range.',
|
||||||
@ -402,38 +392,49 @@ class _AttendanceTable extends StatelessWidget {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border.all(color: Colors.grey.shade300),
|
border: Border.all(color: Colors.grey.shade300),
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
color: Colors.grey.shade50,
|
|
||||||
),
|
),
|
||||||
child: SingleChildScrollView(
|
child: Scrollbar(
|
||||||
scrollDirection: Axis.horizontal,
|
thumbVisibility: true,
|
||||||
child: DataTable(
|
trackVisibility: true,
|
||||||
columnSpacing: screenWidth < 600 ? 20 : 36,
|
child: SingleChildScrollView(
|
||||||
headingRowHeight: 44,
|
scrollDirection: Axis.horizontal,
|
||||||
headingRowColor:
|
child: ConstrainedBox(
|
||||||
MaterialStateProperty.all(Colors.blueAccent.withOpacity(0.08)),
|
constraints:
|
||||||
headingTextStyle: const TextStyle(
|
BoxConstraints(minWidth: MediaQuery.of(context).size.width),
|
||||||
fontWeight: FontWeight.bold, color: Colors.black87),
|
child: SingleChildScrollView(
|
||||||
columns: [
|
scrollDirection: Axis.vertical,
|
||||||
const DataColumn(label: Text('Role')),
|
child: DataTable(
|
||||||
...filteredDates.map((d) => DataColumn(label: Text(d))),
|
columnSpacing: 20,
|
||||||
],
|
headingRowHeight: 44,
|
||||||
rows: filteredRoles.map((role) {
|
headingRowColor: MaterialStateProperty.all(
|
||||||
return DataRow(
|
Colors.blueAccent.withOpacity(0.08)),
|
||||||
cells: [
|
headingTextStyle: const TextStyle(
|
||||||
DataCell(_RolePill(role: role, color: getRoleColor(role))),
|
fontWeight: FontWeight.bold, color: Colors.black87),
|
||||||
...filteredDates.map((date) {
|
columns: [
|
||||||
final key = '${role}_$date';
|
const DataColumn(label: Text('Role')),
|
||||||
return DataCell(
|
...filteredDates.map((d) => DataColumn(label: Text(d))),
|
||||||
Text(
|
],
|
||||||
NumberFormat.decimalPattern()
|
rows: filteredRoles.map((role) {
|
||||||
.format(formattedMap[key] ?? 0),
|
return DataRow(
|
||||||
style: const TextStyle(fontSize: 13),
|
cells: [
|
||||||
),
|
DataCell(
|
||||||
|
_RolePill(role: role, color: getRoleColor(role))),
|
||||||
|
...filteredDates.map((date) {
|
||||||
|
final key = '${role}_$date';
|
||||||
|
return DataCell(
|
||||||
|
Text(
|
||||||
|
NumberFormat.decimalPattern()
|
||||||
|
.format(formattedMap[key] ?? 0),
|
||||||
|
style: const TextStyle(fontSize: 13),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}),
|
}).toList(),
|
||||||
],
|
),
|
||||||
);
|
),
|
||||||
}).toList(),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -197,13 +197,13 @@ class ProjectProgressChart extends StatelessWidget {
|
|||||||
height: height > 280 ? 280 : height,
|
height: height > 280 ? 280 : height,
|
||||||
padding: const EdgeInsets.all(6),
|
padding: const EdgeInsets.all(6),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.blueGrey.shade50,
|
// Remove background
|
||||||
|
color: Colors.transparent,
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
),
|
),
|
||||||
child: SfCartesianChart(
|
child: SfCartesianChart(
|
||||||
tooltipBehavior: TooltipBehavior(enable: true),
|
tooltipBehavior: TooltipBehavior(enable: true),
|
||||||
legend: Legend(isVisible: true, position: LegendPosition.bottom),
|
legend: Legend(isVisible: true, position: LegendPosition.bottom),
|
||||||
// ✅ Use CategoryAxis so only nonZeroData dates show up
|
|
||||||
primaryXAxis: CategoryAxis(
|
primaryXAxis: CategoryAxis(
|
||||||
majorGridLines: const MajorGridLines(width: 0),
|
majorGridLines: const MajorGridLines(width: 0),
|
||||||
axisLine: const AxisLine(width: 0),
|
axisLine: const AxisLine(width: 0),
|
||||||
@ -273,48 +273,44 @@ class ProjectProgressChart extends StatelessWidget {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
border: Border.all(color: Colors.grey.shade300),
|
border: Border.all(color: Colors.grey.shade300),
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
color: Colors.grey.shade50,
|
color: Colors.transparent,
|
||||||
),
|
),
|
||||||
child: LayoutBuilder(
|
child: Scrollbar(
|
||||||
builder: (context, constraints) {
|
thumbVisibility: true,
|
||||||
return SingleChildScrollView(
|
trackVisibility: true,
|
||||||
scrollDirection: Axis.horizontal,
|
child: SingleChildScrollView(
|
||||||
child: ConstrainedBox(
|
scrollDirection: Axis.horizontal,
|
||||||
constraints: BoxConstraints(minWidth: constraints.maxWidth),
|
child: ConstrainedBox(
|
||||||
child: SingleChildScrollView(
|
constraints: BoxConstraints(minWidth: screenWidth),
|
||||||
scrollDirection: Axis.vertical,
|
child: SingleChildScrollView(
|
||||||
child: DataTable(
|
scrollDirection: Axis.vertical,
|
||||||
columnSpacing: screenWidth < 600 ? 16 : 36,
|
child: DataTable(
|
||||||
headingRowHeight: 44,
|
columnSpacing: screenWidth < 600 ? 16 : 36,
|
||||||
headingRowColor: MaterialStateProperty.all(
|
headingRowHeight: 44,
|
||||||
Colors.blueAccent.withOpacity(0.08)),
|
headingRowColor: MaterialStateProperty.all(
|
||||||
headingTextStyle: const TextStyle(
|
Colors.blueAccent.withOpacity(0.08)),
|
||||||
fontWeight: FontWeight.bold, color: Colors.black87),
|
headingTextStyle: const TextStyle(
|
||||||
columns: const [
|
fontWeight: FontWeight.bold, color: Colors.black87),
|
||||||
DataColumn(label: Text('Date')),
|
columns: const [
|
||||||
DataColumn(label: Text('Planned')),
|
DataColumn(label: Text('Date')),
|
||||||
DataColumn(label: Text('Completed')),
|
DataColumn(label: Text('Planned')),
|
||||||
],
|
DataColumn(label: Text('Completed')),
|
||||||
rows: nonZeroData.map((task) {
|
],
|
||||||
return DataRow(
|
rows: nonZeroData.map((task) {
|
||||||
cells: [
|
return DataRow(
|
||||||
DataCell(Text(DateFormat('d MMM').format(task.date))),
|
cells: [
|
||||||
DataCell(Text(
|
DataCell(Text(DateFormat('d MMM').format(task.date))),
|
||||||
'${task.planned}',
|
DataCell(Text('${task.planned}',
|
||||||
style: TextStyle(color: _getTaskColor('Planned')),
|
style: TextStyle(color: _getTaskColor('Planned')))),
|
||||||
)),
|
DataCell(Text('${task.completed}',
|
||||||
DataCell(Text(
|
style: TextStyle(color: _getTaskColor('Completed')))),
|
||||||
'${task.completed}',
|
],
|
||||||
style: TextStyle(color: _getTaskColor('Completed')),
|
);
|
||||||
)),
|
}).toList(),
|
||||||
],
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -323,7 +319,7 @@ class ProjectProgressChart extends StatelessWidget {
|
|||||||
return Container(
|
return Container(
|
||||||
height: height > 280 ? 280 : height,
|
height: height > 280 ? 280 : height,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.blueGrey.shade50,
|
color: Colors.transparent,
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
),
|
),
|
||||||
child: const Center(
|
child: const Center(
|
||||||
|
@ -77,7 +77,32 @@ class OrganizationSelector extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
if (controller.isLoadingOrganizations.value) {
|
if (controller.isLoadingOrganizations.value) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return Container(
|
||||||
|
height: height ?? 40,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.shade300,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: 100,
|
||||||
|
height: 14,
|
||||||
|
color: Colors.grey.shade400,
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: 18,
|
||||||
|
height: 18,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.shade400,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
} else if (controller.organizations.isEmpty) {
|
} else if (controller.organizations.isEmpty) {
|
||||||
return Center(
|
return Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
@ -96,7 +121,6 @@ class OrganizationSelector extends StatelessWidget {
|
|||||||
...controller.organizations.map((e) => e.name)
|
...controller.organizations.map((e) => e.name)
|
||||||
];
|
];
|
||||||
|
|
||||||
// Listen to selectedOrganization.value
|
|
||||||
return _popupSelector(
|
return _popupSelector(
|
||||||
currentValue: controller.currentSelection,
|
currentValue: controller.currentSelection,
|
||||||
items: orgNames,
|
items: orgNames,
|
||||||
|
@ -88,11 +88,40 @@ class ServiceSelector extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _skeletonSelector() {
|
||||||
|
return Container(
|
||||||
|
height: height ?? 40,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.shade300,
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: 100,
|
||||||
|
height: 14,
|
||||||
|
color: Colors.grey.shade400,
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: 18,
|
||||||
|
height: 18,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.shade400,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
if (controller.isLoadingServices.value) {
|
if (controller.isLoadingServices.value) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return _skeletonSelector();
|
||||||
}
|
}
|
||||||
|
|
||||||
final serviceNames = controller.services.isEmpty
|
final serviceNames = controller.services.isEmpty
|
||||||
|
@ -108,8 +108,10 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
final isOldCheckIn = AttendanceButtonHelper.isOlderThanDays(widget.employee.checkIn, 2);
|
final isOldCheckIn =
|
||||||
final isOldCheckOut = AttendanceButtonHelper.isOlderThanDays(widget.employee.checkOut, 2);
|
AttendanceButtonHelper.isOlderThanDays(widget.employee.checkIn, 2);
|
||||||
|
final isOldCheckOut =
|
||||||
|
AttendanceButtonHelper.isOlderThanDays(widget.employee.checkOut, 2);
|
||||||
|
|
||||||
if (widget.employee.checkOut == null && isOldCheckIn) {
|
if (widget.employee.checkOut == null && isOldCheckIn) {
|
||||||
action = 2;
|
action = 2;
|
||||||
@ -167,7 +169,9 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
|
|||||||
String? markTime;
|
String? markTime;
|
||||||
if (actionText == ButtonActions.requestRegularize) {
|
if (actionText == ButtonActions.requestRegularize) {
|
||||||
selectedTime ??= await _pickRegularizationTime(widget.employee.checkIn!);
|
selectedTime ??= await _pickRegularizationTime(widget.employee.checkIn!);
|
||||||
markTime = selectedTime != null ? DateFormat("hh:mm a").format(selectedTime) : null;
|
markTime = selectedTime != null
|
||||||
|
? DateFormat("hh:mm a").format(selectedTime)
|
||||||
|
: null;
|
||||||
} else if (selectedTime != null) {
|
} else if (selectedTime != null) {
|
||||||
markTime = DateFormat("hh:mm a").format(selectedTime);
|
markTime = DateFormat("hh:mm a").format(selectedTime);
|
||||||
}
|
}
|
||||||
@ -205,13 +209,17 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
final controller = widget.attendanceController;
|
final controller = widget.attendanceController;
|
||||||
final isUploading = controller.uploadingStates[uniqueLogKey]?.value ?? false;
|
final isUploading =
|
||||||
|
controller.uploadingStates[uniqueLogKey]?.value ?? false;
|
||||||
final emp = widget.employee;
|
final emp = widget.employee;
|
||||||
|
|
||||||
final isYesterday = AttendanceButtonHelper.isLogFromYesterday(emp.checkIn, emp.checkOut);
|
final isYesterday =
|
||||||
final isTodayApproved = AttendanceButtonHelper.isTodayApproved(emp.activity, emp.checkIn);
|
AttendanceButtonHelper.isLogFromYesterday(emp.checkIn, emp.checkOut);
|
||||||
|
final isTodayApproved =
|
||||||
|
AttendanceButtonHelper.isTodayApproved(emp.activity, emp.checkIn);
|
||||||
final isApprovedButNotToday =
|
final isApprovedButNotToday =
|
||||||
AttendanceButtonHelper.isApprovedButNotToday(emp.activity, isTodayApproved);
|
AttendanceButtonHelper.isApprovedButNotToday(
|
||||||
|
emp.activity, isTodayApproved);
|
||||||
|
|
||||||
final isButtonDisabled = AttendanceButtonHelper.isButtonDisabled(
|
final isButtonDisabled = AttendanceButtonHelper.isButtonDisabled(
|
||||||
isUploading: isUploading,
|
isUploading: isUploading,
|
||||||
@ -272,12 +280,12 @@ class AttendanceActionButtonUI extends StatelessWidget {
|
|||||||
textStyle: const TextStyle(fontSize: 12),
|
textStyle: const TextStyle(fontSize: 12),
|
||||||
),
|
),
|
||||||
child: isUploading
|
child: isUploading
|
||||||
? const SizedBox(
|
? Container(
|
||||||
width: 16,
|
width: 60,
|
||||||
height: 16,
|
height: 14,
|
||||||
child: CircularProgressIndicator(
|
decoration: BoxDecoration(
|
||||||
strokeWidth: 2,
|
color: Colors.white.withOpacity(0.5),
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
borderRadius: BorderRadius.circular(4),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: Row(
|
: Row(
|
||||||
@ -288,7 +296,8 @@ class AttendanceActionButtonUI extends StatelessWidget {
|
|||||||
if (buttonText.toLowerCase() == 'rejected')
|
if (buttonText.toLowerCase() == 'rejected')
|
||||||
const Icon(Icons.close, size: 16, color: Colors.red),
|
const Icon(Icons.close, size: 16, color: Colors.red),
|
||||||
if (buttonText.toLowerCase() == 'requested')
|
if (buttonText.toLowerCase() == 'requested')
|
||||||
const Icon(Icons.hourglass_top, size: 16, color: Colors.orange),
|
const Icon(Icons.hourglass_top,
|
||||||
|
size: 16, color: Colors.orange),
|
||||||
if (['approved', 'rejected', 'requested']
|
if (['approved', 'rejected', 'requested']
|
||||||
.contains(buttonText.toLowerCase()))
|
.contains(buttonText.toLowerCase()))
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
@ -342,7 +351,8 @@ Future<String?> _showCommentBottomSheet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
|
padding: EdgeInsets.only(
|
||||||
|
bottom: MediaQuery.of(context).viewInsets.bottom),
|
||||||
child: BaseBottomSheet(
|
child: BaseBottomSheet(
|
||||||
title: sheetTitle, // 👈 now showing full sentence as title
|
title: sheetTitle, // 👈 now showing full sentence as title
|
||||||
onCancel: () => Navigator.of(context).pop(),
|
onCancel: () => Navigator.of(context).pop(),
|
||||||
@ -375,6 +385,5 @@ Future<String?> _showCommentBottomSheet(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String capitalizeFirstLetter(String text) =>
|
String capitalizeFirstLetter(String text) =>
|
||||||
text.isEmpty ? text : text[0].toUpperCase() + text.substring(1);
|
text.isEmpty ? text : text[0].toUpperCase() + text.substring(1);
|
||||||
|
@ -39,8 +39,7 @@ class _AttendanceFilterBottomSheetState
|
|||||||
final endDate = widget.controller.endDateAttendance;
|
final endDate = widget.controller.endDateAttendance;
|
||||||
|
|
||||||
if (startDate != null && endDate != null) {
|
if (startDate != null && endDate != null) {
|
||||||
final start =
|
final start = DateTimeUtils.formatDate(startDate, 'dd MMM yyyy');
|
||||||
DateTimeUtils.formatDate(startDate, 'dd MMM yyyy');
|
|
||||||
final end = DateTimeUtils.formatDate(endDate, 'dd MMM yyyy');
|
final end = DateTimeUtils.formatDate(endDate, 'dd MMM yyyy');
|
||||||
return "$start - $end";
|
return "$start - $end";
|
||||||
}
|
}
|
||||||
@ -161,7 +160,32 @@ class _AttendanceFilterBottomSheetState
|
|||||||
),
|
),
|
||||||
Obx(() {
|
Obx(() {
|
||||||
if (widget.controller.isLoadingOrganizations.value) {
|
if (widget.controller.isLoadingOrganizations.value) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return Container(
|
||||||
|
height: 40,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.shade300,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: 100,
|
||||||
|
height: 14,
|
||||||
|
color: Colors.grey.shade400,
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: 18,
|
||||||
|
height: 18,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.shade400,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
} else if (widget.controller.organizations.isEmpty) {
|
} else if (widget.controller.organizations.isEmpty) {
|
||||||
return Center(
|
return Center(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
|
@ -3,12 +3,12 @@ import 'package:marco/helpers/utils/attendance_actions.dart';
|
|||||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||||
import 'package:marco/controller/project_controller.dart';
|
import 'package:marco/controller/project_controller.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
enum ButtonActions { approve, reject }
|
enum ButtonActions { approve, reject }
|
||||||
|
|
||||||
class RegularizeActionButton extends StatefulWidget {
|
class RegularizeActionButton extends StatefulWidget {
|
||||||
final dynamic
|
final dynamic attendanceController;
|
||||||
attendanceController;
|
final dynamic log;
|
||||||
final dynamic log;
|
|
||||||
final String uniqueLogKey;
|
final String uniqueLogKey;
|
||||||
final ButtonActions action;
|
final ButtonActions action;
|
||||||
|
|
||||||
@ -53,57 +53,60 @@ class _RegularizeActionButtonState extends State<RegularizeActionButton> {
|
|||||||
Colors.grey;
|
Colors.grey;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handlePress() async {
|
Future<void> _handlePress() async {
|
||||||
final projectController = Get.find<ProjectController>();
|
final projectController = Get.find<ProjectController>();
|
||||||
final selectedProjectId = projectController.selectedProject?.id;
|
final selectedProjectId = projectController.selectedProject?.id;
|
||||||
|
|
||||||
if (selectedProjectId == null) {
|
if (selectedProjectId == null) {
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: 'Warning',
|
title: 'Warning',
|
||||||
message: 'Please select a project first',
|
message: 'Please select a project first',
|
||||||
type: SnackbarType.warning,
|
type: SnackbarType.warning,
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
isUploading = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
widget.attendanceController.uploadingStates[widget.uniqueLogKey]?.value =
|
||||||
|
true;
|
||||||
|
|
||||||
|
final success =
|
||||||
|
await widget.attendanceController.captureAndUploadAttendance(
|
||||||
|
widget.log.id,
|
||||||
|
widget.log.employeeId,
|
||||||
|
selectedProjectId,
|
||||||
|
comment: _buttonComments[widget.action]!,
|
||||||
|
action: _buttonActionCodes[widget.action]!,
|
||||||
|
imageCapture: false,
|
||||||
);
|
);
|
||||||
return;
|
|
||||||
|
showAppSnackbar(
|
||||||
|
title: success ? 'Success' : 'Error',
|
||||||
|
message: success
|
||||||
|
? '${capitalizeFirstLetter(_buttonTexts[widget.action]!)} marked successfully!'
|
||||||
|
: 'Failed to mark ${capitalizeFirstLetter(_buttonTexts[widget.action]!)}.',
|
||||||
|
type: success ? SnackbarType.success : SnackbarType.error,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
widget.attendanceController.fetchEmployeesByProject(selectedProjectId);
|
||||||
|
widget.attendanceController.fetchAttendanceLogs(selectedProjectId);
|
||||||
|
await widget.attendanceController
|
||||||
|
.fetchRegularizationLogs(selectedProjectId);
|
||||||
|
await widget.attendanceController.fetchProjectData(selectedProjectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.attendanceController.uploadingStates[widget.uniqueLogKey]?.value =
|
||||||
|
false;
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
isUploading = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() {
|
|
||||||
isUploading = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
widget.attendanceController.uploadingStates[widget.uniqueLogKey]?.value = true;
|
|
||||||
|
|
||||||
final success = await widget.attendanceController.captureAndUploadAttendance(
|
|
||||||
widget.log.id,
|
|
||||||
widget.log.employeeId,
|
|
||||||
selectedProjectId,
|
|
||||||
comment: _buttonComments[widget.action]!,
|
|
||||||
action: _buttonActionCodes[widget.action]!,
|
|
||||||
imageCapture: false,
|
|
||||||
);
|
|
||||||
|
|
||||||
showAppSnackbar(
|
|
||||||
title: success ? 'Success' : 'Error',
|
|
||||||
message: success
|
|
||||||
? '${capitalizeFirstLetter(_buttonTexts[widget.action]!)} marked successfully!'
|
|
||||||
: 'Failed to mark ${capitalizeFirstLetter(_buttonTexts[widget.action]!)}.',
|
|
||||||
type: success ? SnackbarType.success : SnackbarType.error,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
widget.attendanceController.fetchEmployeesByProject(selectedProjectId);
|
|
||||||
widget.attendanceController.fetchAttendanceLogs(selectedProjectId);
|
|
||||||
await widget.attendanceController.fetchRegularizationLogs(selectedProjectId);
|
|
||||||
await widget.attendanceController.fetchProjectData(selectedProjectId);
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.attendanceController.uploadingStates[widget.uniqueLogKey]?.value = false;
|
|
||||||
|
|
||||||
setState(() {
|
|
||||||
isUploading = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final buttonText = _buttonTexts[widget.action]!;
|
final buttonText = _buttonTexts[widget.action]!;
|
||||||
@ -116,17 +119,19 @@ class _RegularizeActionButtonState extends State<RegularizeActionButton> {
|
|||||||
onPressed: isUploading ? null : _handlePress,
|
onPressed: isUploading ? null : _handlePress,
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
foregroundColor:
|
foregroundColor: Colors.white,
|
||||||
Colors.white, // Ensures visibility on all backgrounds
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 6),
|
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 6),
|
||||||
minimumSize: const Size(60, 20),
|
minimumSize: const Size(60, 20),
|
||||||
textStyle: const TextStyle(fontSize: 12),
|
textStyle: const TextStyle(fontSize: 12),
|
||||||
),
|
),
|
||||||
child: isUploading
|
child: isUploading
|
||||||
? const SizedBox(
|
? Container(
|
||||||
width: 16,
|
width: 60,
|
||||||
height: 16,
|
height: 14,
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white.withOpacity(0.5),
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
: FittedBox(
|
: FittedBox(
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
|
@ -153,7 +153,36 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
Widget _buildEmployeeList() {
|
Widget _buildEmployeeList() {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
if (controller.isLoading.value) {
|
if (controller.isLoading.value) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
// Skeleton loader instead of CircularProgressIndicator
|
||||||
|
return ListView.separated(
|
||||||
|
shrinkWrap: true,
|
||||||
|
itemCount: 5, // show 5 skeleton rows
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(height: 4),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 8),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey.shade300,
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
height: 14,
|
||||||
|
color: Colors.grey.shade300,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final selectedRoleId = controller.selectedRoleId.value;
|
final selectedRoleId = controller.selectedRoleId.value;
|
||||||
@ -276,8 +305,9 @@ class _AssignTaskBottomSheetState extends State<AssignTaskBottomSheet> {
|
|||||||
hintText: '',
|
hintText: '',
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
),
|
),
|
||||||
validator: (value) =>
|
validator: (value) => this
|
||||||
this.controller.formFieldValidator(value, fieldType: validatorType),
|
.controller
|
||||||
|
.formFieldValidator(value, fieldType: validatorType),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -16,38 +16,36 @@ class TaskModel {
|
|||||||
required this.assignmentDate,
|
required this.assignmentDate,
|
||||||
this.reportedDate,
|
this.reportedDate,
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.workItem,
|
this.workItem,
|
||||||
required this.workItemId,
|
required this.workItemId,
|
||||||
required this.plannedTask,
|
required this.plannedTask,
|
||||||
required this.completedTask,
|
required this.completedTask,
|
||||||
required this.assignedBy,
|
required this.assignedBy,
|
||||||
this.approvedBy,
|
this.approvedBy,
|
||||||
required this.teamMembers,
|
this.teamMembers = const [],
|
||||||
required this.comments,
|
this.comments = const [],
|
||||||
required this.reportedPreSignedUrls,
|
this.reportedPreSignedUrls = const [],
|
||||||
});
|
});
|
||||||
|
|
||||||
factory TaskModel.fromJson(Map<String, dynamic> json) {
|
factory TaskModel.fromJson(Map<String, dynamic> json) {
|
||||||
return TaskModel(
|
return TaskModel(
|
||||||
assignmentDate: DateTime.parse(json['assignmentDate']),
|
assignmentDate: DateTime.parse(json['assignmentDate'] ?? DateTime.now().toIso8601String()),
|
||||||
reportedDate: json['reportedDate'] != null
|
reportedDate: json['reportedDate'] != null ? DateTime.tryParse(json['reportedDate']) : null,
|
||||||
? DateTime.tryParse(json['reportedDate'])
|
id: json['id']?.toString() ?? '',
|
||||||
: null,
|
workItem: json['workItem'] != null ? WorkItem.fromJson(json['workItem']) : null,
|
||||||
id: json['id'],
|
workItemId: json['workItemId']?.toString() ?? '',
|
||||||
workItem:
|
plannedTask: (json['plannedTask'] as num?)?.toDouble() ?? 0,
|
||||||
json['workItem'] != null ? WorkItem.fromJson(json['workItem']) : null,
|
completedTask: (json['completedTask'] as num?)?.toDouble() ?? 0,
|
||||||
workItemId: json['workItemId'],
|
assignedBy: AssignedBy.fromJson(json['assignedBy'] ?? {}),
|
||||||
plannedTask: (json['plannedTask'] as num).toDouble(),
|
approvedBy: json['approvedBy'] != null ? AssignedBy.fromJson(json['approvedBy']) : null,
|
||||||
completedTask: (json['completedTask'] as num).toDouble(),
|
teamMembers: (json['teamMembers'] as List<dynamic>?)
|
||||||
assignedBy: AssignedBy.fromJson(json['assignedBy']),
|
?.map((e) => TeamMember.fromJson(e))
|
||||||
approvedBy: json['approvedBy'] != null
|
.toList() ??
|
||||||
? AssignedBy.fromJson(json['approvedBy'])
|
[],
|
||||||
: null,
|
comments: (json['comments'] as List<dynamic>?)
|
||||||
teamMembers: (json['teamMembers'] as List)
|
?.map((e) => Comment.fromJson(e))
|
||||||
.map((e) => TeamMember.fromJson(e))
|
.toList() ??
|
||||||
.toList(),
|
[],
|
||||||
comments:
|
|
||||||
(json['comments'] as List).map((e) => Comment.fromJson(e)).toList(),
|
|
||||||
reportedPreSignedUrls: (json['reportedPreSignedUrls'] as List<dynamic>?)
|
reportedPreSignedUrls: (json['reportedPreSignedUrls'] as List<dynamic>?)
|
||||||
?.map((e) => e.toString())
|
?.map((e) => e.toString())
|
||||||
.toList() ??
|
.toList() ??
|
||||||
@ -79,8 +77,7 @@ class WorkItem {
|
|||||||
activityMaster: json['activityMaster'] != null
|
activityMaster: json['activityMaster'] != null
|
||||||
? ActivityMaster.fromJson(json['activityMaster'])
|
? ActivityMaster.fromJson(json['activityMaster'])
|
||||||
: null,
|
: null,
|
||||||
workArea:
|
workArea: json['workArea'] != null ? WorkArea.fromJson(json['workArea']) : null,
|
||||||
json['workArea'] != null ? WorkArea.fromJson(json['workArea']) : null,
|
|
||||||
plannedWork: (json['plannedWork'] as num?)?.toDouble(),
|
plannedWork: (json['plannedWork'] as num?)?.toDouble(),
|
||||||
completedWork: (json['completedWork'] as num?)?.toDouble(),
|
completedWork: (json['completedWork'] as num?)?.toDouble(),
|
||||||
preSignedUrls: (json['preSignedUrls'] as List<dynamic>?)
|
preSignedUrls: (json['preSignedUrls'] as List<dynamic>?)
|
||||||
@ -92,7 +89,7 @@ class WorkItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ActivityMaster {
|
class ActivityMaster {
|
||||||
final String? id; // ✅ Added
|
final String? id;
|
||||||
final String activityName;
|
final String activityName;
|
||||||
|
|
||||||
ActivityMaster({
|
ActivityMaster({
|
||||||
@ -103,13 +100,13 @@ class ActivityMaster {
|
|||||||
factory ActivityMaster.fromJson(Map<String, dynamic> json) {
|
factory ActivityMaster.fromJson(Map<String, dynamic> json) {
|
||||||
return ActivityMaster(
|
return ActivityMaster(
|
||||||
id: json['id']?.toString(),
|
id: json['id']?.toString(),
|
||||||
activityName: json['activityName'] ?? '',
|
activityName: json['activityName']?.toString() ?? '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class WorkArea {
|
class WorkArea {
|
||||||
final String? id; // ✅ Added
|
final String? id;
|
||||||
final String areaName;
|
final String areaName;
|
||||||
final Floor? floor;
|
final Floor? floor;
|
||||||
|
|
||||||
@ -122,7 +119,7 @@ class WorkArea {
|
|||||||
factory WorkArea.fromJson(Map<String, dynamic> json) {
|
factory WorkArea.fromJson(Map<String, dynamic> json) {
|
||||||
return WorkArea(
|
return WorkArea(
|
||||||
id: json['id']?.toString(),
|
id: json['id']?.toString(),
|
||||||
areaName: json['areaName'] ?? '',
|
areaName: json['areaName']?.toString() ?? '',
|
||||||
floor: json['floor'] != null ? Floor.fromJson(json['floor']) : null,
|
floor: json['floor'] != null ? Floor.fromJson(json['floor']) : null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -136,9 +133,8 @@ class Floor {
|
|||||||
|
|
||||||
factory Floor.fromJson(Map<String, dynamic> json) {
|
factory Floor.fromJson(Map<String, dynamic> json) {
|
||||||
return Floor(
|
return Floor(
|
||||||
floorName: json['floorName'] ?? '',
|
floorName: json['floorName']?.toString() ?? '',
|
||||||
building:
|
building: json['building'] != null ? Building.fromJson(json['building']) : null,
|
||||||
json['building'] != null ? Building.fromJson(json['building']) : null,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,7 +145,7 @@ class Building {
|
|||||||
Building({required this.name});
|
Building({required this.name});
|
||||||
|
|
||||||
factory Building.fromJson(Map<String, dynamic> json) {
|
factory Building.fromJson(Map<String, dynamic> json) {
|
||||||
return Building(name: json['name'] ?? '');
|
return Building(name: json['name']?.toString() ?? '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,8 +163,8 @@ class AssignedBy {
|
|||||||
factory AssignedBy.fromJson(Map<String, dynamic> json) {
|
factory AssignedBy.fromJson(Map<String, dynamic> json) {
|
||||||
return AssignedBy(
|
return AssignedBy(
|
||||||
id: json['id']?.toString() ?? '',
|
id: json['id']?.toString() ?? '',
|
||||||
firstName: json['firstName'] ?? '',
|
firstName: json['firstName']?.toString() ?? '',
|
||||||
lastName: json['lastName'],
|
lastName: json['lastName']?.toString(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,7 +199,7 @@ class Comment {
|
|||||||
required this.comment,
|
required this.comment,
|
||||||
required this.commentedBy,
|
required this.commentedBy,
|
||||||
required this.timestamp,
|
required this.timestamp,
|
||||||
required this.preSignedUrls,
|
this.preSignedUrls = const [],
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Comment.fromJson(Map<String, dynamic> json) {
|
factory Comment.fromJson(Map<String, dynamic> json) {
|
||||||
@ -212,7 +208,9 @@ class Comment {
|
|||||||
commentedBy: json['employee'] != null
|
commentedBy: json['employee'] != null
|
||||||
? TeamMember.fromJson(json['employee'])
|
? TeamMember.fromJson(json['employee'])
|
||||||
: TeamMember(id: '', firstName: '', lastName: null),
|
: TeamMember(id: '', firstName: '', lastName: null),
|
||||||
timestamp: DateTime.parse(json['commentDate'] ?? ''),
|
timestamp: json['commentDate'] != null
|
||||||
|
? DateTime.parse(json['commentDate'])
|
||||||
|
: DateTime.now(),
|
||||||
preSignedUrls: (json['preSignedUrls'] as List<dynamic>?)
|
preSignedUrls: (json['preSignedUrls'] as List<dynamic>?)
|
||||||
?.map((e) => e.toString())
|
?.map((e) => e.toString())
|
||||||
.toList() ??
|
.toList() ??
|
||||||
|
@ -147,8 +147,9 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
floatingLabelBehavior: FloatingLabelBehavior.never,
|
floatingLabelBehavior: FloatingLabelBehavior.never,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
MySpacing.height(10),
|
MySpacing.height(10),
|
||||||
|
|
||||||
|
// Reported Images Section
|
||||||
if ((widget.taskData['reportedPreSignedUrls'] as List<dynamic>?)
|
if ((widget.taskData['reportedPreSignedUrls'] as List<dynamic>?)
|
||||||
?.isNotEmpty ==
|
?.isNotEmpty ==
|
||||||
true)
|
true)
|
||||||
@ -157,39 +158,37 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
widget.taskData['reportedPreSignedUrls'] ?? []),
|
widget.taskData['reportedPreSignedUrls'] ?? []),
|
||||||
context: context,
|
context: context,
|
||||||
),
|
),
|
||||||
|
|
||||||
MySpacing.height(10),
|
MySpacing.height(10),
|
||||||
|
|
||||||
|
// Report Actions Dropdown
|
||||||
MyText.titleSmall("Report Actions", fontWeight: 600),
|
MyText.titleSmall("Report Actions", fontWeight: 600),
|
||||||
MySpacing.height(10),
|
MySpacing.height(10),
|
||||||
|
|
||||||
Obx(() {
|
Obx(() {
|
||||||
if (controller.isLoadingWorkStatus.value)
|
if (controller.isLoadingWorkStatus.value)
|
||||||
return const CircularProgressIndicator();
|
return const CircularProgressIndicator();
|
||||||
return PopupMenuButton<String>(
|
return PopupMenuButton<String>(
|
||||||
onSelected: (String value) {
|
onSelected: (value) {
|
||||||
controller.selectedWorkStatusName.value = value;
|
controller.selectedWorkStatusName.value = value;
|
||||||
controller.showAddTaskCheckbox.value = true;
|
controller.showAddTaskCheckbox.value = true;
|
||||||
},
|
},
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12)),
|
borderRadius: BorderRadius.circular(12)),
|
||||||
itemBuilder: (BuildContext context) {
|
itemBuilder: (context) => controller.workStatus.map((status) {
|
||||||
return controller.workStatus.map((status) {
|
return PopupMenuItem<String>(
|
||||||
return PopupMenuItem<String>(
|
value: status.name,
|
||||||
value: status.name,
|
child: Row(
|
||||||
child: Row(
|
children: [
|
||||||
children: [
|
Radio<String>(
|
||||||
Radio<String>(
|
value: status.name,
|
||||||
value: status.name,
|
groupValue: controller.selectedWorkStatusName.value,
|
||||||
groupValue: controller.selectedWorkStatusName.value,
|
onChanged: (_) => Navigator.pop(context, status.name),
|
||||||
onChanged: (_) => Navigator.pop(context, status.name),
|
),
|
||||||
),
|
const SizedBox(width: 8),
|
||||||
const SizedBox(width: 8),
|
MyText.bodySmall(status.name),
|
||||||
MyText.bodySmall(status.name),
|
],
|
||||||
],
|
),
|
||||||
),
|
);
|
||||||
);
|
}).toList(),
|
||||||
}).toList();
|
|
||||||
},
|
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: MySpacing.xy(16, 12),
|
padding: MySpacing.xy(16, 12),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@ -211,9 +210,9 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
MySpacing.height(10),
|
MySpacing.height(10),
|
||||||
|
|
||||||
|
// Add New Task Checkbox
|
||||||
Obx(() {
|
Obx(() {
|
||||||
if (!controller.showAddTaskCheckbox.value)
|
if (!controller.showAddTaskCheckbox.value)
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
@ -221,19 +220,15 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
data: Theme.of(context).copyWith(
|
data: Theme.of(context).copyWith(
|
||||||
checkboxTheme: CheckboxThemeData(
|
checkboxTheme: CheckboxThemeData(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(4),
|
borderRadius: BorderRadius.circular(4)),
|
||||||
),
|
side: const BorderSide(color: Colors.black, width: 2),
|
||||||
side: const BorderSide(
|
|
||||||
color: Colors.black, width: 2),
|
|
||||||
fillColor: MaterialStateProperty.resolveWith<Color>((states) {
|
fillColor: MaterialStateProperty.resolveWith<Color>((states) {
|
||||||
if (states.contains(MaterialState.selected)) {
|
if (states.contains(MaterialState.selected))
|
||||||
return Colors.blueAccent;
|
return Colors.blueAccent;
|
||||||
}
|
return Colors.white;
|
||||||
return Colors.white;
|
|
||||||
}),
|
}),
|
||||||
checkColor:
|
checkColor: MaterialStateProperty.all(Colors.white),
|
||||||
MaterialStateProperty.all(Colors.white),
|
),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: CheckboxListTile(
|
child: CheckboxListTile(
|
||||||
title: MyText.titleSmall("Add new task", fontWeight: 600),
|
title: MyText.titleSmall("Add new task", fontWeight: 600),
|
||||||
@ -245,10 +240,9 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
MySpacing.height(24),
|
MySpacing.height(24),
|
||||||
|
|
||||||
// ✏️ Comment Field
|
// 💬 Comment Field
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.comment_outlined, size: 18, color: Colors.grey[700]),
|
Icon(Icons.comment_outlined, size: 18, color: Colors.grey[700]),
|
||||||
@ -258,8 +252,8 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
),
|
),
|
||||||
MySpacing.height(8),
|
MySpacing.height(8),
|
||||||
TextFormField(
|
TextFormField(
|
||||||
validator: controller.basicValidator.getValidation('comment'),
|
|
||||||
controller: controller.basicValidator.getController('comment'),
|
controller: controller.basicValidator.getController('comment'),
|
||||||
|
validator: controller.basicValidator.getValidation('comment'),
|
||||||
keyboardType: TextInputType.text,
|
keyboardType: TextInputType.text,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: "eg: Work done successfully",
|
hintText: "eg: Work done successfully",
|
||||||
@ -269,10 +263,9 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
floatingLabelBehavior: FloatingLabelBehavior.never,
|
floatingLabelBehavior: FloatingLabelBehavior.never,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
MySpacing.height(16),
|
MySpacing.height(16),
|
||||||
|
|
||||||
// 📸 Image Attachments
|
// 📸 Attach Photos
|
||||||
Row(
|
Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@ -297,21 +290,18 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
onCameraTap: () => controller.pickImages(fromCamera: true),
|
onCameraTap: () => controller.pickImages(fromCamera: true),
|
||||||
onUploadTap: () => controller.pickImages(fromCamera: false),
|
onUploadTap: () => controller.pickImages(fromCamera: false),
|
||||||
onRemoveImage: (index) => controller.removeImageAt(index),
|
onRemoveImage: (index) => controller.removeImageAt(index),
|
||||||
onPreviewImage: (index) {
|
onPreviewImage: (index) => showDialog(
|
||||||
showDialog(
|
context: context,
|
||||||
context: context,
|
builder: (_) => ImageViewerDialog(
|
||||||
builder: (_) => ImageViewerDialog(
|
imageSources: images,
|
||||||
imageSources: images,
|
initialIndex: index,
|
||||||
initialIndex: index,
|
),
|
||||||
),
|
),
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
MySpacing.height(12),
|
MySpacing.height(12),
|
||||||
|
|
||||||
// ✅ Submit/Cancel Buttons moved here
|
// ✅ Submit/Cancel Buttons
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
@ -347,7 +337,6 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
?.text
|
?.text
|
||||||
.trim() ??
|
.trim() ??
|
||||||
'';
|
'';
|
||||||
|
|
||||||
final shouldShowAddTaskSheet =
|
final shouldShowAddTaskSheet =
|
||||||
controller.isAddTaskChecked.value;
|
controller.isAddTaskChecked.value;
|
||||||
|
|
||||||
@ -408,10 +397,9 @@ class _ReportActionBottomSheetState extends State<ReportActionBottomSheet>
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
MySpacing.height(12),
|
MySpacing.height(12),
|
||||||
|
|
||||||
// 💬 Previous Comments List (only below submit)
|
// 💬 Previous Comments
|
||||||
if ((widget.taskData['taskComments'] as List<dynamic>?)?.isNotEmpty ==
|
if ((widget.taskData['taskComments'] as List<dynamic>?)?.isNotEmpty ==
|
||||||
true) ...[
|
true) ...[
|
||||||
Row(
|
Row(
|
||||||
|
@ -36,7 +36,7 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
|
|||||||
late final TextEditingController _genderController;
|
late final TextEditingController _genderController;
|
||||||
late final TextEditingController _roleController;
|
late final TextEditingController _roleController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_orgFieldController = TextEditingController();
|
_orgFieldController = TextEditingController();
|
||||||
@ -50,7 +50,6 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
|
|||||||
_controller.editingEmployeeData = widget.employeeData;
|
_controller.editingEmployeeData = widget.employeeData;
|
||||||
_controller.prefillFields();
|
_controller.prefillFields();
|
||||||
|
|
||||||
// Prepopulate hasApplicationAccess and email
|
|
||||||
_hasApplicationAccess =
|
_hasApplicationAccess =
|
||||||
widget.employeeData?['hasApplicationAccess'] ?? false;
|
widget.employeeData?['hasApplicationAccess'] ?? false;
|
||||||
|
|
||||||
@ -60,22 +59,32 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
|
|||||||
email.toString();
|
email.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger UI rebuild to reflect email & checkbox
|
final orgId = widget.employeeData?['organization_id'];
|
||||||
setState(() {});
|
if (orgId != null) {
|
||||||
|
final org = _organizationController.organizations
|
||||||
|
.firstWhereOrNull((o) => o.id == orgId);
|
||||||
|
if (org != null) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
_organizationController.selectOrganization(org);
|
||||||
|
_controller.selectedOrganizationId = org.id;
|
||||||
|
_orgFieldController.text = org.name;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Joining date
|
// ✅ Prefill Joining date
|
||||||
if (_controller.joiningDate != null) {
|
if (_controller.joiningDate != null) {
|
||||||
_joiningDateController.text =
|
_joiningDateController.text =
|
||||||
DateFormat('dd MMM yyyy').format(_controller.joiningDate!);
|
DateFormat('dd MMM yyyy').format(_controller.joiningDate!);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gender
|
// ✅ Prefill Gender
|
||||||
if (_controller.selectedGender != null) {
|
if (_controller.selectedGender != null) {
|
||||||
_genderController.text =
|
_genderController.text =
|
||||||
_controller.selectedGender!.name.capitalizeFirst ?? '';
|
_controller.selectedGender!.name.capitalizeFirst ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Role
|
// ✅ Prefill Role
|
||||||
_controller.fetchRoles().then((_) {
|
_controller.fetchRoles().then((_) {
|
||||||
if (_controller.selectedRoleId != null) {
|
if (_controller.selectedRoleId != null) {
|
||||||
final roleName = _controller.roles.firstWhereOrNull(
|
final roleName = _controller.roles.firstWhereOrNull(
|
||||||
@ -91,6 +100,7 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
|
|||||||
_controller.fetchRoles();
|
_controller.fetchRoles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_orgFieldController.dispose();
|
_orgFieldController.dispose();
|
||||||
@ -337,8 +347,7 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
|
|||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
keyboardType: TextInputType.emailAddress,
|
keyboardType: TextInputType.emailAddress,
|
||||||
decoration: _inputDecoration('e.g., john.doe@example.com').copyWith(
|
decoration: _inputDecoration('e.g., john.doe@example.com').copyWith(),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -45,7 +45,7 @@ getPageRoute() {
|
|||||||
page: () => DashboardScreen(),
|
page: () => DashboardScreen(),
|
||||||
middlewares: [AuthMiddleware()]),
|
middlewares: [AuthMiddleware()]),
|
||||||
GetPage(
|
GetPage(
|
||||||
name: '/home',
|
name: '/dashboard',
|
||||||
page: () => DashboardScreen(), // or your actual home screen
|
page: () => DashboardScreen(), // or your actual home screen
|
||||||
middlewares: [AuthMiddleware()],
|
middlewares: [AuthMiddleware()],
|
||||||
),
|
),
|
||||||
|
@ -123,20 +123,24 @@ class _EmailLoginFormState extends State<EmailLoginForm> with UIMixin {
|
|||||||
),
|
),
|
||||||
MySpacing.height(28),
|
MySpacing.height(28),
|
||||||
Center(
|
Center(
|
||||||
child: MyButton.rounded(
|
child: Obx(() {
|
||||||
onPressed: controller.onLogin,
|
final isLoading = controller.isLoading.value;
|
||||||
elevation: 2,
|
return MyButton.rounded(
|
||||||
padding: MySpacing.xy(80, 16),
|
onPressed: isLoading
|
||||||
borderRadiusAll: 10,
|
? null
|
||||||
backgroundColor: contentTheme.brandRed,
|
: controller.onLogin,
|
||||||
child: MyText.labelLarge(
|
elevation: 2,
|
||||||
'Login',
|
padding: MySpacing.xy(80, 16),
|
||||||
fontWeight: 700,
|
borderRadiusAll: 10,
|
||||||
color: contentTheme.onPrimary,
|
backgroundColor: contentTheme.brandRed,
|
||||||
),
|
child: MyText.labelLarge(
|
||||||
),
|
isLoading ? 'Logging in...' : 'Login',
|
||||||
|
fontWeight: 700,
|
||||||
|
color: contentTheme.onPrimary,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -37,7 +37,7 @@ class _LoginScreenState extends State<LoginScreen> with UIMixin {
|
|||||||
builder: (_) {
|
builder: (_) {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
if (controller.isLoading.value) {
|
if (controller.isLoading.value) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: LinearProgressIndicator());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Form(
|
return Form(
|
||||||
|
@ -84,8 +84,6 @@ class _DashboardScreenState extends State<DashboardScreen> with UIMixin {
|
|||||||
/// Project Progress Chart Section
|
/// Project Progress Chart Section
|
||||||
Widget _buildProjectProgressChartSection() {
|
Widget _buildProjectProgressChartSection() {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
|
|
||||||
|
|
||||||
if (dashboardController.projectChartData.isEmpty) {
|
if (dashboardController.projectChartData.isEmpty) {
|
||||||
return const Padding(
|
return const Padding(
|
||||||
padding: EdgeInsets.all(16),
|
padding: EdgeInsets.all(16),
|
||||||
@ -110,7 +108,6 @@ class _DashboardScreenState extends State<DashboardScreen> with UIMixin {
|
|||||||
/// Attendance Chart Section
|
/// Attendance Chart Section
|
||||||
Widget _buildAttendanceChartSection() {
|
Widget _buildAttendanceChartSection() {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
|
|
||||||
final isAttendanceAllowed = menuController.isMenuAllowed("Attendance");
|
final isAttendanceAllowed = menuController.isMenuAllowed("Attendance");
|
||||||
|
|
||||||
if (!isAttendanceAllowed) {
|
if (!isAttendanceAllowed) {
|
||||||
@ -212,7 +209,7 @@ class _DashboardScreenState extends State<DashboardScreen> with UIMixin {
|
|||||||
return _buildLoadingSkeleton(context);
|
return _buildLoadingSkeleton(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (menuController.hasError.value && menuController.menuItems.isEmpty) {
|
if (menuController.hasError.value || menuController.menuItems.isEmpty) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
child: Center(
|
child: Center(
|
||||||
@ -224,6 +221,10 @@ class _DashboardScreenState extends State<DashboardScreen> with UIMixin {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final projectController = Get.find<ProjectController>();
|
||||||
|
final isProjectSelected = projectController.selectedProject != null;
|
||||||
|
|
||||||
|
// Keep previous stat items (icons, title, routes)
|
||||||
final stats = [
|
final stats = [
|
||||||
_StatItem(LucideIcons.scan_face, "Attendance", contentTheme.success,
|
_StatItem(LucideIcons.scan_face, "Attendance", contentTheme.success,
|
||||||
DashboardScreen.attendanceRoute),
|
DashboardScreen.attendanceRoute),
|
||||||
@ -241,8 +242,16 @@ class _DashboardScreenState extends State<DashboardScreen> with UIMixin {
|
|||||||
DashboardScreen.documentMainPageRoute),
|
DashboardScreen.documentMainPageRoute),
|
||||||
];
|
];
|
||||||
|
|
||||||
final projectController = Get.find<ProjectController>();
|
// Safe menu check function to avoid exceptions
|
||||||
final isProjectSelected = projectController.selectedProject != null;
|
bool _isMenuAllowed(String menuTitle) {
|
||||||
|
try {
|
||||||
|
return menuController.menuItems.isNotEmpty
|
||||||
|
? menuController.isMenuAllowed(menuTitle)
|
||||||
|
: false;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@ -250,7 +259,6 @@ class _DashboardScreenState extends State<DashboardScreen> with UIMixin {
|
|||||||
if (!isProjectSelected) _buildNoProjectMessage(),
|
if (!isProjectSelected) _buildNoProjectMessage(),
|
||||||
LayoutBuilder(
|
LayoutBuilder(
|
||||||
builder: (context, constraints) {
|
builder: (context, constraints) {
|
||||||
// ✅ smaller width cards → fit more in a row
|
|
||||||
int crossAxisCount = (constraints.maxWidth ~/ 80).clamp(2, 8);
|
int crossAxisCount = (constraints.maxWidth ~/ 80).clamp(2, 8);
|
||||||
double cardWidth =
|
double cardWidth =
|
||||||
(constraints.maxWidth - (crossAxisCount - 1) * 6) /
|
(constraints.maxWidth - (crossAxisCount - 1) * 6) /
|
||||||
@ -261,14 +269,10 @@ class _DashboardScreenState extends State<DashboardScreen> with UIMixin {
|
|||||||
runSpacing: 6,
|
runSpacing: 6,
|
||||||
alignment: WrapAlignment.start,
|
alignment: WrapAlignment.start,
|
||||||
children: stats
|
children: stats
|
||||||
.where((stat) {
|
.where((stat) => _isMenuAllowed(stat.title))
|
||||||
if (stat.title == "Documents") return true;
|
|
||||||
return menuController.isMenuAllowed(stat.title);
|
|
||||||
})
|
|
||||||
.map((stat) =>
|
.map((stat) =>
|
||||||
_buildStatCard(stat, isProjectSelected, cardWidth))
|
_buildStatCard(stat, isProjectSelected, cardWidth))
|
||||||
.toList()
|
.toList(),
|
||||||
.cast<Widget>(),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -360,33 +360,31 @@ class _ContactDetailScreenState extends State<ContactDetailScreen> {
|
|||||||
[...activeComments, ...inactiveComments].reversed.toList();
|
[...activeComments, ...inactiveComments].reversed.toList();
|
||||||
final editingId = directoryController.editingCommentId.value;
|
final editingId = directoryController.editingCommentId.value;
|
||||||
|
|
||||||
if (comments.isEmpty) {
|
|
||||||
return Center(
|
|
||||||
child: MyText.bodyLarge("No notes yet.", color: Colors.grey),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
MyRefreshIndicator(
|
comments.isEmpty
|
||||||
onRefresh: () async {
|
? Center(
|
||||||
await directoryController.fetchCommentsForContact(contactId,
|
child: MyText.bodyLarge("No notes yet.", color: Colors.grey),
|
||||||
active: true);
|
)
|
||||||
await directoryController.fetchCommentsForContact(contactId,
|
: MyRefreshIndicator(
|
||||||
active: false);
|
onRefresh: () async {
|
||||||
},
|
await directoryController.fetchCommentsForContact(contactId,
|
||||||
child: Padding(
|
active: true);
|
||||||
padding: MySpacing.xy(12, 12),
|
await directoryController.fetchCommentsForContact(contactId,
|
||||||
child: ListView.separated(
|
active: false);
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
},
|
||||||
padding: const EdgeInsets.only(bottom: 100),
|
child: Padding(
|
||||||
itemCount: comments.length,
|
padding: MySpacing.xy(12, 12),
|
||||||
separatorBuilder: (_, __) => MySpacing.height(14),
|
child: ListView.separated(
|
||||||
itemBuilder: (_, index) =>
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
_buildCommentItem(comments[index], editingId, contactId),
|
padding: const EdgeInsets.only(bottom: 100),
|
||||||
),
|
itemCount: comments.length,
|
||||||
),
|
separatorBuilder: (_, __) => MySpacing.height(14),
|
||||||
),
|
itemBuilder: (_, index) => _buildCommentItem(
|
||||||
|
comments[index], editingId, contactId),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
if (editingId == null)
|
if (editingId == null)
|
||||||
Positioned(
|
Positioned(
|
||||||
bottom: 20,
|
bottom: 20,
|
||||||
|
@ -27,8 +27,8 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
|||||||
final DocumentDetailsController controller =
|
final DocumentDetailsController controller =
|
||||||
Get.find<DocumentDetailsController>();
|
Get.find<DocumentDetailsController>();
|
||||||
|
|
||||||
final PermissionController permissionController =
|
final permissionController = Get.put(PermissionController());
|
||||||
Get.find<PermissionController>();
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
|
import 'dart:convert';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:marco/controller/document/user_document_controller.dart';
|
|
||||||
import 'package:marco/controller/project_controller.dart';
|
|
||||||
import 'package:marco/helpers/widgets/my_spacing.dart';
|
|
||||||
import 'package:marco/helpers/widgets/my_text.dart';
|
|
||||||
import 'package:marco/helpers/widgets/my_refresh_indicator.dart';
|
|
||||||
import 'package:marco/helpers/utils/permission_constants.dart';
|
|
||||||
import 'package:marco/model/document/user_document_filter_bottom_sheet.dart';
|
|
||||||
import 'package:marco/model/document/documents_list_model.dart';
|
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:marco/helpers/widgets/my_custom_skeleton.dart';
|
import 'package:marco/controller/document/document_details_controller.dart';
|
||||||
import 'package:marco/model/document/document_upload_bottom_sheet.dart';
|
|
||||||
import 'package:marco/controller/document/document_upload_controller.dart';
|
import 'package:marco/controller/document/document_upload_controller.dart';
|
||||||
import 'package:marco/view/document/document_details_page.dart';
|
import 'package:marco/controller/document/user_document_controller.dart';
|
||||||
|
import 'package:marco/controller/permission_controller.dart';
|
||||||
|
import 'package:marco/controller/project_controller.dart';
|
||||||
|
import 'package:marco/helpers/utils/permission_constants.dart';
|
||||||
import 'package:marco/helpers/widgets/custom_app_bar.dart';
|
import 'package:marco/helpers/widgets/custom_app_bar.dart';
|
||||||
import 'package:marco/helpers/widgets/my_confirmation_dialog.dart';
|
import 'package:marco/helpers/widgets/my_confirmation_dialog.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_refresh_indicator.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_spacing.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_text.dart';
|
||||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||||
import 'package:marco/controller/permission_controller.dart';
|
import 'package:marco/helpers/widgets/my_custom_skeleton.dart';
|
||||||
import 'package:marco/controller/document/document_details_controller.dart';
|
import 'package:marco/model/document/document_upload_bottom_sheet.dart';
|
||||||
import 'dart:convert';
|
import 'package:marco/model/document/documents_list_model.dart';
|
||||||
|
import 'package:marco/model/document/user_document_filter_bottom_sheet.dart';
|
||||||
|
import 'package:marco/view/document/document_details_page.dart';
|
||||||
|
|
||||||
class UserDocumentsPage extends StatefulWidget {
|
class UserDocumentsPage extends StatefulWidget {
|
||||||
final String? entityId;
|
final String? entityId;
|
||||||
@ -36,10 +36,9 @@ class UserDocumentsPage extends StatefulWidget {
|
|||||||
|
|
||||||
class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
||||||
final DocumentController docController = Get.put(DocumentController());
|
final DocumentController docController = Get.put(DocumentController());
|
||||||
final PermissionController permissionController =
|
final PermissionController permissionController = Get.put(PermissionController());
|
||||||
Get.find<PermissionController>();
|
final DocumentDetailsController controller = Get.put(DocumentDetailsController());
|
||||||
final DocumentDetailsController controller =
|
|
||||||
Get.put(DocumentDetailsController());
|
|
||||||
String get entityTypeId => widget.isEmployee
|
String get entityTypeId => widget.isEmployee
|
||||||
? Permissions.employeeEntity
|
? Permissions.employeeEntity
|
||||||
: Permissions.projectEntity;
|
: Permissions.projectEntity;
|
||||||
@ -68,12 +67,9 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildDocumentTile(DocumentItem doc, bool showDateHeader) {
|
Widget _buildDocumentTile(DocumentItem doc, bool showDateHeader) {
|
||||||
final uploadDate =
|
final uploadDate = DateFormat("dd MMM yyyy").format(doc.uploadedAt.toLocal());
|
||||||
DateFormat("dd MMM yyyy").format(doc.uploadedAt.toLocal());
|
|
||||||
|
|
||||||
final uploader = doc.uploadedBy.firstName.isNotEmpty
|
final uploader = doc.uploadedBy.firstName.isNotEmpty
|
||||||
? "Added by ${doc.uploadedBy.firstName} ${doc.uploadedBy.lastName}"
|
? "Added by ${doc.uploadedBy.firstName} ${doc.uploadedBy.lastName}".trim()
|
||||||
.trim()
|
|
||||||
: "Added by you";
|
: "Added by you";
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
@ -91,7 +87,6 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
),
|
),
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// 👉 Navigate to details page
|
|
||||||
Get.to(() => DocumentDetailsPage(documentId: doc.id));
|
Get.to(() => DocumentDetailsPage(documentId: doc.id));
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
@ -146,92 +141,90 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
PopupMenuButton<String>(
|
Obx(() {
|
||||||
icon: const Icon(Icons.more_vert, color: Colors.black54),
|
// React to permission changes
|
||||||
onSelected: (value) async {
|
return PopupMenuButton<String>(
|
||||||
if (value == "delete") {
|
icon: const Icon(Icons.more_vert, color: Colors.black54),
|
||||||
// existing delete flow (unchanged)
|
onSelected: (value) async {
|
||||||
final result = await showDialog<bool>(
|
if (value == "delete") {
|
||||||
context: context,
|
final result = await showDialog<bool>(
|
||||||
builder: (_) => ConfirmDialog(
|
context: context,
|
||||||
title: "Delete Document",
|
builder: (_) => ConfirmDialog(
|
||||||
message:
|
title: "Delete Document",
|
||||||
"Are you sure you want to delete \"${doc.name}\"?\nThis action cannot be undone.",
|
message:
|
||||||
confirmText: "Delete",
|
"Are you sure you want to delete \"${doc.name}\"?\nThis action cannot be undone.",
|
||||||
cancelText: "Cancel",
|
confirmText: "Delete",
|
||||||
icon: Icons.delete_forever,
|
cancelText: "Cancel",
|
||||||
confirmColor: Colors.redAccent,
|
icon: Icons.delete_forever,
|
||||||
onConfirm: () async {
|
confirmColor: Colors.redAccent,
|
||||||
final success =
|
onConfirm: () async {
|
||||||
await docController.toggleDocumentActive(
|
final success =
|
||||||
doc.id,
|
await docController.toggleDocumentActive(
|
||||||
isActive: false,
|
doc.id,
|
||||||
entityTypeId: entityTypeId,
|
isActive: false,
|
||||||
entityId: resolvedEntityId,
|
entityTypeId: entityTypeId,
|
||||||
);
|
entityId: resolvedEntityId,
|
||||||
|
);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Deleted",
|
title: "Deleted",
|
||||||
message: "Document deleted successfully",
|
message: "Document deleted successfully",
|
||||||
type: SnackbarType.success,
|
type: SnackbarType.success,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
title: "Error",
|
title: "Error",
|
||||||
message: "Failed to delete document",
|
message: "Failed to delete document",
|
||||||
type: SnackbarType.error,
|
type: SnackbarType.error,
|
||||||
);
|
);
|
||||||
throw Exception(
|
throw Exception("Failed to delete");
|
||||||
"Failed to delete"); // keep dialog open
|
}
|
||||||
}
|
},
|
||||||
},
|
),
|
||||||
|
);
|
||||||
|
if (result == true) {
|
||||||
|
debugPrint("✅ Document deleted and removed from list");
|
||||||
|
}
|
||||||
|
} else if (value == "restore") {
|
||||||
|
final success = await docController.toggleDocumentActive(
|
||||||
|
doc.id,
|
||||||
|
isActive: true,
|
||||||
|
entityTypeId: entityTypeId,
|
||||||
|
entityId: resolvedEntityId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
showAppSnackbar(
|
||||||
|
title: "Restored",
|
||||||
|
message: "Document restored successfully",
|
||||||
|
type: SnackbarType.success,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
showAppSnackbar(
|
||||||
|
title: "Error",
|
||||||
|
message: "Failed to restore document",
|
||||||
|
type: SnackbarType.error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
itemBuilder: (context) => [
|
||||||
|
if (doc.isActive &&
|
||||||
|
permissionController.hasPermission(Permissions.deleteDocument))
|
||||||
|
const PopupMenuItem(
|
||||||
|
value: "delete",
|
||||||
|
child: Text("Delete"),
|
||||||
|
)
|
||||||
|
else if (!doc.isActive &&
|
||||||
|
permissionController.hasPermission(Permissions.modifyDocument))
|
||||||
|
const PopupMenuItem(
|
||||||
|
value: "restore",
|
||||||
|
child: Text("Restore"),
|
||||||
),
|
),
|
||||||
);
|
],
|
||||||
if (result == true) {
|
);
|
||||||
debugPrint("✅ Document deleted and removed from list");
|
}),
|
||||||
}
|
|
||||||
} else if (value == "restore") {
|
|
||||||
// existing activate flow (unchanged)
|
|
||||||
final success = await docController.toggleDocumentActive(
|
|
||||||
doc.id,
|
|
||||||
isActive: true,
|
|
||||||
entityTypeId: entityTypeId,
|
|
||||||
entityId: resolvedEntityId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
showAppSnackbar(
|
|
||||||
title: "Restored",
|
|
||||||
message: "Document reastored successfully",
|
|
||||||
type: SnackbarType.success,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
showAppSnackbar(
|
|
||||||
title: "Error",
|
|
||||||
message: "Failed to restore document",
|
|
||||||
type: SnackbarType.error,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
itemBuilder: (context) => [
|
|
||||||
if (doc.isActive &&
|
|
||||||
permissionController
|
|
||||||
.hasPermission(Permissions.deleteDocument))
|
|
||||||
const PopupMenuItem(
|
|
||||||
value: "delete",
|
|
||||||
child: Text("Delete"),
|
|
||||||
)
|
|
||||||
else if (!doc.isActive &&
|
|
||||||
permissionController
|
|
||||||
.hasPermission(Permissions.modifyDocument))
|
|
||||||
const PopupMenuItem(
|
|
||||||
value: "restore",
|
|
||||||
child: Text("Restore"),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -267,7 +260,6 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
padding: MySpacing.xy(8, 8),
|
padding: MySpacing.xy(8, 8),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
// 🔍 Search Bar
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 35,
|
height: 35,
|
||||||
@ -283,15 +275,13 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
},
|
},
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
prefixIcon:
|
prefixIcon: const Icon(Icons.search, size: 20, color: Colors.grey),
|
||||||
const Icon(Icons.search, size: 20, color: Colors.grey),
|
|
||||||
suffixIcon: ValueListenableBuilder<TextEditingValue>(
|
suffixIcon: ValueListenableBuilder<TextEditingValue>(
|
||||||
valueListenable: docController.searchController,
|
valueListenable: docController.searchController,
|
||||||
builder: (context, value, _) {
|
builder: (context, value, _) {
|
||||||
if (value.text.isEmpty) return const SizedBox.shrink();
|
if (value.text.isEmpty) return const SizedBox.shrink();
|
||||||
return IconButton(
|
return IconButton(
|
||||||
icon: const Icon(Icons.clear,
|
icon: const Icon(Icons.clear, size: 20, color: Colors.grey),
|
||||||
size: 20, color: Colors.grey),
|
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
docController.searchController.clear();
|
docController.searchController.clear();
|
||||||
docController.searchQuery.value = '';
|
docController.searchQuery.value = '';
|
||||||
@ -320,8 +310,6 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
MySpacing.width(8),
|
MySpacing.width(8),
|
||||||
|
|
||||||
// 🛠️ Filter Icon with indicator
|
|
||||||
Obx(() {
|
Obx(() {
|
||||||
final isFilterActive = docController.hasActiveFilters();
|
final isFilterActive = docController.hasActiveFilters();
|
||||||
return Stack(
|
return Stack(
|
||||||
@ -337,18 +325,13 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
child: IconButton(
|
child: IconButton(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
constraints: BoxConstraints(),
|
constraints: BoxConstraints(),
|
||||||
icon: Icon(
|
icon: Icon(Icons.tune, size: 20, color: Colors.black87),
|
||||||
Icons.tune,
|
|
||||||
size: 20,
|
|
||||||
color: Colors.black87,
|
|
||||||
),
|
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
shape: const RoundedRectangleBorder(
|
shape: const RoundedRectangleBorder(
|
||||||
borderRadius:
|
borderRadius: BorderRadius.vertical(top: Radius.circular(5)),
|
||||||
BorderRadius.vertical(top: Radius.circular(5)),
|
|
||||||
),
|
),
|
||||||
builder: (_) => UserDocumentFilterBottomSheet(
|
builder: (_) => UserDocumentFilterBottomSheet(
|
||||||
entityId: resolvedEntityId,
|
entityId: resolvedEntityId,
|
||||||
@ -375,8 +358,6 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
MySpacing.width(10),
|
MySpacing.width(10),
|
||||||
|
|
||||||
// ⋮ Menu (Show Inactive toggle)
|
|
||||||
Container(
|
Container(
|
||||||
height: 35,
|
height: 35,
|
||||||
width: 35,
|
width: 35,
|
||||||
@ -387,8 +368,7 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
),
|
),
|
||||||
child: PopupMenuButton<int>(
|
child: PopupMenuButton<int>(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
icon:
|
icon: const Icon(Icons.more_vert, size: 20, color: Colors.black87),
|
||||||
const Icon(Icons.more_vert, size: 20, color: Colors.black87),
|
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
),
|
),
|
||||||
@ -439,8 +419,7 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
|
|
||||||
Widget _buildStatusHeader() {
|
Widget _buildStatusHeader() {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
final isInactive = docController.showInactive.value;
|
if (!docController.showInactive.value) return const SizedBox.shrink();
|
||||||
if (!isInactive) return const SizedBox.shrink(); // hide when active
|
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
@ -448,18 +427,11 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
color: Colors.red.shade50,
|
color: Colors.red.shade50,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(Icons.visibility_off, color: Colors.red, size: 18),
|
||||||
Icons.visibility_off,
|
|
||||||
color: Colors.red,
|
|
||||||
size: 18,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Text(
|
Text(
|
||||||
"Showing Deleted Documents",
|
"Showing Deleted Documents",
|
||||||
style: TextStyle(
|
style: TextStyle(color: Colors.red, fontWeight: FontWeight.w600),
|
||||||
color: Colors.red,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -468,30 +440,33 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildBody(BuildContext context) {
|
Widget _buildBody(BuildContext context) {
|
||||||
// 🔒 Check for viewDocument permission
|
|
||||||
if (!permissionController.hasPermission(Permissions.viewDocument)) {
|
|
||||||
return Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.lock_outline, size: 60, color: Colors.grey),
|
|
||||||
MySpacing.height(18),
|
|
||||||
MyText.titleMedium(
|
|
||||||
'Access Denied',
|
|
||||||
fontWeight: 600,
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
MySpacing.height(10),
|
|
||||||
MyText.bodySmall(
|
|
||||||
'You do not have permission to view documents.',
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
|
if (permissionController.permissions.isEmpty) {
|
||||||
|
return Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!permissionController.hasPermission(Permissions.viewDocument)) {
|
||||||
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.lock_outline, size: 60, color: Colors.grey),
|
||||||
|
MySpacing.height(18),
|
||||||
|
MyText.titleMedium(
|
||||||
|
'Access Denied',
|
||||||
|
fontWeight: 600,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
MySpacing.height(10),
|
||||||
|
MyText.bodySmall(
|
||||||
|
'You do not have permission to view documents.',
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (docController.isLoading.value && docController.documents.isEmpty) {
|
if (docController.isLoading.value && docController.documents.isEmpty) {
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
@ -510,8 +485,7 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
final combinedFilter = {
|
final combinedFilter = {
|
||||||
'uploadedByIds': docController.selectedUploadedBy.toList(),
|
'uploadedByIds': docController.selectedUploadedBy.toList(),
|
||||||
'documentCategoryIds':
|
'documentCategoryIds': docController.selectedCategory.toList(),
|
||||||
docController.selectedCategory.toList(),
|
|
||||||
'documentTypeIds': docController.selectedType.toList(),
|
'documentTypeIds': docController.selectedType.toList(),
|
||||||
'documentTagIds': docController.selectedTag.toList(),
|
'documentTagIds': docController.selectedTag.toList(),
|
||||||
};
|
};
|
||||||
@ -525,9 +499,7 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
},
|
},
|
||||||
child: ListView(
|
child: ListView(
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
padding: docs.isEmpty
|
padding: docs.isEmpty ? null : const EdgeInsets.fromLTRB(0, 0, 0, 80),
|
||||||
? null
|
|
||||||
: const EdgeInsets.fromLTRB(0, 0, 0, 80),
|
|
||||||
children: docs.isEmpty
|
children: docs.isEmpty
|
||||||
? [
|
? [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
@ -543,8 +515,8 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
final currentDate = DateFormat("dd MMM yyyy")
|
final currentDate = DateFormat("dd MMM yyyy")
|
||||||
.format(doc.uploadedAt.toLocal());
|
.format(doc.uploadedAt.toLocal());
|
||||||
final prevDate = index > 0
|
final prevDate = index > 0
|
||||||
? DateFormat("dd MMM yyyy").format(
|
? DateFormat("dd MMM yyyy")
|
||||||
docs[index - 1].uploadedAt.toLocal())
|
.format(docs[index - 1].uploadedAt.toLocal())
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
final showDateHeader = currentDate != prevDate;
|
final showDateHeader = currentDate != prevDate;
|
||||||
@ -591,58 +563,61 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
|||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
body: _buildBody(context),
|
body: _buildBody(context),
|
||||||
floatingActionButton: permissionController
|
floatingActionButton: Obx(() {
|
||||||
.hasPermission(Permissions.uploadDocument)
|
if (permissionController.permissions.isEmpty) return SizedBox.shrink();
|
||||||
? FloatingActionButton.extended(
|
|
||||||
onPressed: () {
|
|
||||||
final uploadController = Get.put(DocumentUploadController());
|
|
||||||
|
|
||||||
showModalBottomSheet(
|
return permissionController.hasPermission(Permissions.uploadDocument)
|
||||||
context: context,
|
? FloatingActionButton.extended(
|
||||||
isScrollControlled: true,
|
onPressed: () {
|
||||||
backgroundColor: Colors.transparent,
|
final uploadController = Get.put(DocumentUploadController());
|
||||||
builder: (_) => DocumentUploadBottomSheet(
|
|
||||||
isEmployee: widget.isEmployee,
|
|
||||||
onSubmit: (data) async {
|
|
||||||
final success = await uploadController.uploadDocument(
|
|
||||||
name: data["name"],
|
|
||||||
description: data["description"],
|
|
||||||
documentId: data["documentId"],
|
|
||||||
entityId: resolvedEntityId,
|
|
||||||
documentTypeId: data["documentTypeId"],
|
|
||||||
fileName: data["attachment"]["fileName"],
|
|
||||||
base64Data: data["attachment"]["base64Data"],
|
|
||||||
contentType: data["attachment"]["contentType"],
|
|
||||||
fileSize: data["attachment"]["fileSize"],
|
|
||||||
);
|
|
||||||
|
|
||||||
if (success) {
|
showModalBottomSheet(
|
||||||
Navigator.pop(context);
|
context: context,
|
||||||
docController.fetchDocuments(
|
isScrollControlled: true,
|
||||||
entityTypeId: entityTypeId,
|
backgroundColor: Colors.transparent,
|
||||||
|
builder: (_) => DocumentUploadBottomSheet(
|
||||||
|
isEmployee: widget.isEmployee,
|
||||||
|
onSubmit: (data) async {
|
||||||
|
final success = await uploadController.uploadDocument(
|
||||||
|
name: data["name"],
|
||||||
|
description: data["description"],
|
||||||
|
documentId: data["documentId"],
|
||||||
entityId: resolvedEntityId,
|
entityId: resolvedEntityId,
|
||||||
reset: true,
|
documentTypeId: data["documentTypeId"],
|
||||||
|
fileName: data["attachment"]["fileName"],
|
||||||
|
base64Data: data["attachment"]["base64Data"],
|
||||||
|
contentType: data["attachment"]["contentType"],
|
||||||
|
fileSize: data["attachment"]["fileSize"],
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
showAppSnackbar(
|
if (success) {
|
||||||
title: "Error",
|
Navigator.pop(context);
|
||||||
message: "Upload failed, please try again",
|
docController.fetchDocuments(
|
||||||
type: SnackbarType.error,
|
entityTypeId: entityTypeId,
|
||||||
);
|
entityId: resolvedEntityId,
|
||||||
}
|
reset: true,
|
||||||
},
|
);
|
||||||
),
|
} else {
|
||||||
);
|
showAppSnackbar(
|
||||||
},
|
title: "Error",
|
||||||
icon: const Icon(Icons.add, color: Colors.white),
|
message: "Upload failed, please try again",
|
||||||
label: MyText.bodyMedium(
|
type: SnackbarType.error,
|
||||||
"Add Document",
|
);
|
||||||
color: Colors.white,
|
}
|
||||||
fontWeight: 600,
|
},
|
||||||
),
|
),
|
||||||
backgroundColor: Colors.red,
|
);
|
||||||
)
|
},
|
||||||
: null,
|
icon: const Icon(Icons.add, color: Colors.white),
|
||||||
|
label: MyText.bodyMedium(
|
||||||
|
"Add Document",
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: 600,
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
)
|
||||||
|
: SizedBox.shrink();
|
||||||
|
}),
|
||||||
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
|
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,8 @@ class EmployeeDetailPage extends StatefulWidget {
|
|||||||
class _EmployeeDetailPageState extends State<EmployeeDetailPage> {
|
class _EmployeeDetailPageState extends State<EmployeeDetailPage> {
|
||||||
final EmployeesScreenController controller =
|
final EmployeesScreenController controller =
|
||||||
Get.put(EmployeesScreenController());
|
Get.put(EmployeesScreenController());
|
||||||
final PermissionController _permissionController =
|
final PermissionController permissionController =
|
||||||
Get.find<PermissionController>();
|
Get.put(PermissionController());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -272,6 +272,7 @@ class _EmployeeDetailPageState extends State<EmployeeDetailPage> {
|
|||||||
'job_role_id': employee.jobRoleId,
|
'job_role_id': employee.jobRoleId,
|
||||||
'joining_date':
|
'joining_date':
|
||||||
employee.joiningDate?.toIso8601String(),
|
employee.joiningDate?.toIso8601String(),
|
||||||
|
'organization_id': employee.organizationId,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -292,7 +293,7 @@ class _EmployeeDetailPageState extends State<EmployeeDetailPage> {
|
|||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
floatingActionButton: Obx(() {
|
floatingActionButton: Obx(() {
|
||||||
if (!_permissionController.hasPermission(Permissions.assignToProject)) {
|
if (!permissionController.hasPermission(Permissions.assignToProject)) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
if (controller.isLoadingEmployeeDetails.value ||
|
if (controller.isLoadingEmployeeDetails.value ||
|
||||||
|
@ -29,8 +29,8 @@ class EmployeesScreen extends StatefulWidget {
|
|||||||
class _EmployeesScreenState extends State<EmployeesScreen> with UIMixin {
|
class _EmployeesScreenState extends State<EmployeesScreen> with UIMixin {
|
||||||
final EmployeesScreenController _employeeController =
|
final EmployeesScreenController _employeeController =
|
||||||
Get.put(EmployeesScreenController());
|
Get.put(EmployeesScreenController());
|
||||||
final PermissionController _permissionController =
|
final PermissionController permissionController =
|
||||||
Get.find<PermissionController>();
|
Get.put(PermissionController());
|
||||||
final TextEditingController _searchController = TextEditingController();
|
final TextEditingController _searchController = TextEditingController();
|
||||||
final RxList<EmployeeModel> _filteredEmployees = <EmployeeModel>[].obs;
|
final RxList<EmployeeModel> _filteredEmployees = <EmployeeModel>[].obs;
|
||||||
final OrganizationController _organizationController =
|
final OrganizationController _organizationController =
|
||||||
@ -248,33 +248,46 @@ class _EmployeesScreenState extends State<EmployeesScreen> with UIMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildFloatingActionButton() {
|
Widget _buildFloatingActionButton() {
|
||||||
if (!_permissionController.hasPermission(Permissions.manageEmployees)) {
|
return Obx(() {
|
||||||
return const SizedBox.shrink();
|
// Show nothing while permissions are loading
|
||||||
}
|
if (permissionController.isLoading.value) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
return InkWell(
|
// Show FAB only if user has Manage Employees permission
|
||||||
onTap: _onAddNewEmployee,
|
final hasPermission =
|
||||||
borderRadius: BorderRadius.circular(28),
|
permissionController.hasPermission(Permissions.manageEmployees);
|
||||||
child: Container(
|
if (!hasPermission) {
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
return const SizedBox.shrink();
|
||||||
decoration: BoxDecoration(
|
}
|
||||||
color: Colors.red,
|
|
||||||
borderRadius: BorderRadius.circular(28),
|
return InkWell(
|
||||||
boxShadow: const [
|
onTap: _onAddNewEmployee,
|
||||||
BoxShadow(
|
borderRadius: BorderRadius.circular(28),
|
||||||
color: Colors.black26, blurRadius: 6, offset: Offset(0, 3))
|
child: Container(
|
||||||
],
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.red,
|
||||||
|
borderRadius: BorderRadius.circular(28),
|
||||||
|
boxShadow: const [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black26,
|
||||||
|
blurRadius: 6,
|
||||||
|
offset: Offset(0, 3),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: const Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.add, color: Colors.white),
|
||||||
|
SizedBox(width: 8),
|
||||||
|
Text('Add New Employee', style: TextStyle(color: Colors.white)),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: const Row(
|
);
|
||||||
mainAxisSize: MainAxisSize.min,
|
});
|
||||||
children: [
|
|
||||||
Icon(Icons.add, color: Colors.white),
|
|
||||||
SizedBox(width: 8),
|
|
||||||
Text('Add New Employee', style: TextStyle(color: Colors.white)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildSearchAndActionRow() {
|
Widget _buildSearchAndActionRow() {
|
||||||
@ -371,60 +384,63 @@ class _EmployeesScreenState extends State<EmployeesScreen> with UIMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPopupMenu() {
|
Widget _buildPopupMenu() {
|
||||||
if (!_permissionController.hasPermission(Permissions.viewAllEmployees)) {
|
return Obx(() {
|
||||||
return const SizedBox.shrink();
|
if (permissionController.isLoading.value ||
|
||||||
}
|
!permissionController.hasPermission(Permissions.viewAllEmployees)) {
|
||||||
|
return const SizedBox.shrink();
|
||||||
|
}
|
||||||
|
|
||||||
return PopupMenuButton<String>(
|
return PopupMenuButton<String>(
|
||||||
icon: Stack(
|
icon: Stack(
|
||||||
clipBehavior: Clip.none,
|
clipBehavior: Clip.none,
|
||||||
children: [
|
children: [
|
||||||
const Icon(Icons.tune, color: Colors.black),
|
const Icon(Icons.tune, color: Colors.black),
|
||||||
Obx(() => _employeeController.isAllEmployeeSelected.value
|
Obx(() => _employeeController.isAllEmployeeSelected.value
|
||||||
? Positioned(
|
? Positioned(
|
||||||
right: -1,
|
right: -1,
|
||||||
top: -1,
|
top: -1,
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 10,
|
width: 10,
|
||||||
height: 10,
|
height: 10,
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
color: Colors.red, shape: BoxShape.circle),
|
color: Colors.red, shape: BoxShape.circle),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onSelected: (value) async {
|
||||||
|
if (value == 'all_employees') {
|
||||||
|
_employeeController.isAllEmployeeSelected.toggle();
|
||||||
|
await _initEmployees();
|
||||||
|
_employeeController.update(['employee_screen_controller']);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
itemBuilder: (_) => [
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: 'all_employees',
|
||||||
|
child: Obx(
|
||||||
|
() => Row(
|
||||||
|
children: [
|
||||||
|
Checkbox(
|
||||||
|
value: _employeeController.isAllEmployeeSelected.value,
|
||||||
|
onChanged: (_) => Navigator.pop(context, 'all_employees'),
|
||||||
|
checkColor: Colors.white,
|
||||||
|
activeColor: Colors.blueAccent,
|
||||||
|
side: const BorderSide(color: Colors.black, width: 1.5),
|
||||||
|
fillColor: MaterialStateProperty.resolveWith<Color>(
|
||||||
|
(states) => states.contains(MaterialState.selected)
|
||||||
|
? Colors.blueAccent
|
||||||
|
: Colors.white),
|
||||||
),
|
),
|
||||||
)
|
const Text('All Employees'),
|
||||||
: const SizedBox.shrink()),
|
],
|
||||||
],
|
),
|
||||||
),
|
|
||||||
onSelected: (value) async {
|
|
||||||
if (value == 'all_employees') {
|
|
||||||
_employeeController.isAllEmployeeSelected.toggle();
|
|
||||||
await _initEmployees();
|
|
||||||
_employeeController.update(['employee_screen_controller']);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
itemBuilder: (_) => [
|
|
||||||
PopupMenuItem<String>(
|
|
||||||
value: 'all_employees',
|
|
||||||
child: Obx(
|
|
||||||
() => Row(
|
|
||||||
children: [
|
|
||||||
Checkbox(
|
|
||||||
value: _employeeController.isAllEmployeeSelected.value,
|
|
||||||
onChanged: (_) => Navigator.pop(context, 'all_employees'),
|
|
||||||
checkColor: Colors.white,
|
|
||||||
activeColor: Colors.blueAccent,
|
|
||||||
side: const BorderSide(color: Colors.black, width: 1.5),
|
|
||||||
fillColor: MaterialStateProperty.resolveWith<Color>(
|
|
||||||
(states) => states.contains(MaterialState.selected)
|
|
||||||
? Colors.blueAccent
|
|
||||||
: Colors.white),
|
|
||||||
),
|
|
||||||
const Text('All Employees'),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildEmployeeList() {
|
Widget _buildEmployeeList() {
|
||||||
|
@ -33,7 +33,7 @@ class ExpenseDetailScreen extends StatefulWidget {
|
|||||||
class _ExpenseDetailScreenState extends State<ExpenseDetailScreen> {
|
class _ExpenseDetailScreenState extends State<ExpenseDetailScreen> {
|
||||||
final controller = Get.put(ExpenseDetailController());
|
final controller = Get.put(ExpenseDetailController());
|
||||||
final projectController = Get.find<ProjectController>();
|
final projectController = Get.find<ProjectController>();
|
||||||
final permissionController = Get.find<PermissionController>();
|
final permissionController = Get.put(PermissionController());
|
||||||
|
|
||||||
EmployeeInfo? employeeInfo;
|
EmployeeInfo? employeeInfo;
|
||||||
final RxBool canSubmit = false.obs;
|
final RxBool canSubmit = false.obs;
|
||||||
|
@ -26,7 +26,7 @@ class _ExpenseMainScreenState extends State<ExpenseMainScreen>
|
|||||||
final searchController = TextEditingController();
|
final searchController = TextEditingController();
|
||||||
final expenseController = Get.put(ExpenseController());
|
final expenseController = Get.put(ExpenseController());
|
||||||
final projectController = Get.find<ProjectController>();
|
final projectController = Get.find<ProjectController>();
|
||||||
final permissionController = Get.find<PermissionController>();
|
final permissionController = Get.put(PermissionController());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -81,7 +81,7 @@ class _ExpenseMainScreenState extends State<ExpenseMainScreen>
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
@ -106,7 +106,7 @@ Widget build(BuildContext context) {
|
|||||||
// ---------------- Gray background for rest ----------------
|
// ---------------- Gray background for rest ----------------
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Container(
|
child: Container(
|
||||||
color: Colors.grey[100], // Light gray background
|
color: Colors.grey[100],
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
// ---------------- Search ----------------
|
// ---------------- Search ----------------
|
||||||
@ -137,14 +137,24 @@ Widget build(BuildContext context) {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
floatingActionButton:
|
// ✅ FAB reacts only to upload permission
|
||||||
permissionController.hasPermission(Permissions.expenseUpload)
|
floatingActionButton: Obx(() {
|
||||||
? FloatingActionButton(
|
// Show loader or hide FAB while permissions are loading
|
||||||
backgroundColor: Colors.red,
|
if (permissionController.permissions.isEmpty) {
|
||||||
onPressed: showAddExpenseBottomSheet,
|
return const SizedBox.shrink();
|
||||||
child: const Icon(Icons.add, color: Colors.white),
|
}
|
||||||
)
|
|
||||||
: null,
|
final canUpload =
|
||||||
|
permissionController.hasPermission(Permissions.expenseUpload);
|
||||||
|
|
||||||
|
return canUpload
|
||||||
|
? FloatingActionButton(
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
onPressed: showAddExpenseBottomSheet,
|
||||||
|
child: const Icon(Icons.add, color: Colors.white),
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink();
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ class _LeftBarState extends State<LeftBar>
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.only(top: 50),
|
padding: EdgeInsets.only(top: 50),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () => Get.toNamed('/home'),
|
onTap: () => Get.toNamed('/dashboard'),
|
||||||
child: Image.asset(
|
child: Image.asset(
|
||||||
(ThemeCustomizer.instance.theme == ThemeMode.light
|
(ThemeCustomizer.instance.theme == ThemeMode.light
|
||||||
? (widget.isCondensed
|
? (widget.isCondensed
|
||||||
|
@ -9,10 +9,12 @@ import 'package:marco/helpers/widgets/my_text.dart';
|
|||||||
import 'package:marco/helpers/widgets/avatar.dart';
|
import 'package:marco/helpers/widgets/avatar.dart';
|
||||||
import 'package:marco/model/employees/employee_info.dart';
|
import 'package:marco/model/employees/employee_info.dart';
|
||||||
import 'package:marco/controller/auth/mpin_controller.dart';
|
import 'package:marco/controller/auth/mpin_controller.dart';
|
||||||
import 'package:marco/controller/tenant/tenant_selection_controller.dart';
|
|
||||||
import 'package:marco/view/employees/employee_profile_screen.dart';
|
import 'package:marco/view/employees/employee_profile_screen.dart';
|
||||||
import 'package:marco/helpers/services/tenant_service.dart';
|
import 'package:marco/helpers/services/tenant_service.dart';
|
||||||
import 'package:marco/view/tenant/tenant_selection_screen.dart';
|
import 'package:marco/view/tenant/tenant_selection_screen.dart';
|
||||||
|
import 'package:marco/controller/tenant/tenant_switch_controller.dart';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UserProfileBar extends StatefulWidget {
|
class UserProfileBar extends StatefulWidget {
|
||||||
final bool isCondensed;
|
final bool isCondensed;
|
||||||
@ -27,21 +29,13 @@ class _UserProfileBarState extends State<UserProfileBar>
|
|||||||
late EmployeeInfo employeeInfo;
|
late EmployeeInfo employeeInfo;
|
||||||
bool _isLoading = true;
|
bool _isLoading = true;
|
||||||
bool hasMpin = true;
|
bool hasMpin = true;
|
||||||
late final TenantSelectionController _tenantController;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_tenantController = Get.put(TenantSelectionController());
|
|
||||||
_initData();
|
_initData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
Get.delete<TenantSelectionController>();
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _initData() async {
|
Future<void> _initData() async {
|
||||||
employeeInfo = LocalStorage.getEmployeeInfo()!;
|
employeeInfo = LocalStorage.getEmployeeInfo()!;
|
||||||
hasMpin = await LocalStorage.getIsMpin();
|
hasMpin = await LocalStorage.getIsMpin();
|
||||||
@ -122,93 +116,101 @@ class _UserProfileBarState extends State<UserProfileBar>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Row widget to switch tenant with popup menu (button only)
|
/// Row widget to switch tenant with popup menu (button only)
|
||||||
Widget _switchTenantRow() {
|
/// Row widget to switch tenant with popup menu (button only)
|
||||||
return Padding(
|
Widget _switchTenantRow() {
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
// Use the dedicated switch controller
|
||||||
child: Obx(() {
|
final TenantSwitchController tenantSwitchController =
|
||||||
if (_tenantController.isLoading.value) return _loadingTenantContainer();
|
Get.put(TenantSwitchController());
|
||||||
|
|
||||||
final tenants = _tenantController.tenants;
|
return Padding(
|
||||||
if (tenants.isEmpty) return _noTenantContainer();
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||||
|
child: Obx(() {
|
||||||
|
if (tenantSwitchController.isLoading.value) {
|
||||||
|
return _loadingTenantContainer();
|
||||||
|
}
|
||||||
|
|
||||||
final selectedTenant = TenantService.currentTenant;
|
final tenants = tenantSwitchController.tenants;
|
||||||
|
if (tenants.isEmpty) return _noTenantContainer();
|
||||||
|
|
||||||
// Sort tenants: selected tenant first
|
final selectedTenant = TenantService.currentTenant;
|
||||||
final sortedTenants = List.of(tenants);
|
|
||||||
if (selectedTenant != null) {
|
|
||||||
sortedTenants.sort((a, b) {
|
|
||||||
if (a.id == selectedTenant.id) return -1;
|
|
||||||
if (b.id == selectedTenant.id) return 1;
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return PopupMenuButton<String>(
|
// Sort tenants: selected tenant first
|
||||||
onSelected: (tenantId) =>
|
final sortedTenants = List.of(tenants);
|
||||||
_tenantController.onTenantSelected(tenantId),
|
if (selectedTenant != null) {
|
||||||
itemBuilder: (_) => sortedTenants.map((tenant) {
|
sortedTenants.sort((a, b) {
|
||||||
return PopupMenuItem(
|
if (a.id == selectedTenant.id) return -1;
|
||||||
value: tenant.id,
|
if (b.id == selectedTenant.id) return 1;
|
||||||
child: Row(
|
return 0;
|
||||||
children: [
|
});
|
||||||
ClipRRect(
|
}
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
child: Container(
|
return PopupMenuButton<String>(
|
||||||
width: 20,
|
onSelected: (tenantId) =>
|
||||||
height: 20,
|
tenantSwitchController.switchTenant(tenantId),
|
||||||
color: Colors.grey.shade200,
|
itemBuilder: (_) => sortedTenants.map((tenant) {
|
||||||
child: TenantLogo(logoImage: tenant.logoImage),
|
return PopupMenuItem(
|
||||||
),
|
value: tenant.id,
|
||||||
),
|
|
||||||
const SizedBox(width: 10),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
tenant.name,
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: TextStyle(
|
|
||||||
fontWeight: tenant.id == selectedTenant?.id
|
|
||||||
? FontWeight.bold
|
|
||||||
: FontWeight.w600,
|
|
||||||
color: tenant.id == selectedTenant?.id
|
|
||||||
? Colors.blueAccent
|
|
||||||
: Colors.black87,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (tenant.id == selectedTenant?.id)
|
|
||||||
const Icon(Icons.check_circle,
|
|
||||||
color: Colors.blueAccent, size: 18),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
children: [
|
||||||
Icon(Icons.swap_horiz, color: Colors.blue.shade600),
|
ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
child: Container(
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
color: Colors.grey.shade200,
|
||||||
|
child: TenantLogo(logoImage: tenant.logoImage),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Padding(
|
child: Text(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
tenant.name,
|
||||||
child: Text(
|
maxLines: 1,
|
||||||
"Switch Organization",
|
overflow: TextOverflow.ellipsis,
|
||||||
maxLines: 1,
|
style: TextStyle(
|
||||||
overflow: TextOverflow.ellipsis,
|
fontWeight: tenant.id == selectedTenant?.id
|
||||||
style: TextStyle(
|
? FontWeight.bold
|
||||||
color: Colors.blue, fontWeight: FontWeight.bold),
|
: FontWeight.w600,
|
||||||
|
color: tenant.id == selectedTenant?.id
|
||||||
|
? Colors.blueAccent
|
||||||
|
: Colors.black87,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Icon(Icons.arrow_drop_down, color: Colors.blue.shade600),
|
if (tenant.id == selectedTenant?.id)
|
||||||
|
const Icon(Icons.check_circle,
|
||||||
|
color: Colors.blueAccent, size: 18),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.swap_horiz, color: Colors.blue.shade600),
|
||||||
|
Expanded(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||||
|
child: Text(
|
||||||
|
"Switch Organization",
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.blue, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Icon(Icons.arrow_drop_down, color: Colors.blue.shade600),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
}),
|
);
|
||||||
);
|
}),
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Widget _loadingTenantContainer() => Container(
|
Widget _loadingTenantContainer() => Container(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
|
||||||
|
@ -5,7 +5,6 @@ import 'package:provider/provider.dart';
|
|||||||
|
|
||||||
import 'package:marco/helpers/services/app_logger.dart';
|
import 'package:marco/helpers/services/app_logger.dart';
|
||||||
import 'package:marco/helpers/extensions/app_localization_delegate.dart';
|
import 'package:marco/helpers/extensions/app_localization_delegate.dart';
|
||||||
import 'package:marco/helpers/services/auth_service.dart';
|
|
||||||
import 'package:marco/helpers/services/localizations/language.dart';
|
import 'package:marco/helpers/services/localizations/language.dart';
|
||||||
import 'package:marco/helpers/services/navigation_services.dart';
|
import 'package:marco/helpers/services/navigation_services.dart';
|
||||||
import 'package:marco/helpers/services/storage/local_storage.dart';
|
import 'package:marco/helpers/services/storage/local_storage.dart';
|
||||||
@ -19,22 +18,21 @@ class MyApp extends StatelessWidget {
|
|||||||
|
|
||||||
Future<String> _getInitialRoute() async {
|
Future<String> _getInitialRoute() async {
|
||||||
try {
|
try {
|
||||||
if (!AuthService.isLoggedIn) {
|
final token = LocalStorage.getJwtToken();
|
||||||
|
if (token == null || token.isEmpty) {
|
||||||
logSafe("User not logged in. Routing to /auth/login-option");
|
logSafe("User not logged in. Routing to /auth/login-option");
|
||||||
return "/auth/login-option";
|
return "/auth/login-option";
|
||||||
}
|
}
|
||||||
|
|
||||||
final bool hasMpin = LocalStorage.getIsMpin();
|
final bool hasMpin = LocalStorage.getIsMpin();
|
||||||
logSafe("MPIN enabled: $hasMpin", );
|
|
||||||
|
|
||||||
if (hasMpin) {
|
if (hasMpin) {
|
||||||
await LocalStorage.setBool("mpin_verified", false);
|
await LocalStorage.setBool("mpin_verified", false);
|
||||||
logSafe("Routing to /auth/mpin-auth and setting mpin_verified to false");
|
logSafe("Routing to /auth/mpin-auth");
|
||||||
return "/auth/mpin-auth";
|
return "/auth/mpin-auth";
|
||||||
} else {
|
|
||||||
logSafe("MPIN not enabled. Routing to /dashboard");
|
|
||||||
return "/dashboard";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logSafe("No MPIN. Routing to /dashboard");
|
||||||
|
return "/dashboard";
|
||||||
} catch (e, stacktrace) {
|
} catch (e, stacktrace) {
|
||||||
logSafe("Error determining initial route",
|
logSafe("Error determining initial route",
|
||||||
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
level: LogLevel.error, error: e, stackTrace: stacktrace);
|
||||||
|
120
lib/view/splash_screen.dart
Normal file
120
lib/view/splash_screen.dart
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:marco/images.dart';
|
||||||
|
|
||||||
|
class SplashScreen extends StatefulWidget {
|
||||||
|
final String? message;
|
||||||
|
final double? logoSize;
|
||||||
|
final Color? backgroundColor;
|
||||||
|
|
||||||
|
const SplashScreen({
|
||||||
|
super.key,
|
||||||
|
this.message,
|
||||||
|
this.logoSize = 120,
|
||||||
|
this.backgroundColor = Colors.white,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SplashScreen> createState() => _SplashScreenState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SplashScreenState extends State<SplashScreen>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
|
late AnimationController _controller;
|
||||||
|
late Animation<double> _animation;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
_controller = AnimationController(
|
||||||
|
duration: const Duration(seconds: 1),
|
||||||
|
vsync: this,
|
||||||
|
)..repeat(reverse: true);
|
||||||
|
|
||||||
|
_animation = Tween<double>(begin: 0.0, end: 8.0).animate(
|
||||||
|
CurvedAnimation(parent: _controller, curve: Curves.easeInOut),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildAnimatedDots() {
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: List.generate(3, (index) {
|
||||||
|
return AnimatedBuilder(
|
||||||
|
animation: _animation,
|
||||||
|
builder: (context, child) {
|
||||||
|
double opacity;
|
||||||
|
if (index == 0) {
|
||||||
|
opacity = (0.3 + _animation.value / 8).clamp(0.0, 1.0);
|
||||||
|
} else if (index == 1) {
|
||||||
|
opacity = (0.3 + (_animation.value / 8)).clamp(0.0, 1.0);
|
||||||
|
} else {
|
||||||
|
opacity = (0.3 + (1 - _animation.value / 8)).clamp(0.0, 1.0);
|
||||||
|
}
|
||||||
|
return Container(
|
||||||
|
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||||
|
width: 10,
|
||||||
|
height: 10,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.blueAccent.withOpacity(opacity),
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: widget.backgroundColor,
|
||||||
|
body: SafeArea(
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
// Logo with slight bounce animation
|
||||||
|
ScaleTransition(
|
||||||
|
scale: Tween(begin: 0.8, end: 1.0).animate(
|
||||||
|
CurvedAnimation(
|
||||||
|
parent: _controller,
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: SizedBox(
|
||||||
|
width: widget.logoSize,
|
||||||
|
height: widget.logoSize,
|
||||||
|
child: Image.asset(Images.logoDark),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
// Text message
|
||||||
|
if (widget.message != null)
|
||||||
|
Text(
|
||||||
|
widget.message!,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.black87,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 30),
|
||||||
|
// Animated loading dots
|
||||||
|
_buildAnimatedDots(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -41,7 +41,7 @@ class _DailyProgressReportScreenState extends State<DailyProgressReportScreen>
|
|||||||
final DailyTaskController dailyTaskController =
|
final DailyTaskController dailyTaskController =
|
||||||
Get.put(DailyTaskController());
|
Get.put(DailyTaskController());
|
||||||
final PermissionController permissionController =
|
final PermissionController permissionController =
|
||||||
Get.find<PermissionController>();
|
Get.put(PermissionController());
|
||||||
final ProjectController projectController = Get.find<ProjectController>();
|
final ProjectController projectController = Get.find<ProjectController>();
|
||||||
final ServiceController serviceController = Get.put(ServiceController());
|
final ServiceController serviceController = Get.put(ServiceController());
|
||||||
final ScrollController _scrollController = ScrollController();
|
final ScrollController _scrollController = ScrollController();
|
||||||
|
@ -6,6 +6,7 @@ import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
|
|||||||
import 'package:marco/helpers/widgets/my_text.dart';
|
import 'package:marco/helpers/widgets/my_text.dart';
|
||||||
import 'package:marco/images.dart';
|
import 'package:marco/images.dart';
|
||||||
import 'package:marco/controller/tenant/tenant_selection_controller.dart';
|
import 'package:marco/controller/tenant/tenant_selection_controller.dart';
|
||||||
|
import 'package:marco/view/splash_screen.dart';
|
||||||
|
|
||||||
class TenantSelectionScreen extends StatefulWidget {
|
class TenantSelectionScreen extends StatefulWidget {
|
||||||
const TenantSelectionScreen({super.key});
|
const TenantSelectionScreen({super.key});
|
||||||
@ -20,24 +21,23 @@ class _TenantSelectionScreenState extends State<TenantSelectionScreen>
|
|||||||
late final AnimationController _logoAnimController;
|
late final AnimationController _logoAnimController;
|
||||||
late final Animation<double> _logoAnimation;
|
late final Animation<double> _logoAnimation;
|
||||||
final bool _isBetaEnvironment = ApiEndpoints.baseUrl.contains("stage");
|
final bool _isBetaEnvironment = ApiEndpoints.baseUrl.contains("stage");
|
||||||
bool _isLoading = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_controller = Get.put(TenantSelectionController());
|
_controller = Get.put(TenantSelectionController());
|
||||||
|
|
||||||
_logoAnimController = AnimationController(
|
_logoAnimController = AnimationController(
|
||||||
vsync: this,
|
vsync: this,
|
||||||
duration: const Duration(milliseconds: 800),
|
duration: const Duration(milliseconds: 800),
|
||||||
);
|
);
|
||||||
|
|
||||||
_logoAnimation = CurvedAnimation(
|
_logoAnimation = CurvedAnimation(
|
||||||
parent: _logoAnimController,
|
parent: _logoAnimController,
|
||||||
curve: Curves.easeOutBack,
|
curve: Curves.easeOutBack,
|
||||||
);
|
);
|
||||||
_logoAnimController.forward();
|
|
||||||
|
|
||||||
// 🔥 Tell controller this is tenant selection screen
|
_logoAnimController.forward();
|
||||||
_controller.loadTenants(fromTenantSelectionScreen: true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -48,61 +48,66 @@ class _TenantSelectionScreenState extends State<TenantSelectionScreen>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onTenantSelected(String tenantId) async {
|
Future<void> _onTenantSelected(String tenantId) async {
|
||||||
setState(() => _isLoading = true);
|
|
||||||
await _controller.onTenantSelected(tenantId);
|
await _controller.onTenantSelected(tenantId);
|
||||||
setState(() => _isLoading = false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Obx(() {
|
||||||
body: Stack(
|
// Splash screen for auto-selection
|
||||||
children: [
|
if (_controller.isAutoSelecting.value) {
|
||||||
_RedWaveBackground(brandRed: contentTheme.brandRed),
|
return const SplashScreen();
|
||||||
SafeArea(
|
}
|
||||||
child: Center(
|
|
||||||
child: Column(
|
return Scaffold(
|
||||||
children: [
|
body: Stack(
|
||||||
const SizedBox(height: 24),
|
children: [
|
||||||
_AnimatedLogo(animation: _logoAnimation),
|
_RedWaveBackground(brandRed: contentTheme.brandRed),
|
||||||
const SizedBox(height: 8),
|
SafeArea(
|
||||||
Expanded(
|
child: Center(
|
||||||
child: SingleChildScrollView(
|
child: Column(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
children: [
|
||||||
child: Center(
|
const SizedBox(height: 24),
|
||||||
child: ConstrainedBox(
|
_AnimatedLogo(animation: _logoAnimation),
|
||||||
constraints: const BoxConstraints(maxWidth: 420),
|
const SizedBox(height: 8),
|
||||||
child: Column(
|
Expanded(
|
||||||
children: [
|
child: SingleChildScrollView(
|
||||||
const SizedBox(height: 12),
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
const _WelcomeTexts(),
|
child: Center(
|
||||||
if (_isBetaEnvironment) ...[
|
child: ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 420),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
const _BetaBadge(),
|
const _WelcomeTexts(),
|
||||||
|
if (_isBetaEnvironment) ...[
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
const _BetaBadge(),
|
||||||
|
],
|
||||||
|
const SizedBox(height: 36),
|
||||||
|
TenantCardList(
|
||||||
|
controller: _controller,
|
||||||
|
isLoading: _controller.isLoading.value,
|
||||||
|
onTenantSelected: _onTenantSelected,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
const SizedBox(height: 36),
|
),
|
||||||
// Tenant list directly reacts to controller
|
|
||||||
TenantCardList(
|
|
||||||
controller: _controller,
|
|
||||||
isLoading: _isLoading,
|
|
||||||
onTenantSelected: _onTenantSelected,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
],
|
),
|
||||||
),
|
);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Animated Logo Widget
|
||||||
class _AnimatedLogo extends StatelessWidget {
|
class _AnimatedLogo extends StatelessWidget {
|
||||||
final Animation<double> animation;
|
final Animation<double> animation;
|
||||||
const _AnimatedLogo({required this.animation});
|
const _AnimatedLogo({required this.animation});
|
||||||
@ -132,6 +137,7 @@ class _AnimatedLogo extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Welcome Texts
|
||||||
class _WelcomeTexts extends StatelessWidget {
|
class _WelcomeTexts extends StatelessWidget {
|
||||||
const _WelcomeTexts();
|
const _WelcomeTexts();
|
||||||
|
|
||||||
@ -148,7 +154,7 @@ class _WelcomeTexts extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
MyText(
|
MyText(
|
||||||
"Please select which dashboard you want to explore!.",
|
"Please select which dashboard you want to explore!",
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: Colors.black54,
|
color: Colors.black54,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
@ -158,6 +164,7 @@ class _WelcomeTexts extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Beta Badge
|
||||||
class _BetaBadge extends StatelessWidget {
|
class _BetaBadge extends StatelessWidget {
|
||||||
const _BetaBadge();
|
const _BetaBadge();
|
||||||
|
|
||||||
@ -179,6 +186,7 @@ class _BetaBadge extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tenant Card List
|
||||||
class TenantCardList extends StatelessWidget {
|
class TenantCardList extends StatelessWidget {
|
||||||
final TenantSelectionController controller;
|
final TenantSelectionController controller;
|
||||||
final bool isLoading;
|
final bool isLoading;
|
||||||
@ -194,10 +202,9 @@ class TenantCardList extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
if (controller.isLoading.value || isLoading) {
|
if (controller.isLoading.value || isLoading) {
|
||||||
return const Center(
|
return const Center(child: CircularProgressIndicator(strokeWidth: 2));
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controller.tenants.isEmpty) {
|
if (controller.tenants.isEmpty) {
|
||||||
return Center(
|
return Center(
|
||||||
child: MyText(
|
child: MyText(
|
||||||
@ -208,39 +215,35 @@ class TenantCardList extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (controller.tenants.length == 1) {
|
|
||||||
return const SizedBox.shrink();
|
return Column(
|
||||||
}
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
return SingleChildScrollView(
|
children: [
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 24),
|
...controller.tenants.map(
|
||||||
child: Column(
|
(tenant) => _TenantCard(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
tenant: tenant,
|
||||||
children: [
|
onTap: () => onTenantSelected(tenant.id),
|
||||||
...controller.tenants.map(
|
|
||||||
(tenant) => _TenantCard(
|
|
||||||
tenant: tenant,
|
|
||||||
onTap: () => onTenantSelected(tenant.id),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
),
|
||||||
TextButton.icon(
|
const SizedBox(height: 16),
|
||||||
onPressed: () => Get.back(),
|
TextButton.icon(
|
||||||
icon: const Icon(Icons.arrow_back,
|
onPressed: () => Get.back(),
|
||||||
size: 20, color: Colors.redAccent),
|
icon:
|
||||||
label: MyText(
|
const Icon(Icons.arrow_back, size: 20, color: Colors.redAccent),
|
||||||
'Back to Login',
|
label: MyText(
|
||||||
color: Colors.red,
|
'Back to Login',
|
||||||
fontWeight: 600,
|
color: Colors.red,
|
||||||
fontSize: 14,
|
fontWeight: 600,
|
||||||
),
|
fontSize: 14,
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Single Tenant Card
|
||||||
class _TenantCard extends StatelessWidget {
|
class _TenantCard extends StatelessWidget {
|
||||||
final dynamic tenant;
|
final dynamic tenant;
|
||||||
final VoidCallback onTap;
|
final VoidCallback onTap;
|
||||||
@ -253,9 +256,7 @@ class _TenantCard extends StatelessWidget {
|
|||||||
borderRadius: BorderRadius.circular(5),
|
borderRadius: BorderRadius.circular(5),
|
||||||
child: Card(
|
child: Card(
|
||||||
elevation: 3,
|
elevation: 3,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
|
||||||
borderRadius: BorderRadius.circular(5),
|
|
||||||
),
|
|
||||||
margin: const EdgeInsets.only(bottom: 20),
|
margin: const EdgeInsets.only(bottom: 20),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
@ -291,11 +292,7 @@ class _TenantCard extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Icon(
|
const Icon(Icons.arrow_forward_ios, size: 24, color: Colors.red),
|
||||||
Icons.arrow_forward_ios,
|
|
||||||
size: 24,
|
|
||||||
color: Colors.red,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -304,6 +301,7 @@ class _TenantCard extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tenant Logo (supports base64 and URL)
|
||||||
class TenantLogo extends StatelessWidget {
|
class TenantLogo extends StatelessWidget {
|
||||||
final String? logoImage;
|
final String? logoImage;
|
||||||
const TenantLogo({required this.logoImage});
|
const TenantLogo({required this.logoImage});
|
||||||
@ -311,9 +309,7 @@ class TenantLogo extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (logoImage == null || logoImage!.isEmpty) {
|
if (logoImage == null || logoImage!.isEmpty) {
|
||||||
return Center(
|
return Center(child: Icon(Icons.business, color: Colors.grey.shade600));
|
||||||
child: Icon(Icons.business, color: Colors.grey.shade600),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (logoImage!.startsWith("data:image")) {
|
if (logoImage!.startsWith("data:image")) {
|
||||||
try {
|
try {
|
||||||
@ -321,9 +317,7 @@ class TenantLogo extends StatelessWidget {
|
|||||||
final bytes = base64Decode(base64Str);
|
final bytes = base64Decode(base64Str);
|
||||||
return Image.memory(bytes, fit: BoxFit.cover);
|
return Image.memory(bytes, fit: BoxFit.cover);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
return Center(
|
return Center(child: Icon(Icons.business, color: Colors.grey.shade600));
|
||||||
child: Icon(Icons.business, color: Colors.grey.shade600),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Image.network(
|
return Image.network(
|
||||||
@ -337,6 +331,7 @@ class TenantLogo extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Red Wave Background
|
||||||
class _RedWaveBackground extends StatelessWidget {
|
class _RedWaveBackground extends StatelessWidget {
|
||||||
final Color brandRed;
|
final Color brandRed;
|
||||||
const _RedWaveBackground({required this.brandRed});
|
const _RedWaveBackground({required this.brandRed});
|
||||||
@ -352,7 +347,6 @@ class _RedWaveBackground extends StatelessWidget {
|
|||||||
|
|
||||||
class _WavePainter extends CustomPainter {
|
class _WavePainter extends CustomPainter {
|
||||||
final Color brandRed;
|
final Color brandRed;
|
||||||
|
|
||||||
_WavePainter(this.brandRed);
|
_WavePainter(this.brandRed);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user