diff --git a/lib/customAppBar/customAppBar.dart b/lib/customAppBar/customAppBar.dart index 3834421..42262d1 100644 --- a/lib/customAppBar/customAppBar.dart +++ b/lib/customAppBar/customAppBar.dart @@ -14,7 +14,8 @@ class CustomAppBar extends StatefulWidget implements PreferredSizeWidget { } class _CustomAppBarState extends State { - bool showBackToHR = true; + bool showBackToHR = false; + // bool isLoading = true; // Add a loading state // bool hideInactiveStatus = true; @override @@ -27,10 +28,15 @@ class _CustomAppBarState extends State { final prefs = await SharedPreferences.getInstance(); final String? hrtoken = prefs.getString('hrtoken'); final String? token = prefs.getString('token'); + // showBackToHR = prefs.getBool('showBackToHR')!; setState(() { - showBackToHR = (hrtoken != null && hrtoken.isNotEmpty) && - (token != null && token.isNotEmpty); + showBackToHR = prefs.getBool('showBackToHR')!; + // showBackToHR = (hrtoken != null && hrtoken.isNotEmpty) && + // (token != null && token.isNotEmpty); + // print((hrtoken != null && hrtoken.isNotEmpty)); + // print((token != null && token.isNotEmpty)); + // print('showBackToHR $showBackToHR'); // hideInactiveStatus = token != null && token.isNotEmpty; }); @@ -41,6 +47,7 @@ class _CustomAppBarState extends State { final String? hrtoken = prefs.getString('hrtoken'); if (hrtoken != null && hrtoken.isNotEmpty) { + prefs.setBool('showBackToHR', false); prefs.remove('token'); Navigator.pushNamed(context, 'hrDashboard'); } else { @@ -71,7 +78,12 @@ class _CustomAppBarState extends State { @override Widget build(BuildContext context) { final sw = MediaQuery.of(context).size.width; - + // if (isLoading) { + // // Show a loading indicator or a placeholder AppBar while waiting + // return AppBar( + // title: Text('Loading...'), + // ); + // } return Scaffold( backgroundColor: Color(0xFFFFFCE5), // Set background color for AppBar appBar: PreferredSize( diff --git a/lib/empDetails.dart b/lib/empDetails.dart index 958b8ab..702de24 100644 --- a/lib/empDetails.dart +++ b/lib/empDetails.dart @@ -125,18 +125,19 @@ class _empDetailsState extends State { final SharedPreferences prefs = await SharedPreferences.getInstance(); if (prefs.containsKey('hrtoken')) { String? getHrToken = prefs.getString('hrtoken'); + String? empID = prefs.getString('employee_id'); Map? decodedToken = Jwt.parseJwt(getHrToken!); print(decodedToken); hrPrimaryId = decodedToken['id']; print('hrPrimaryId'); print(hrPrimaryId); - _hrLoadToken(); + _hrLoadToken(empID); } else { _loadToken(); } } - Future _hrLoadToken() async { + Future _hrLoadToken(empID) async { print('_hrLoadToken'); final SharedPreferences prefs = await SharedPreferences.getInstance(); prefs.setString('fromHrLoginMobileNo', mobileNumber); @@ -148,8 +149,9 @@ class _empDetailsState extends State { Uri.parse(Environment.apiUrl + 'getVerifiedUserData'), body: json.encode({ 'mobile_number': mobileNumber, - 'otp': 0, - 'login_by_hr': login_by_hr + 'otp_verification': 0, + 'login_by_hr': login_by_hr, + 'employee_id': empID }), headers: { HttpHeaders.contentTypeHeader: 'application/json', @@ -165,11 +167,13 @@ class _empDetailsState extends State { if (status == 'success') { print(status); // final SharedPreferences prefs = await SharedPreferences.getInstance(); - prefs.setString('token', data['data']); + setState(() { + prefs.setString('token', data['data']); + }); // Decode the JWT token received from the API response Map? decodedToken = Jwt.parseJwt(data['data']); - print(decodedToken); + print('decodedTokenssss $decodedToken'); empClientBranchId = decodedToken['client_branch_id']; prefs.setString('empClientBranchId', empClientBranchId); print(empClientBranchId); @@ -186,9 +190,10 @@ class _empDetailsState extends State { // Redirect to another page final token = prefs.getString('token'); + print('final $token'); if (token != null && token.isNotEmpty) { // ToastHelper.showSuccessToast(context, 'Successfully Login'); - getSelfEmployeeProfile(); + await getSelfEmployeeProfile(token); if (prefs.containsKey('clientLogo') && prefs.containsKey('clientName')) { clientLogo = prefs.getString('clientLogo'); @@ -196,8 +201,8 @@ class _empDetailsState extends State { } else { getClientLogoAndDetails(); } - getGpaEmpPolicyDetails(empPrimaryId); - getGmcEmpPolicyDetails(empPrimaryId); + await getGpaEmpPolicyDetails(empPrimaryId); + await getGmcEmpPolicyDetails(empPrimaryId); fetchRelationshipList(); // Navigator.pushReplacementNamed(context, 'empDetails', // arguments: {'mobile': ''}); @@ -248,7 +253,7 @@ class _empDetailsState extends State { // print(empPrimaryId); // Call the API when the page enters - getSelfEmployeeProfile(); + getSelfEmployeeProfile(''); if (prefs.containsKey('clientLogo') && prefs.containsKey('clientName')) { clientLogo = prefs.getString('clientLogo'); clientName = prefs.getString('clientName'); @@ -309,7 +314,7 @@ class _empDetailsState extends State { } } - Future getSelfEmployeeProfile() async { + Future getSelfEmployeeProfile(token) async { try { if (client_id == null || empCodeString == null || @@ -317,7 +322,7 @@ class _empDetailsState extends State { return; } final response = await apiService.getSelfEmployeeProfileToApi( - client_id!, empCodeString!, empClientBranchId!); + token, client_id!, empCodeString!, empClientBranchId!); if (response['status'] == 'success') { if (response.containsKey('data')) { diff --git a/lib/empReview.dart b/lib/empReview.dart index 17d1a68..23d0588 100644 --- a/lib/empReview.dart +++ b/lib/empReview.dart @@ -745,8 +745,18 @@ class _empReviewDetailsState extends State { color: Color(0xFFE26728), ), ), - onPressed: () { - Navigator.popAndPushNamed(context, 'empDetails'); + onPressed: () async { + final SharedPreferences prefs = + await SharedPreferences.getInstance(); + final String? fromHrLoginMobileNo = + prefs.getString('fromHrLoginMobileNo'); + if (fromHrLoginMobileNo != null && + fromHrLoginMobileNo.isNotEmpty) { + Navigator.pushNamed(context, 'empDetails', + arguments: {'mobile': fromHrLoginMobileNo}); + } else { + Navigator.popAndPushNamed(context, 'empDetails'); + } }, ), ], diff --git a/lib/hrPolicyDetails.dart b/lib/hrPolicyDetails.dart index 4fc9131..e485c32 100644 --- a/lib/hrPolicyDetails.dart +++ b/lib/hrPolicyDetails.dart @@ -106,7 +106,7 @@ class _HrPolicyDetailsState extends State String int_inception_type = argumentsData['inception_type']; inceptionType = int.parse(int_inception_type); getEmployeeAndDependence(clientId, clientPolicyId); - } else if (argumentsData['type'] == 'SI TopUp') { + } else if (argumentsData['type'] == 'GMC - Parents') { _isLoading = true; clientPolicyId = argumentsData['client_policy_id']; clientId = argumentsData['client_id']; @@ -115,7 +115,16 @@ class _HrPolicyDetailsState extends State String int_inception_type = argumentsData['inception_type']; inceptionType = int.parse(int_inception_type); getEmployeeAndDependence(clientId, clientPolicyId); - } else if (argumentsData['type'] == 'Dependent AddOn') { + } else if (argumentsData['type'] == 'GMC - Topup') { + _isLoading = true; + clientPolicyId = argumentsData['client_policy_id']; + clientId = argumentsData['client_id']; + policyType = argumentsData['type']; + policyName = argumentsData['policy_name']; + String int_inception_type = argumentsData['inception_type']; + inceptionType = int.parse(int_inception_type); + getEmployeeAndDependence(clientId, clientPolicyId); + } else if (argumentsData['type'] == 'GMC - Topup(Parents)') { _isLoading = true; clientPolicyId = argumentsData['client_policy_id']; clientId = argumentsData['client_id']; @@ -818,8 +827,11 @@ class _DependenceDataSource0 extends DataTableSource { @override int get selectedRowCount => 0; - void _navigateToAnotherPage(row) { + void _navigateToAnotherPage(row) async { print(row['mobile']); + final SharedPreferences prefs = await SharedPreferences.getInstance(); + prefs.setBool('showBackToHR', true); + prefs.setString('employee_id', row['employee_id']); // Navigation logic here Navigator.pushNamed(context, 'empDetails', arguments: {'mobile': row['mobile']}); diff --git a/lib/service/api_service.dart b/lib/service/api_service.dart index 96bb740..8de0f82 100644 --- a/lib/service/api_service.dart +++ b/lib/service/api_service.dart @@ -39,8 +39,9 @@ class ApiService { } Future> getSelfEmployeeProfileToApi( - String clientId, String empCode, String branchID) async { + token, String clientId, String empCode, String branchID) async { print(_token); + _token = await token; if (_token == null) { await _initializeToken(); }