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) {
|
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||||
|
print("GRPDATA");
|
||||||
|
await apiService.handleTokenRefresh(userId!);
|
||||||
print("Group submitted successfully!");
|
print("Group submitted successfully!");
|
||||||
print("Response: ${response.body}");
|
print("Response: ${response.body}");
|
||||||
context.go('/group');
|
context.go('/group');
|
||||||
|
|||||||
@ -285,6 +285,8 @@ class GroupDataState extends State<GroupData> {
|
|||||||
// _clearError();
|
// _clearError();
|
||||||
_clearError();
|
_clearError();
|
||||||
await widget.fetchGetGroup();
|
await widget.fetchGetGroup();
|
||||||
|
|
||||||
|
await apiService.handleTokenRefresh(userId!);
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
Navigator.of(context).pop(); // Close modal only if mounted
|
Navigator.of(context).pop(); // Close modal only if mounted
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,6 +52,7 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
|||||||
// List<String> selectedServiceIds = [];
|
// List<String> selectedServiceIds = [];
|
||||||
|
|
||||||
List<Map<String, dynamic>> selectedServiceIds = [];
|
List<Map<String, dynamic>> selectedServiceIds = [];
|
||||||
|
List<Map<String, dynamic>> originalSelectedServiceIds = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -280,6 +281,16 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
|||||||
final map = Map<String, dynamic>.from(item);
|
final map = Map<String, dynamic>.from(item);
|
||||||
return {"service_id": map['service_id'].toString()};
|
return {"service_id": map['service_id'].toString()};
|
||||||
}).toList();
|
}).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();
|
orgId = await getOrgId();
|
||||||
@ -389,6 +400,7 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
|||||||
|
|
||||||
print(orgList);
|
print(orgList);
|
||||||
await updateOrgDataWithNewValues(orgList);
|
await updateOrgDataWithNewValues(orgList);
|
||||||
|
await apiService.handleTokenRefresh(userId!);
|
||||||
print("📨 Response Organizt Update:");
|
print("📨 Response Organizt Update:");
|
||||||
// return orgList;
|
// return orgList;
|
||||||
context.go('/OrganizationSettings');
|
context.go('/OrganizationSettings');
|
||||||
@ -439,18 +451,104 @@ class _OrgSetUpState extends State<OrgSetUp> {
|
|||||||
|
|
||||||
void handleSubmit() {
|
void handleSubmit() {
|
||||||
print("HandleSubmiy - $orgData");
|
print("HandleSubmiy - $orgData");
|
||||||
|
print("Raw Service IDs: ${orgData['services_ids']}");
|
||||||
|
print("SEA2 -$originalSelectedServiceIds");
|
||||||
createOrgData(orgData);
|
createOrgData(orgData);
|
||||||
|
|
||||||
setState(() {
|
// Raw (decode JSON string to list)
|
||||||
if (!isValidData(orgData)) {
|
// final rawServiceList = jsonDecode(orgData['services_ids']);
|
||||||
print("USERDETAILS : $orgData");
|
//
|
||||||
print("Validation Failed: Required fields are missing.");
|
// print("Raw Service IDs: ${orgData['services_ids']}");
|
||||||
return; // Stop execution if validation fails
|
// print("Raw Service IDs2: $rawServiceList");
|
||||||
} else {
|
// print("SEA2 -$originalSelectedServiceIds");
|
||||||
print("USERDETAILS : $orgData");
|
// final rawServiceIds =
|
||||||
createOrgData(orgData);
|
// 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
|
@override
|
||||||
|
|||||||
@ -602,6 +602,7 @@ class _PolicyState extends State<Policy> {
|
|||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
print("policyData submitted successfully!");
|
print("policyData submitted successfully!");
|
||||||
|
await apiService.handleTokenRefresh(userId!);
|
||||||
print("Response: ${response.body}");
|
print("Response: ${response.body}");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1448,8 +1448,8 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
|
|||||||
SelectedParallelProcess[ServiceId!] ==
|
SelectedParallelProcess[ServiceId!] ==
|
||||||
"3") {
|
"3") {
|
||||||
setState(() {
|
setState(() {
|
||||||
SelectedParallelProcess[ServiceId!] =
|
// SelectedParallelProcess[ServiceId!] =
|
||||||
"0";
|
// "0";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
print(
|
print(
|
||||||
@ -2373,15 +2373,17 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
|
|||||||
"None"))
|
"None"))
|
||||||
? "P"
|
? "P"
|
||||||
: ((FourthExceptionalApproverAction[ServiceId!] !=
|
: ((FourthExceptionalApproverAction[ServiceId!] !=
|
||||||
"None") &&
|
"None")
|
||||||
((SelectedParallelExceptionalProcess[ServiceId] ==
|
// &&
|
||||||
"1" ||
|
// ((SelectedParallelExceptionalProcess[ServiceId] ==
|
||||||
SelectedParallelExceptionalProcess[ServiceId] ==
|
// "1" ||
|
||||||
"2" ||
|
// SelectedParallelExceptionalProcess[ServiceId] ==
|
||||||
SelectedParallelExceptionalProcess[ServiceId] ==
|
// "2" ||
|
||||||
"3" ||
|
// SelectedParallelExceptionalProcess[ServiceId] ==
|
||||||
SelectedParallelExceptionalProcess[ServiceId] ==
|
// "3" ||
|
||||||
"4")))
|
// SelectedParallelExceptionalProcess[ServiceId] ==
|
||||||
|
// "4"))
|
||||||
|
)
|
||||||
? 'S'
|
? 'S'
|
||||||
: '',
|
: '',
|
||||||
|
|
||||||
@ -2504,14 +2506,13 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
|
|||||||
// Find the country_code based on selected country_name
|
// Find the country_code based on selected country_name
|
||||||
FourthExceptionalApproverAction[ServiceId!] =
|
FourthExceptionalApproverAction[ServiceId!] =
|
||||||
newValue;
|
newValue;
|
||||||
|
// SelectedParallelExceptionalProcess[ServiceId!] =
|
||||||
|
// "4";
|
||||||
if (newValue == "None" &&
|
if (newValue == "None" &&
|
||||||
((SelectedParallelExceptionalProcess[ServiceId!] ==
|
((SelectedParallelExceptionalProcess[ServiceId!] ==
|
||||||
"4"))) {
|
"4"))) {
|
||||||
setState(() {
|
// SelectedParallelExceptionalProcess[ServiceId!] =
|
||||||
SelectedParallelExceptionalProcess[ServiceId!] =
|
// "4";
|
||||||
"4";
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// print("selectedUserType - $selectedUserType");
|
// print("selectedUserType - $selectedUserType");
|
||||||
@ -3355,8 +3356,8 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
|
|||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
SelectedParallelAmendProcess[ServiceId!] =
|
// SelectedParallelAmendProcess[ServiceId!] =
|
||||||
"4";
|
// "4";
|
||||||
|
|
||||||
if ((FourthAmendApproverAction[ServiceId!] ==
|
if ((FourthAmendApproverAction[ServiceId!] ==
|
||||||
"None")) {
|
"None")) {
|
||||||
@ -3415,15 +3416,17 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
|
|||||||
"None"))
|
"None"))
|
||||||
? "P"
|
? "P"
|
||||||
: ((FourthAmendApproverAction[ServiceId!] !=
|
: ((FourthAmendApproverAction[ServiceId!] !=
|
||||||
"None") &&
|
"None")
|
||||||
((SelectedParallelAmendProcess[ServiceId] ==
|
// &&
|
||||||
"1" ||
|
// ((SelectedParallelAmendProcess[ServiceId] ==
|
||||||
SelectedParallelAmendProcess[ServiceId] ==
|
// "1" ||
|
||||||
"2" ||
|
// SelectedParallelAmendProcess[ServiceId] ==
|
||||||
SelectedParallelAmendProcess[ServiceId] ==
|
// "2" ||
|
||||||
"3" ||
|
// SelectedParallelAmendProcess[ServiceId] ==
|
||||||
SelectedParallelAmendProcess[ServiceId] ==
|
// "3" ||
|
||||||
"4")))
|
// SelectedParallelAmendProcess[ServiceId] ==
|
||||||
|
// "4"))
|
||||||
|
)
|
||||||
? 'S'
|
? 'S'
|
||||||
: '',
|
: '',
|
||||||
|
|
||||||
@ -3533,14 +3536,13 @@ class PolicyCriteriaState extends State<PolicyCriteria> {
|
|||||||
// Find the country_code based on selected country_name
|
// Find the country_code based on selected country_name
|
||||||
FourthAmendApproverAction[ServiceId!] =
|
FourthAmendApproverAction[ServiceId!] =
|
||||||
newValue;
|
newValue;
|
||||||
|
// SelectedParallelAmendProcess[ServiceId!] =
|
||||||
|
// "4";
|
||||||
if (newValue == "None" &&
|
if (newValue == "None" &&
|
||||||
((SelectedParallelAmendProcess[ServiceId!] ==
|
((SelectedParallelAmendProcess[ServiceId!] ==
|
||||||
"4"))) {
|
"4"))) {
|
||||||
setState(() {
|
// SelectedParallelAmendProcess[ServiceId!] =
|
||||||
SelectedParallelAmendProcess[ServiceId!] =
|
// "4";
|
||||||
"4";
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// print("selectedUserType - $selectedUserType");
|
// print("selectedUserType - $selectedUserType");
|
||||||
|
|||||||
@ -34,8 +34,8 @@ class _MyAppState extends State<MyApp> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
SemanticsBinding.instance
|
// SemanticsBinding.instance
|
||||||
.ensureSemantics(); // -only for testing uncomment, Otherwise Email Template wont allow to type
|
// .ensureSemantics(); // -only for testing uncomment, Otherwise Email Template wont allow to type
|
||||||
if (kIsWeb) {
|
if (kIsWeb) {
|
||||||
final uri = Uri.parse(html.window.location.href);
|
final uri = Uri.parse(html.window.location.href);
|
||||||
print("URI - $uri");
|
print("URI - $uri");
|
||||||
@ -62,7 +62,7 @@ class _MyAppState extends State<MyApp> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
_isAuthRedirect = true; // Show loading screen ONLY for MS login
|
_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
|
// ✅ Immediately begin token handling
|
||||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
// handleTokenUsingMS(authCode);
|
// handleTokenUsingMS(authCode);
|
||||||
|
|||||||
@ -13,6 +13,42 @@ import 'dart:convert';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class ApiService {
|
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 {
|
Future<void> getOrganizationData() async {
|
||||||
try {
|
try {
|
||||||
print("ORG getUpdatedServices");
|
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(
|
static Future<void> viewPlan(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
String planId, {
|
String planId, {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user