profile changes

This commit is contained in:
venbaittech 2025-10-31 14:59:25 +05:30
parent e16fec2619
commit bfe7055dc1
5 changed files with 76 additions and 22 deletions

View File

@ -70,6 +70,7 @@ class ApiService {
await clearLocalStorageAndRedirect();
return http.Response('Forbidden', 403);
} else {
ToastHelper.show('No File Found', Colors.red);
throw Exception('Failed request: ${response.statusCode}');
}
}
@ -88,6 +89,22 @@ class ApiService {
}
// --------------------------- COMMON FILES __________________________________________
Future<Map<String, dynamic>> logoutUsingAPI(agentId) async {
// print(_token);
if (_token == null) {
await _initializeToken();
}
final url = Uri.parse('${Env.apiUrl}auth/logout');
final headers = {
'Authorization': 'Bearer $_token' ?? '',
'app-signature': Env.App_Signature,
};
final response = await _makeGetRequest(url, headers);
return response;
}
Future<Map<String, dynamic>> _handleResponse(http.Response response) async {
if (response.statusCode == 200) {
return jsonDecode(response.body);
@ -193,7 +210,6 @@ class ApiService {
String path,
String id,
) async {
print('getPdfDownload 1');
print('getPdfDownload 1 - $path');
// if (path.isEmpty) {
@ -201,9 +217,9 @@ class ApiService {
// return;
// }
final url = Uri.parse('https://venbait.in/nhance/partner/dev/$path');
print('getPdfDownload 2 - $url');
await _initializeToken();
print('getPdfDownload 2');
if (_token == null) throw Exception('Token not found. Please log in.');
final headers = {
@ -213,7 +229,6 @@ class ApiService {
};
final response = await _makeGethttpRequest(url, headers);
print('getPdfDownload 3');
if (response.statusCode == 200) {
final contentType = response.headers['content-type'] ?? '';
@ -253,7 +268,7 @@ class ApiService {
final anchor = html.AnchorElement(href: blobUrl)
..setAttribute('download', fileName)
..click();
print('getPdfDownloadcontentDisp..4');
html.Url.revokeObjectUrl(blobUrl);
}
} else if (response.statusCode == 404) {
@ -273,6 +288,9 @@ class ApiService {
await clearLocalStorageAndRedirect();
} else if (response.statusCode == 500) {
ToastHelper.show('No File Found', Colors.red);
} else if (response.statusCode == 302) {
print('getPdfDownload 3-PP-302');
ToastHelper.show('No File Found', Colors.red);
} else {
ToastHelper.show('No File Found', Colors.red);
throw Exception('Failed to download file');

View File

@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:http/http.dart' as ref;
import 'package:nhance_partner/core/routing/routes.dart';
import 'package:nhance_partner/core/services/api_service.dart';
import 'package:nhance_partner/data/services/auth_service.dart';
import '../providers/manager_provider.dart';
import '../providers/userRoleProvider.dart';
import '../screens/UserManagement/Profile/profile_web.dart';
import '../widgets/custom_action_popup.dart';
import '../widgets/topbar.dart';
@ -11,21 +13,45 @@ import '../widgets/footer.dart';
import '../widgets/drawer_menu.dart';
import '../widgets/mobile_tabs.dart';
import 'responsive_layout.dart';
import 'package:http/http.dart' as http;
// import 'package:http/http.dart' as ref;
class MainLayout extends StatelessWidget {
// class MainLayout extends StatelessWidget {
// final Widget body;
// final String title;
//
// MainLayout({super.key, required this.body, required this.title});
class MainLayout extends ConsumerStatefulWidget {
final Widget body;
final String title;
MainLayout({super.key, required this.body, required this.title});
@override
ConsumerState<MainLayout> createState() => MainLayoutState();
}
const MainLayout({super.key, required this.body, required this.title});
class MainLayoutState extends ConsumerState<MainLayout> {
dynamic role;
ApiService apiService = ApiService();
@override
void initState() {
super.initState();
Future.microtask(() {
role = ref.watch(userRoleProvider);
});
}
@override
Widget build(BuildContext context) {
final role = ref.watch(userRoleProvider);
return ResponsiveLayout(
// Mobile Layout
mobile: Scaffold(
backgroundColor: Colors.white,
appBar: TopBar(
title: title,
title: widget.title,
isMobile: true,
// onBack: () {
// // Navigator.pop(context);
@ -34,14 +60,19 @@ class MainLayout extends StatelessWidget {
debugPrint("Notifications tapped");
},
onLogout: () {
onLogout: () async {
debugPrint("Logout tapped");
AuthService.clearToken();
if (role != 'handler') {
await apiService.logoutUsingAPI(context);
}
context.go(AppRoutes.login);
},
),
drawer: const DrawerMenu(),
body: body,
body: widget.body,
bottomNavigationBar: MobileBottomMenu(
// onTabChanged: (index) {
// debugPrint("Mobile tab changed to $index");
@ -60,13 +91,16 @@ class MainLayout extends StatelessWidget {
// Web Layout
web: Scaffold(
appBar: TopBar(
title: title,
title: widget.title,
onMenuPressed: () {
Scaffold.of(context).openDrawer();
},
onLogout: () {
onLogout: () async {
debugPrint("Logout tapped");
AuthService.clearToken();
if (role != 'handler') {
await apiService.logoutUsingAPI(context);
}
context.go(AppRoutes.login);
},
@ -104,7 +138,7 @@ class MainLayout extends StatelessWidget {
child: Container(
padding: EdgeInsets.all(2.0),
color: Colors.white,
child: Column(children: [Expanded(child: body)]),
child: Column(children: [Expanded(child: widget.body)]),
),
),
],

View File

@ -250,9 +250,9 @@ class ProfileState extends ConsumerState<Profile> {
],
),
const SizedBox(height: 16),
if (profileData?['role_id'] != '1' &&
profileData?['role_id'] != '2' &&
profileData?['role_id'] != '3') ...[
if ((roleId != 1) &&
(roleId != 2) &&
(roleId != 3)) ...[
Row(
crossAxisAlignment:
CrossAxisAlignment.start,
@ -276,7 +276,7 @@ class ProfileState extends ConsumerState<Profile> {
const SizedBox(height: 20),
],
if (profileData?['role_id'] != 3) ...[
if ((roleId != 2) && (roleId != 3)) ...[
Container(
padding: const EdgeInsets.all(6),
color: Color(0xffEDF6F5),

View File

@ -84,7 +84,7 @@ class ProfilePopUpState extends ConsumerState<ProfilePopUp> {
if (managerId != null) {
getIncenctiveFileList(managerId);
}
} else if (roleId != 1 && roleId != 2) {
} else if (roleId != 1 && roleId != 2 && roleId != 3) {
final agentIdRaw = profileData?['id'];
final agentId = agentIdRaw is String
? int.tryParse(agentIdRaw)
@ -265,8 +265,9 @@ class ProfilePopUpState extends ConsumerState<ProfilePopUp> {
],
),
const SizedBox(height: 16),
if (profileData?['role_id'] != '1' &&
profileData?['role_id'] != '2') ...[
if ((roleId != 1) &&
(roleId != 2) &&
(roleId != 3)) ...[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@ -289,7 +290,8 @@ class ProfilePopUpState extends ConsumerState<ProfilePopUp> {
const SizedBox(height: 20),
],
if (profileData?['role_id'] != 2) ...[
if ((roleId != 2) && (roleId != 3)) ...[
// Staff, Handler doesn't have this part Only Manager and agent have
Container(
padding: const EdgeInsets.all(6),
color: Color(0xffEDF6F5),

Binary file not shown.