resolved the email and has application acccess is not populated on edit

This commit is contained in:
Vaibhav Surve 2025-10-01 16:59:15 +05:30
parent 843f394ebe
commit a1bd9a3108
4 changed files with 187 additions and 159 deletions

View File

@ -74,12 +74,17 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
ever(controller.isInitialized, (bool ready) {
if (ready) {
// Buckets - map all
if (c.bucketIds.isNotEmpty) {
final names = c.bucketIds.map((id) {
return controller.bucketsMap.entries
.firstWhereOrNull((e) => e.value == id)
?.key;
}).whereType<String>().toList();
controller.selectedBuckets.assignAll(names);
}
// Projects and Category mapping - as before
final projectIds = c.projectIds;
final bucketId = c.bucketIds.firstOrNull;
final category = c.contactCategory?.name;
if (category != null) controller.selectedCategory.value = category;
if (projectIds != null) {
controller.selectedProjects.assignAll(
projectIds
@ -90,18 +95,12 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
.toList(),
);
}
if (bucketId != null) {
final name = controller.bucketsMap.entries
.firstWhereOrNull((e) => e.value == bucketId)
?.key;
if (name != null && !controller.selectedBuckets.contains(name)) {
controller.selectedBuckets.add(name);
}
}
final category = c.contactCategory?.name;
if (category != null) controller.selectedCategory.value = category;
}
});
} else {
showAdvanced.value = false; // Optional
emailCtrls.add(TextEditingController());
emailLabels.add('Office'.obs);
phoneCtrls.add(TextEditingController());
@ -382,16 +381,12 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
}) {
if (items.isEmpty) return const SizedBox.shrink();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Obx(() {
return Obx(() {
final selectedNames = items
.where((f) => selectedValues.contains(f.id))
.map((f) => f.name)
.join(", ");
final displayText =
selectedNames.isNotEmpty ? selectedNames : fallback;
final displayText = selectedNames.isNotEmpty ? selectedNames : fallback;
return Builder(
builder: (context) {
@ -399,10 +394,8 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
onTap: () async {
final RenderBox button =
context.findRenderObject() as RenderBox;
final RenderBox overlay = Overlay.of(context)
.context
.findRenderObject() as RenderBox;
final RenderBox overlay =
Overlay.of(context).context.findRenderObject() as RenderBox;
final position = button.localToGlobal(Offset.zero);
await showMenu(
@ -413,30 +406,32 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
overlay.size.width - position.dx - button.size.width,
0,
),
items: items.map((f) {
return PopupMenuItem<String>(
items: [
PopupMenuItem(
enabled: false,
child: StatefulBuilder(
builder: (context, setState) {
return SizedBox(
width: 250,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: items.map((f) {
final isChecked = selectedValues.contains(f.id);
return CheckboxListTile(
dense: true,
title: Text(f.name),
value: isChecked,
contentPadding: EdgeInsets.zero,
controlAffinity: ListTileControlAffinity.leading,
title: MyText(f.name),
checkColor: Colors.white,
side: const BorderSide(
color: Colors.black, width: 1.5),
fillColor:
MaterialStateProperty.resolveWith<Color>(
(states) {
side: const BorderSide(color: Colors.black, width: 1.5),
fillColor: MaterialStateProperty.resolveWith<Color>((states) {
if (states.contains(MaterialState.selected)) {
return Colors.indigo;
return Colors.indigo; // selected color
}
return Colors.white;
},
),
return Colors.white; // unselected background
}),
checkColor: Colors.white, // tick color
onChanged: (val) {
if (val == true) {
selectedValues.add(f.id);
@ -446,10 +441,14 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
setState(() {});
},
);
},
}).toList(),
),
),
);
}).toList(),
},
),
),
],
);
},
child: Container(
@ -476,12 +475,10 @@ class _AddContactBottomSheetState extends State<AddContactBottomSheet> {
);
},
);
}),
MySpacing.height(16),
],
);
});
}
void _handleSubmit() {
bool valid = formKey.currentState?.validate() ?? false;

View File

@ -36,7 +36,7 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
@override
void initState() {
super.initState();
_orgFieldController = TextEditingController();
_joiningDateController = TextEditingController();
_genderController = TextEditingController();
_roleController = TextEditingController();
@ -46,17 +46,33 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
if (widget.employeeData != null) {
_controller.editingEmployeeData = widget.employeeData;
_controller.prefillFields();
// 👇 joining date & gender already handled in your code
// Prepopulate hasApplicationAccess and email
_hasApplicationAccess =
widget.employeeData?['hasApplicationAccess'] ?? false;
final email = widget.employeeData?['email'];
if (email != null && email.toString().isNotEmpty) {
_controller.basicValidator.getController('email')?.text =
email.toString();
}
// Trigger UI rebuild to reflect email & checkbox
setState(() {});
// Joining date
if (_controller.joiningDate != null) {
_joiningDateController.text =
DateFormat('dd MMM yyyy').format(_controller.joiningDate!);
}
// Gender
if (_controller.selectedGender != null) {
_genderController.text =
_controller.selectedGender!.name.capitalizeFirst ?? '';
}
// Important part: fetch roles, then set roleController
// Role
_controller.fetchRoles().then((_) {
if (_controller.selectedRoleId != null) {
final roleName = _controller.roles.firstWhereOrNull(
@ -65,6 +81,7 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
if (roleName != null) {
_roleController.text = roleName;
}
_controller.update();
}
});
} else {

View File

@ -12,15 +12,17 @@ class EmployeeDetailsModel {
final String phoneNumber;
final String? emergencyPhoneNumber;
final String? emergencyContactPerson;
final String? aadharNumber;
final bool isActive;
final String? panNumber;
final String? photo;
final String? applicationUserId;
final String jobRoleId;
final bool isRootUser;
final bool isSystem;
final String jobRole;
final String jobRoleId;
final String? photo;
final String? applicationUserId;
final bool hasApplicationAccess;
final String? organizationId;
final String? aadharNumber;
final String? panNumber;
EmployeeDetailsModel({
required this.id,
required this.firstName,
@ -35,14 +37,17 @@ class EmployeeDetailsModel {
required this.phoneNumber,
this.emergencyPhoneNumber,
this.emergencyContactPerson,
this.aadharNumber,
required this.isActive,
this.panNumber,
this.photo,
this.applicationUserId,
required this.jobRoleId,
required this.isRootUser,
required this.isSystem,
required this.jobRole,
required this.jobRoleId,
this.photo,
this.applicationUserId,
required this.hasApplicationAccess,
this.organizationId,
this.aadharNumber,
this.panNumber,
});
factory EmployeeDetailsModel.fromJson(Map<String, dynamic> json) {
@ -60,24 +65,20 @@ class EmployeeDetailsModel {
phoneNumber: json['phoneNumber'],
emergencyPhoneNumber: json['emergencyPhoneNumber'],
emergencyContactPerson: json['emergencyContactPerson'],
aadharNumber: json['aadharNumber'],
isActive: json['isActive'],
panNumber: json['panNumber'],
photo: json['photo'],
applicationUserId: json['applicationUserId'],
jobRoleId: json['jobRoleId'],
isRootUser: json['isRootUser'],
isSystem: json['isSystem'],
jobRole: json['jobRole'],
jobRoleId: json['jobRoleId'],
photo: json['photo'],
applicationUserId: json['applicationUserId'],
hasApplicationAccess: json['hasApplicationAccess'],
organizationId: json['organizationId'],
aadharNumber: json['aadharNumber'],
panNumber: json['panNumber'],
);
}
static DateTime? _parseDate(String? dateStr) {
if (dateStr == null || dateStr == "0001-01-01T00:00:00") {
return null;
}
return DateTime.tryParse(dateStr);
}
Map<String, dynamic> toJson() {
return {
'id': id,
@ -93,14 +94,24 @@ class EmployeeDetailsModel {
'phoneNumber': phoneNumber,
'emergencyPhoneNumber': emergencyPhoneNumber,
'emergencyContactPerson': emergencyContactPerson,
'aadharNumber': aadharNumber,
'isActive': isActive,
'panNumber': panNumber,
'photo': photo,
'applicationUserId': applicationUserId,
'jobRoleId': jobRoleId,
'isRootUser': isRootUser,
'isSystem': isSystem,
'jobRole': jobRole,
'jobRoleId': jobRoleId,
'photo': photo,
'applicationUserId': applicationUserId,
'hasApplicationAccess': hasApplicationAccess,
'organizationId': organizationId,
'aadharNumber': aadharNumber,
'panNumber': panNumber,
};
}
static DateTime? _parseDate(String? dateStr) {
if (dateStr == null || dateStr == "0001-01-01T00:00:00") {
return null;
}
return DateTime.tryParse(dateStr);
}
}

View File

@ -261,6 +261,9 @@ class _EmployeeDetailPageState extends State<EmployeeDetailPage> {
'first_name': employee.firstName,
'last_name': employee.lastName,
'phone_number': employee.phoneNumber,
'email': employee.email,
'hasApplicationAccess':
employee.hasApplicationAccess,
'gender': employee.gender.toLowerCase(),
'job_role_id': employee.jobRoleId,
'joining_date':