UI_TP_SEQ_PARL
This commit is contained in:
parent
f9a3cbd91b
commit
6f251973a5
@ -262,6 +262,8 @@ class _groupState extends State<Group> {
|
||||
));
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
print("GRPDATA");
|
||||
await apiService.handleTokenRefresh(userId!);
|
||||
print("Group submitted successfully!");
|
||||
print("Response: ${response.body}");
|
||||
context.go('/group');
|
||||
|
||||
@ -285,6 +285,8 @@ class GroupDataState extends State<GroupData> {
|
||||
// _clearError();
|
||||
_clearError();
|
||||
await widget.fetchGetGroup();
|
||||
|
||||
await apiService.handleTokenRefresh(userId!);
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop(); // Close modal only if mounted
|
||||
}
|
||||
|
||||
@ -52,6 +52,7 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
// List<String> selectedServiceIds = [];
|
||||
|
||||
List<Map<String, dynamic>> selectedServiceIds = [];
|
||||
List<Map<String, dynamic>> originalSelectedServiceIds = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -280,6 +281,16 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
final map = Map<String, dynamic>.from(item);
|
||||
return {"service_id": map['service_id'].toString()};
|
||||
}).toList();
|
||||
|
||||
originalSelectedServiceIds =
|
||||
services.map<Map<String, dynamic>>((item) {
|
||||
// force cast or copy to a regular map
|
||||
final map = Map<String, dynamic>.from(item);
|
||||
return {"service_id": map['service_id'].toString()};
|
||||
}).toList();
|
||||
|
||||
print("SEA1 -$selectedServiceIds");
|
||||
print("SEA2 -$originalSelectedServiceIds");
|
||||
});
|
||||
|
||||
orgId = await getOrgId();
|
||||
@ -389,6 +400,7 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
|
||||
print(orgList);
|
||||
await updateOrgDataWithNewValues(orgList);
|
||||
await apiService.handleTokenRefresh(userId!);
|
||||
print("📨 Response Organizt Update:");
|
||||
// return orgList;
|
||||
context.go('/OrganizationSettings');
|
||||
@ -439,18 +451,104 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
||||
|
||||
void handleSubmit() {
|
||||
print("HandleSubmiy - $orgData");
|
||||
print("Raw Service IDs: ${orgData['services_ids']}");
|
||||
print("SEA2 -$originalSelectedServiceIds");
|
||||
createOrgData(orgData);
|
||||
|
||||
setState(() {
|
||||
if (!isValidData(orgData)) {
|
||||
print("USERDETAILS : $orgData");
|
||||
print("Validation Failed: Required fields are missing.");
|
||||
return; // Stop execution if validation fails
|
||||
} else {
|
||||
print("USERDETAILS : $orgData");
|
||||
createOrgData(orgData);
|
||||
}
|
||||
});
|
||||
// Raw (decode JSON string to list)
|
||||
// final rawServiceList = jsonDecode(orgData['services_ids']);
|
||||
//
|
||||
// print("Raw Service IDs: ${orgData['services_ids']}");
|
||||
// print("Raw Service IDs2: $rawServiceList");
|
||||
// print("SEA2 -$originalSelectedServiceIds");
|
||||
// final rawServiceIds =
|
||||
// rawServiceList.map((e) => e['service_id'].toString()).toList();
|
||||
//
|
||||
// // Original service IDs
|
||||
// final originalServiceIds =
|
||||
// originalSelectedServiceIds
|
||||
// .map((e) => e['service_id'].toString())
|
||||
// .toList();
|
||||
//
|
||||
// final addedServices =
|
||||
// rawServiceIds.where((id) => !originalServiceIds.contains(id)).toList();
|
||||
// final removedServices =
|
||||
// originalServiceIds.where((id) => !rawServiceIds.contains(id)).toList();
|
||||
//
|
||||
// setState(() {
|
||||
// if (addedServices.isNotEmpty || removedServices.isNotEmpty) {
|
||||
// print("UE1");
|
||||
// _showConfirmationDialog(context);
|
||||
// } else {
|
||||
// print("UE2");
|
||||
// createOrgData(orgData);
|
||||
// }
|
||||
// });
|
||||
|
||||
// setState(() {
|
||||
// if (!isValidData(orgData)) {
|
||||
// print("USERDETAILS : $orgData");
|
||||
// print("Validation Failed: Required fields are missing.");
|
||||
// return; // Stop execution if validation fails
|
||||
// } else {
|
||||
// print("USERDETAILS : $orgData");
|
||||
//
|
||||
// //createOrgData(orgData);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
void _showConfirmationDialog(
|
||||
BuildContext context,
|
||||
// List<String> added,
|
||||
// List<String> removed,
|
||||
) {
|
||||
print("clickTR12 ");
|
||||
String message = '';
|
||||
// if (added.isNotEmpty) {
|
||||
// message += "Added: ${added.join(", ")}\n";
|
||||
// }
|
||||
// if (removed.isNotEmpty) {
|
||||
// message += "Removed: ${removed.join(", ")}\n";
|
||||
// }
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder:
|
||||
(ctx) => AlertDialog(
|
||||
title: Text("Service Changes "),
|
||||
content: Text(
|
||||
"App will logout when service changes,Do you want to continue?",
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text("Cancel"),
|
||||
onPressed: () => Navigator.of(ctx).pop(),
|
||||
),
|
||||
TextButton(
|
||||
child: Text("Continue"),
|
||||
onPressed: () {
|
||||
Navigator.of(ctx).pop();
|
||||
logout(ctx);
|
||||
// ✅ Call your function here
|
||||
createOrgData(orgData);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> logout(BuildContext context) async {
|
||||
// Clear localStorage
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.clear(); // Clears all keys
|
||||
|
||||
// Optional: clear sessionStorage if used
|
||||
// html.window.sessionStorage.clear();
|
||||
|
||||
// Navigate to login or home page
|
||||
context.go('/');
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -602,6 +602,7 @@ class _PolicyState extends State<Policy> {
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print("policyData submitted successfully!");
|
||||
await apiService.handleTokenRefresh(userId!);
|
||||
print("Response: ${response.body}");
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@ -1448,8 +1448,8 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
|
||||
SelectedParallelProcess[ServiceId!] ==
|
||||
"3") {
|
||||
setState(() {
|
||||
SelectedParallelProcess[ServiceId!] =
|
||||
"0";
|
||||
// SelectedParallelProcess[ServiceId!] =
|
||||
// "0";
|
||||
});
|
||||
}
|
||||
print(
|
||||
@ -2373,15 +2373,17 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
|
||||
"None"))
|
||||
? "P"
|
||||
: ((FourthExceptionalApproverAction[ServiceId!] !=
|
||||
"None") &&
|
||||
((SelectedParallelExceptionalProcess[ServiceId] ==
|
||||
"1" ||
|
||||
SelectedParallelExceptionalProcess[ServiceId] ==
|
||||
"2" ||
|
||||
SelectedParallelExceptionalProcess[ServiceId] ==
|
||||
"3" ||
|
||||
SelectedParallelExceptionalProcess[ServiceId] ==
|
||||
"4")))
|
||||
"None")
|
||||
// &&
|
||||
// ((SelectedParallelExceptionalProcess[ServiceId] ==
|
||||
// "1" ||
|
||||
// SelectedParallelExceptionalProcess[ServiceId] ==
|
||||
// "2" ||
|
||||
// SelectedParallelExceptionalProcess[ServiceId] ==
|
||||
// "3" ||
|
||||
// SelectedParallelExceptionalProcess[ServiceId] ==
|
||||
// "4"))
|
||||
)
|
||||
? 'S'
|
||||
: '',
|
||||
|
||||
@ -2504,14 +2506,13 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
|
||||
// Find the country_code based on selected country_name
|
||||
FourthExceptionalApproverAction[ServiceId!] =
|
||||
newValue;
|
||||
|
||||
// SelectedParallelExceptionalProcess[ServiceId!] =
|
||||
// "4";
|
||||
if (newValue == "None" &&
|
||||
((SelectedParallelExceptionalProcess[ServiceId!] ==
|
||||
"4"))) {
|
||||
setState(() {
|
||||
SelectedParallelExceptionalProcess[ServiceId!] =
|
||||
"4";
|
||||
});
|
||||
// SelectedParallelExceptionalProcess[ServiceId!] =
|
||||
// "4";
|
||||
}
|
||||
|
||||
// print("selectedUserType - $selectedUserType");
|
||||
@ -3355,8 +3356,8 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
SelectedParallelAmendProcess[ServiceId!] =
|
||||
"4";
|
||||
// SelectedParallelAmendProcess[ServiceId!] =
|
||||
// "4";
|
||||
|
||||
if ((FourthAmendApproverAction[ServiceId!] ==
|
||||
"None")) {
|
||||
@ -3415,15 +3416,17 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
|
||||
"None"))
|
||||
? "P"
|
||||
: ((FourthAmendApproverAction[ServiceId!] !=
|
||||
"None") &&
|
||||
((SelectedParallelAmendProcess[ServiceId] ==
|
||||
"1" ||
|
||||
SelectedParallelAmendProcess[ServiceId] ==
|
||||
"2" ||
|
||||
SelectedParallelAmendProcess[ServiceId] ==
|
||||
"3" ||
|
||||
SelectedParallelAmendProcess[ServiceId] ==
|
||||
"4")))
|
||||
"None")
|
||||
// &&
|
||||
// ((SelectedParallelAmendProcess[ServiceId] ==
|
||||
// "1" ||
|
||||
// SelectedParallelAmendProcess[ServiceId] ==
|
||||
// "2" ||
|
||||
// SelectedParallelAmendProcess[ServiceId] ==
|
||||
// "3" ||
|
||||
// SelectedParallelAmendProcess[ServiceId] ==
|
||||
// "4"))
|
||||
)
|
||||
? 'S'
|
||||
: '',
|
||||
|
||||
@ -3533,14 +3536,13 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
|
||||
// Find the country_code based on selected country_name
|
||||
FourthAmendApproverAction[ServiceId!] =
|
||||
newValue;
|
||||
|
||||
// SelectedParallelAmendProcess[ServiceId!] =
|
||||
// "4";
|
||||
if (newValue == "None" &&
|
||||
((SelectedParallelAmendProcess[ServiceId!] ==
|
||||
"4"))) {
|
||||
setState(() {
|
||||
SelectedParallelAmendProcess[ServiceId!] =
|
||||
"4";
|
||||
});
|
||||
// SelectedParallelAmendProcess[ServiceId!] =
|
||||
// "4";
|
||||
}
|
||||
|
||||
// print("selectedUserType - $selectedUserType");
|
||||
|
||||
@ -34,8 +34,8 @@ class _MyAppState extends State<MyApp> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
SemanticsBinding.instance
|
||||
.ensureSemantics(); // -only for testing uncomment, Otherwise Email Template wont allow to type
|
||||
// SemanticsBinding.instance
|
||||
// .ensureSemantics(); // -only for testing uncomment, Otherwise Email Template wont allow to type
|
||||
if (kIsWeb) {
|
||||
final uri = Uri.parse(html.window.location.href);
|
||||
print("URI - $uri");
|
||||
@ -62,7 +62,7 @@ class _MyAppState extends State<MyApp> {
|
||||
setState(() {
|
||||
_isAuthRedirect = true; // Show loading screen ONLY for MS login
|
||||
});
|
||||
print("🔍 Auth code detected at startup: $authCode");
|
||||
print(" Auth code detected at startup: $authCode");
|
||||
// ✅ Immediately begin token handling
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// handleTokenUsingMS(authCode);
|
||||
|
||||
@ -13,6 +13,42 @@ import 'dart:convert';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class ApiService {
|
||||
Future<void> storeUserDetails(String token) async {
|
||||
try {
|
||||
final parts = token.split('.');
|
||||
if (parts.length != 3) throw Exception('Invalid token format');
|
||||
|
||||
final payload = json.decode(
|
||||
utf8.decode(base64Url.decode(base64Url.normalize(parts[1]))),
|
||||
);
|
||||
|
||||
final userData = payload['data'];
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('auth_token', token);
|
||||
await prefs.setString(
|
||||
'user_data',
|
||||
jsonEncode(userData),
|
||||
); // Store full user data
|
||||
|
||||
if (userData != null) {
|
||||
final pref = await SharedPreferences.getInstance();
|
||||
await pref.setString('auth_token', token);
|
||||
await pref.setString('user_data', jsonEncode(userData));
|
||||
|
||||
// userRole = userData['role'];
|
||||
|
||||
print("userData - $userData");
|
||||
print("userData11 - ${userData['role']}");
|
||||
// print("userData12 - $userRole");
|
||||
}
|
||||
|
||||
await getOrganizationData();
|
||||
} catch (e) {
|
||||
print('Error decoding token: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getOrganizationData() async {
|
||||
try {
|
||||
print("ORG getUpdatedServices");
|
||||
@ -610,6 +646,37 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> handleTokenRefresh(String userId) async {
|
||||
final String apiUrldata =
|
||||
'$apiUrl/api/user/refreshUserToken?user_id=$userId';
|
||||
print("API URL: $userId");
|
||||
// final token = await getToken();
|
||||
|
||||
final token = await getToken();
|
||||
|
||||
final response = await http.get(
|
||||
Uri.parse(apiUrldata),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
'Content-Type': 'application/json',
|
||||
'app-signature': 'ts-traveltool-2025-signature-123456',
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
print("data- $data");
|
||||
|
||||
final token = data['token']; // Assuming the token is in response
|
||||
// final userId = data['user_id'].toString();
|
||||
|
||||
print("Token - $token");
|
||||
await storeUserDetails(token);
|
||||
} else {
|
||||
throw Exception('Failed to load plans');
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> viewPlan(
|
||||
BuildContext context,
|
||||
String planId, {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user