profile changes
This commit is contained in:
parent
e16fec2619
commit
bfe7055dc1
@ -70,6 +70,7 @@ class ApiService {
|
|||||||
await clearLocalStorageAndRedirect();
|
await clearLocalStorageAndRedirect();
|
||||||
return http.Response('Forbidden', 403);
|
return http.Response('Forbidden', 403);
|
||||||
} else {
|
} else {
|
||||||
|
ToastHelper.show('No File Found', Colors.red);
|
||||||
throw Exception('Failed request: ${response.statusCode}');
|
throw Exception('Failed request: ${response.statusCode}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,6 +89,22 @@ class ApiService {
|
|||||||
}
|
}
|
||||||
// --------------------------- COMMON FILES __________________________________________
|
// --------------------------- 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 {
|
Future<Map<String, dynamic>> _handleResponse(http.Response response) async {
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
return jsonDecode(response.body);
|
return jsonDecode(response.body);
|
||||||
@ -193,7 +210,6 @@ class ApiService {
|
|||||||
String path,
|
String path,
|
||||||
String id,
|
String id,
|
||||||
) async {
|
) async {
|
||||||
print('getPdfDownload 1');
|
|
||||||
print('getPdfDownload 1 - $path');
|
print('getPdfDownload 1 - $path');
|
||||||
|
|
||||||
// if (path.isEmpty) {
|
// if (path.isEmpty) {
|
||||||
@ -201,9 +217,9 @@ class ApiService {
|
|||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
final url = Uri.parse('https://venbait.in/nhance/partner/dev/$path');
|
final url = Uri.parse('https://venbait.in/nhance/partner/dev/$path');
|
||||||
|
print('getPdfDownload 2 - $url');
|
||||||
await _initializeToken();
|
await _initializeToken();
|
||||||
print('getPdfDownload 2');
|
|
||||||
if (_token == null) throw Exception('Token not found. Please log in.');
|
if (_token == null) throw Exception('Token not found. Please log in.');
|
||||||
|
|
||||||
final headers = {
|
final headers = {
|
||||||
@ -213,7 +229,6 @@ class ApiService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
final response = await _makeGethttpRequest(url, headers);
|
final response = await _makeGethttpRequest(url, headers);
|
||||||
print('getPdfDownload 3');
|
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
final contentType = response.headers['content-type'] ?? '';
|
final contentType = response.headers['content-type'] ?? '';
|
||||||
@ -253,7 +268,7 @@ class ApiService {
|
|||||||
final anchor = html.AnchorElement(href: blobUrl)
|
final anchor = html.AnchorElement(href: blobUrl)
|
||||||
..setAttribute('download', fileName)
|
..setAttribute('download', fileName)
|
||||||
..click();
|
..click();
|
||||||
print('getPdfDownloadcontentDisp..4');
|
|
||||||
html.Url.revokeObjectUrl(blobUrl);
|
html.Url.revokeObjectUrl(blobUrl);
|
||||||
}
|
}
|
||||||
} else if (response.statusCode == 404) {
|
} else if (response.statusCode == 404) {
|
||||||
@ -273,6 +288,9 @@ class ApiService {
|
|||||||
await clearLocalStorageAndRedirect();
|
await clearLocalStorageAndRedirect();
|
||||||
} else if (response.statusCode == 500) {
|
} else if (response.statusCode == 500) {
|
||||||
ToastHelper.show('No File Found', Colors.red);
|
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 {
|
} else {
|
||||||
ToastHelper.show('No File Found', Colors.red);
|
ToastHelper.show('No File Found', Colors.red);
|
||||||
throw Exception('Failed to download file');
|
throw Exception('Failed to download file');
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:go_router/go_router.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/routing/routes.dart';
|
||||||
|
import 'package:nhance_partner/core/services/api_service.dart';
|
||||||
import 'package:nhance_partner/data/services/auth_service.dart';
|
import 'package:nhance_partner/data/services/auth_service.dart';
|
||||||
import '../providers/manager_provider.dart';
|
import '../providers/manager_provider.dart';
|
||||||
|
import '../providers/userRoleProvider.dart';
|
||||||
import '../screens/UserManagement/Profile/profile_web.dart';
|
import '../screens/UserManagement/Profile/profile_web.dart';
|
||||||
import '../widgets/custom_action_popup.dart';
|
import '../widgets/custom_action_popup.dart';
|
||||||
import '../widgets/topbar.dart';
|
import '../widgets/topbar.dart';
|
||||||
@ -11,21 +13,45 @@ import '../widgets/footer.dart';
|
|||||||
import '../widgets/drawer_menu.dart';
|
import '../widgets/drawer_menu.dart';
|
||||||
import '../widgets/mobile_tabs.dart';
|
import '../widgets/mobile_tabs.dart';
|
||||||
import 'responsive_layout.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 Widget body;
|
||||||
final String title;
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final role = ref.watch(userRoleProvider);
|
||||||
|
|
||||||
return ResponsiveLayout(
|
return ResponsiveLayout(
|
||||||
// Mobile Layout
|
// Mobile Layout
|
||||||
mobile: Scaffold(
|
mobile: Scaffold(
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
appBar: TopBar(
|
appBar: TopBar(
|
||||||
title: title,
|
title: widget.title,
|
||||||
isMobile: true,
|
isMobile: true,
|
||||||
// onBack: () {
|
// onBack: () {
|
||||||
// // Navigator.pop(context);
|
// // Navigator.pop(context);
|
||||||
@ -34,14 +60,19 @@ class MainLayout extends StatelessWidget {
|
|||||||
debugPrint("Notifications tapped");
|
debugPrint("Notifications tapped");
|
||||||
},
|
},
|
||||||
|
|
||||||
onLogout: () {
|
onLogout: () async {
|
||||||
debugPrint("Logout tapped");
|
debugPrint("Logout tapped");
|
||||||
AuthService.clearToken();
|
AuthService.clearToken();
|
||||||
|
|
||||||
|
if (role != 'handler') {
|
||||||
|
await apiService.logoutUsingAPI(context);
|
||||||
|
}
|
||||||
|
|
||||||
context.go(AppRoutes.login);
|
context.go(AppRoutes.login);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
drawer: const DrawerMenu(),
|
drawer: const DrawerMenu(),
|
||||||
body: body,
|
body: widget.body,
|
||||||
bottomNavigationBar: MobileBottomMenu(
|
bottomNavigationBar: MobileBottomMenu(
|
||||||
// onTabChanged: (index) {
|
// onTabChanged: (index) {
|
||||||
// debugPrint("Mobile tab changed to $index");
|
// debugPrint("Mobile tab changed to $index");
|
||||||
@ -60,13 +91,16 @@ class MainLayout extends StatelessWidget {
|
|||||||
// Web Layout
|
// Web Layout
|
||||||
web: Scaffold(
|
web: Scaffold(
|
||||||
appBar: TopBar(
|
appBar: TopBar(
|
||||||
title: title,
|
title: widget.title,
|
||||||
onMenuPressed: () {
|
onMenuPressed: () {
|
||||||
Scaffold.of(context).openDrawer();
|
Scaffold.of(context).openDrawer();
|
||||||
},
|
},
|
||||||
onLogout: () {
|
onLogout: () async {
|
||||||
debugPrint("Logout tapped");
|
debugPrint("Logout tapped");
|
||||||
AuthService.clearToken();
|
AuthService.clearToken();
|
||||||
|
if (role != 'handler') {
|
||||||
|
await apiService.logoutUsingAPI(context);
|
||||||
|
}
|
||||||
context.go(AppRoutes.login);
|
context.go(AppRoutes.login);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -104,7 +138,7 @@ class MainLayout extends StatelessWidget {
|
|||||||
child: Container(
|
child: Container(
|
||||||
padding: EdgeInsets.all(2.0),
|
padding: EdgeInsets.all(2.0),
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
child: Column(children: [Expanded(child: body)]),
|
child: Column(children: [Expanded(child: widget.body)]),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@ -250,9 +250,9 @@ class ProfileState extends ConsumerState<Profile> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
if (profileData?['role_id'] != '1' &&
|
if ((roleId != 1) &&
|
||||||
profileData?['role_id'] != '2' &&
|
(roleId != 2) &&
|
||||||
profileData?['role_id'] != '3') ...[
|
(roleId != 3)) ...[
|
||||||
Row(
|
Row(
|
||||||
crossAxisAlignment:
|
crossAxisAlignment:
|
||||||
CrossAxisAlignment.start,
|
CrossAxisAlignment.start,
|
||||||
@ -276,7 +276,7 @@ class ProfileState extends ConsumerState<Profile> {
|
|||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
],
|
],
|
||||||
|
|
||||||
if (profileData?['role_id'] != 3) ...[
|
if ((roleId != 2) && (roleId != 3)) ...[
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.all(6),
|
padding: const EdgeInsets.all(6),
|
||||||
color: Color(0xffEDF6F5),
|
color: Color(0xffEDF6F5),
|
||||||
|
|||||||
@ -84,7 +84,7 @@ class ProfilePopUpState extends ConsumerState<ProfilePopUp> {
|
|||||||
if (managerId != null) {
|
if (managerId != null) {
|
||||||
getIncenctiveFileList(managerId);
|
getIncenctiveFileList(managerId);
|
||||||
}
|
}
|
||||||
} else if (roleId != 1 && roleId != 2) {
|
} else if (roleId != 1 && roleId != 2 && roleId != 3) {
|
||||||
final agentIdRaw = profileData?['id'];
|
final agentIdRaw = profileData?['id'];
|
||||||
final agentId = agentIdRaw is String
|
final agentId = agentIdRaw is String
|
||||||
? int.tryParse(agentIdRaw)
|
? int.tryParse(agentIdRaw)
|
||||||
@ -265,8 +265,9 @@ class ProfilePopUpState extends ConsumerState<ProfilePopUp> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
if (profileData?['role_id'] != '1' &&
|
if ((roleId != 1) &&
|
||||||
profileData?['role_id'] != '2') ...[
|
(roleId != 2) &&
|
||||||
|
(roleId != 3)) ...[
|
||||||
Row(
|
Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@ -289,7 +290,8 @@ class ProfilePopUpState extends ConsumerState<ProfilePopUp> {
|
|||||||
const SizedBox(height: 20),
|
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(
|
Container(
|
||||||
padding: const EdgeInsets.all(6),
|
padding: const EdgeInsets.all(6),
|
||||||
color: Color(0xffEDF6F5),
|
color: Color(0xffEDF6F5),
|
||||||
|
|||||||
BIN
lib_29_sep.zip
BIN
lib_29_sep.zip
Binary file not shown.
Loading…
Reference in New Issue
Block a user