diff --git a/lib/Screens/dialog/user_selection_dialog.dart b/lib/Screens/dialog/user_selection_dialog.dart index 1922436..6a90111 100644 --- a/lib/Screens/dialog/user_selection_dialog.dart +++ b/lib/Screens/dialog/user_selection_dialog.dart @@ -94,8 +94,10 @@ class _UserSelectionDialogState extends State { setState(() { _users = userList.map((user) => SearchUser.fromJson(user)).toList(); _filteredUsers = List.from(_users); - }); + _filterUsers(""); + }); + print("filtered user === ${_filteredUsers.length}"); print("Users fetched: ${_users.length}"); for (var user in _users) { print("${user.firstName} ${user.lastName} ${user.empCode}"); @@ -136,7 +138,7 @@ class _UserSelectionDialogState extends State { if (response.statusCode == 200) { final Map responseBody = json.decode(response.body); - print("API Response: $responseBody"); // Debugging + print("API Traveller Response: $responseBody"); // Debugging if (responseBody.containsKey('data') && responseBody['data'] is List) { List travellerList = responseBody['data']; @@ -147,6 +149,7 @@ class _UserSelectionDialogState extends State { .map((user) => SearchTraveler.fromJson(user)) .toList(); _filteredTraveller = List.from(_traveller); + _filterTravellers(""); }); print("Users fetched: ${_users.length}"); @@ -201,21 +204,28 @@ class _UserSelectionDialogState extends State { // } void _filterUsers(String query) { - print("Filtering _filterUsersTravellers..."); + print("Filtering _filterUsers... ${_filteredUsers.length}"); setState(() { _filteredList.clear(); // Reset the list before filtering final excludedUserId = widget.currentUser.toString(); + if (query.isEmpty) { - _filteredList = [ - // ..._users.map((user) => {"type": "user", "data": user}), - ..._users - .where( - (user) => - (user.userId.toString() == excludedUserId && - user.roleId.toString() == "5"), - ) // ⛔ Exclude user ID 4 - .map((user) => {"type": "user", "data": user}), - ]; + // ✅ Return all users excluding self and roleId == 5 + _filteredList = _users.where((user) => + user.userId.toString() != excludedUserId && user.roleId.toString() != "5") + .map((user) => {"type": "user", "data": user}) + .toList(); + + // _filteredList = [ + // // ..._users.map((user) => {"type": "user", "data": user}), + // ..._users + // .where( + // (user) => + // (user.userId.toString() == excludedUserId && + // user.roleId.toString() == "5"), + // ) // ⛔ Exclude user ID 4 + // .map((user) => {"type": "user", "data": user}), + // ]; } else { _filteredList = [ ..._users @@ -243,7 +253,17 @@ class _UserSelectionDialogState extends State { } }); - print("Filtered List:"); + // setState(() { + // print("Called 2.1"); + // print("h1 - ${_filteredUsers}"); + // if (query.isEmpty) { + // _filteredList = _filteredUsers + // .map((user) => {"type": "user", "data": user}) + // .toList(); + // } + // + // }); + for (var item in _filteredList) { var user = item["data"]; print( @@ -253,14 +273,16 @@ class _UserSelectionDialogState extends State { } void _filterTravellers(String query) { - print("Filtering _filterUsersTravellers..."); + print("Filtering _filterTravellers..."); setState(() { _filteredList.clear(); // Reset the list before filtering - if (query.isEmpty) { - _filteredList = [ - ..._users.map((user) => {"type": "user", "data": user}), - ]; + _filteredList = _traveller + .map((traveller) => {"type": "traveller", "data": traveller}) + .toList(); + // _filteredList = [ + // ..._users.map((user) => {"type": "user", "data": user}), + // ]; } else { _filteredList = [ ..._traveller @@ -289,6 +311,15 @@ class _UserSelectionDialogState extends State { } } + void _filterByTitle(String query) { + print("filtered by title"); + if (widget.title == "Others (Non Employee)") { + _filterTravellers(query); + } else { + _filterUsers(query); + } + } + void _filterUsersTravellers(String query) { print("Filtering _filterUsersTravellers..."); setState(() { @@ -346,13 +377,19 @@ class _UserSelectionDialogState extends State { @override void initState() { super.initState(); - fetchUsers(); - fetchTraveller(); + if (widget.title == "Others (Non Employee)"){ fetchTraveller(); } + else{ fetchUsers(); } print("SelffsdfcurrentUser - ${widget.currentUser}"); + _filterByTitle(""); } @override Widget build(BuildContext context) { + + final isValid = _searchController.text.trim().isNotEmpty && + userIdSelected.trim().isNotEmpty; + + return Dialog( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), child: Container( @@ -442,8 +479,10 @@ class _UserSelectionDialogState extends State { SizedBox(height: 5), // User List or Message - _searchController.text.isNotEmpty - ? SizedBox( + // _searchController.text.isNotEmpty + // ? + if (!_showTravellerForm) + SizedBox( height: 300, // Limit height to avoid overflow // child: _filteredUsers.isEmpty child: @@ -468,31 +507,33 @@ class _UserSelectionDialogState extends State { final userType = item["type"]; // "user" or "traveller" if (user is Map) { - print( - "userLsirer - ${jsonEncode(user)}", - ); // pretty JSON-like string + print("userLsirer - ${jsonEncode(user)}"); // pretty JSON-like string } else { print("userLsirer - $user"); // fallback } + final isSelected = userIdSelected == (userType == "user" ? user.userId : user.travellerId); return ListTile( + // hoverColor: , title: Text( - "${user.firstName ?? "Unknown"} ${user.lastName ?? ""}", - style: GoogleFonts.poppins(fontSize: 11), + "${user.firstName ?? "Unknown"}" "${(user.lastName?.isNotEmpty ?? false) ? " ${user.lastName}" : ""}", + style: GoogleFonts.poppins(fontSize: 11 , color: isSelected ? widget.layoutColorForUser : Colors.black), ), subtitle: userType == "user" ? Text( - "Employee ID: ${user.empCode ?? ""} ", + "Employee ID: ${user.empCode ?? "-"} ", // "Employee ID: ${userType == "user" ? user.userId : user.travellerId}", style: GoogleFonts.poppins( fontSize: 10, + color: isSelected ? widget.layoutColorForUser : Colors.black, ), ) : Text( - "Mobile : ${user.mobileNo ?? ""} ", + "Mobile : ${user.mobileNo ?? "-"} ", // "Employee ID: ${userType == "user" ? user.userId : user.travellerId}", style: GoogleFonts.poppins( fontSize: 10, + color: isSelected ? widget.layoutColorForUser : Colors.black, ), ), onTap: () { @@ -514,8 +555,8 @@ class _UserSelectionDialogState extends State { ); }, ), - ) - : SizedBox.shrink(), + ), + // : SizedBox.shrink(), // Traveler Form if (_showTravellerForm) @@ -575,30 +616,30 @@ class _UserSelectionDialogState extends State { SizedBox(width: 10), ElevatedButton( style: ElevatedButton.styleFrom( - backgroundColor: widget.layoutColorForUser, + backgroundColor: isValid ? widget.layoutColorForUser : Colors.grey, foregroundColor: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8), side: BorderSide( - color: widget.layoutColorForUser, - width: 2, + // color: widget.layoutColorForUser, + color: isValid ? widget.layoutColorForUser : Colors.grey, + width: isValid ? 2 : 0, ), ), padding: EdgeInsets.symmetric(horizontal: 20, vertical: 12), ), - onPressed: () { - print( - "Submitting: ${_searchController.text}, ID: $userIdSelected", - ); - widget.onSubmit( - _searchController.text, - userIdSelected, - isTraveller, - ); - Navigator.pop(context); - }, + onPressed: isValid ? () { + print("Submitting: ${_searchController.text}, ID: $userIdSelected"); + widget.onSubmit( + _searchController.text, + userIdSelected, + isTraveller, + ); + Navigator.pop(context); + } + : null, child: Text( - "Submit", + "Save", style: GoogleFonts.poppins(fontSize: 11), ), ), diff --git a/lib/Screens/itnerary/accomodations.dart b/lib/Screens/itnerary/accomodations.dart index 9cef823..266b643 100644 --- a/lib/Screens/itnerary/accomodations.dart +++ b/lib/Screens/itnerary/accomodations.dart @@ -277,6 +277,7 @@ class _AccomodationScreenState extends State { List requiredFields = [ "destination_city", "hotel_name", + "class", "checkin_date", "checkin_time", "checkout_date", diff --git a/lib/Screens/itnerary/flights.dart b/lib/Screens/itnerary/flights.dart index 0130965..20f6ca5 100644 --- a/lib/Screens/itnerary/flights.dart +++ b/lib/Screens/itnerary/flights.dart @@ -649,6 +649,9 @@ class FlightScreenState extends State { errorMessages["date_$i"] = "Required"; } + if( selectedClasses[i] == null ) { + errorMessages["class_$i"] = "Required"; + } if (textControllers["_time${i}Controller"]?.text.trim().isEmpty ?? true) { errorMessages["time_$i"] = "Required"; }