made chnages for all employee

This commit is contained in:
Vaibhav Surve 2025-08-07 17:14:04 +05:30
parent 10e4a6e514
commit 7175ade940
6 changed files with 118 additions and 176 deletions

View File

@ -22,42 +22,6 @@ class AddEmployeeController extends MyController {
Gender? selectedGender; Gender? selectedGender;
List<Map<String, dynamic>> roles = []; List<Map<String, dynamic>> roles = [];
String? selectedRoleId; String? selectedRoleId;
final List<Map<String, String>> countries = [
{"code": "+91", "name": "India"},
{"code": "+1", "name": "USA"},
{"code": "+971", "name": "UAE"},
{"code": "+44", "name": "UK"},
{"code": "+81", "name": "Japan"},
{"code": "+61", "name": "Australia"},
{"code": "+49", "name": "Germany"},
{"code": "+33", "name": "France"},
{"code": "+86", "name": "China"},
];
final Map<String, int> minDigitsPerCountry = {
"+91": 10,
"+1": 10,
"+971": 9,
"+44": 10,
"+81": 10,
"+61": 9,
"+49": 10,
"+33": 9,
"+86": 11,
};
final Map<String, int> maxDigitsPerCountry = {
"+91": 10,
"+1": 10,
"+971": 9,
"+44": 11,
"+81": 10,
"+61": 9,
"+49": 11,
"+33": 9,
"+86": 11,
};
String selectedCountryCode = "+91"; String selectedCountryCode = "+91";
bool showOnline = true; bool showOnline = true;
final List<String> categories = []; final List<String> categories = [];

View File

@ -1180,8 +1180,9 @@ class ApiService {
static Future<List<dynamic>?> getAllEmployeesByProject( static Future<List<dynamic>?> getAllEmployeesByProject(
String projectId) async { String projectId) async {
if (projectId.isEmpty) throw ArgumentError('projectId must not be empty'); if (projectId.isEmpty) throw ArgumentError('projectId must not be empty');
final endpoint =
"${ApiEndpoints.getAllEmployeesByProject}?projectId=$projectId"; final endpoint = "${ApiEndpoints.getAllEmployeesByProject}/$projectId";
return _getRequest(endpoint).then( return _getRequest(endpoint).then(
(res) => res != null (res) => res != null
? _parseResponse(res, label: 'Employees by Project') ? _parseResponse(res, label: 'Employees by Project')

View File

@ -147,7 +147,8 @@ class AuthService {
required String mpin, required String mpin,
}) async { }) async {
final token = await LocalStorage.getJwtToken(); final token = await LocalStorage.getJwtToken();
logSafe("Generating MPIN for employeeId: $employeeId");
logSafe("MPIN: $mpin");
try { try {
logSafe("Generating MPIN..."); logSafe("Generating MPIN...");
final response = await http.post( final response = await http.post(

View File

@ -147,7 +147,12 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
// Phone input with country code selector // Phone input with country code selector
Widget _buildPhoneInput(BuildContext context) { Widget _buildPhoneInput(BuildContext context) {
return Row( return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MyText.labelMedium("Phone Number"),
MySpacing.height(8),
Row(
children: [ children: [
Container( Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14), padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
@ -156,37 +161,7 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
color: Colors.grey.shade100, color: Colors.grey.shade100,
), ),
child: PopupMenuButton<Map<String, String>>( child: Text("+91"),
onSelected: (country) {
_controller.selectedCountryCode = country['code']!;
_controller.update();
},
itemBuilder: (context) => [
PopupMenuItem(
enabled: false,
padding: EdgeInsets.zero,
child: SizedBox(
height: 200,
width: 100,
child: ListView(
children: _controller.countries.map((country) {
return ListTile(
dense: true,
title: Text("${country['name']} (${country['code']})"),
onTap: () => Navigator.pop(context, country),
);
}).toList(),
),
),
),
],
child: Row(
children: [
Text(_controller.selectedCountryCode),
const Icon(Icons.arrow_drop_down),
],
),
),
), ),
MySpacing.width(12), MySpacing.width(12),
Expanded( Expanded(
@ -198,21 +173,8 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
return "Phone number is required"; return "Phone number is required";
} }
final digitsOnly = value.trim(); if (!RegExp(r'^\d{10}$').hasMatch(value.trim())) {
final minLength = _controller return "Enter a valid 10-digit number";
.minDigitsPerCountry[_controller.selectedCountryCode] ??
7;
final maxLength = _controller
.maxDigitsPerCountry[_controller.selectedCountryCode] ??
15;
if (!RegExp(r'^[0-9]+$').hasMatch(digitsOnly)) {
return "Only digits allowed";
}
if (digitsOnly.length < minLength ||
digitsOnly.length > maxLength) {
return "Between $minLength$maxLength digits";
} }
return null; return null;
@ -220,7 +182,7 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
keyboardType: TextInputType.phone, keyboardType: TextInputType.phone,
inputFormatters: [ inputFormatters: [
FilteringTextInputFormatter.digitsOnly, FilteringTextInputFormatter.digitsOnly,
LengthLimitingTextInputFormatter(15), LengthLimitingTextInputFormatter(10),
], ],
decoration: _inputDecoration("e.g., 9876543210").copyWith( decoration: _inputDecoration("e.g., 9876543210").copyWith(
suffixIcon: IconButton( suffixIcon: IconButton(
@ -231,6 +193,8 @@ class _AddEmployeeBottomSheetState extends State<AddEmployeeBottomSheet>
), ),
), ),
], ],
),
],
); );
} }

View File

@ -83,21 +83,27 @@ class _EmployeesScreenState extends State<EmployeesScreen> with UIMixin {
void _filterEmployees(String query) { void _filterEmployees(String query) {
final employees = _employeeController.employees; final employees = _employeeController.employees;
if (query.isEmpty) { List<EmployeeModel> filtered;
_filteredEmployees.assignAll(employees);
return;
}
if (query.isEmpty) {
filtered = List<EmployeeModel>.from(employees);
} else {
final q = query.toLowerCase(); final q = query.toLowerCase();
_filteredEmployees.assignAll( filtered = employees
employees.where( .where(
(e) => (e) =>
e.name.toLowerCase().contains(q) || e.name.toLowerCase().contains(q) ||
e.email.toLowerCase().contains(q) || e.email.toLowerCase().contains(q) ||
e.phoneNumber.toLowerCase().contains(q) || e.phoneNumber.toLowerCase().contains(q) ||
e.jobRole.toLowerCase().contains(q), e.jobRole.toLowerCase().contains(q),
), )
); .toList();
}
filtered
.sort((a, b) => a.name.toLowerCase().compareTo(b.name.toLowerCase()));
_filteredEmployees.assignAll(filtered);
} }
Future<void> _onAddNewEmployee() async { Future<void> _onAddNewEmployee() async {
@ -225,8 +231,7 @@ class _EmployeesScreenState extends State<EmployeesScreen> with UIMixin {
Widget _buildFloatingActionButton() { Widget _buildFloatingActionButton() {
if (!_permissionController.hasPermission(Permissions.manageEmployees)) { if (!_permissionController.hasPermission(Permissions.manageEmployees)) {
return const SizedBox return const SizedBox.shrink();
.shrink();
} }
return InkWell( return InkWell(

View File

@ -129,12 +129,16 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Obx(() { Obx(() {
return SegmentedButton<String>( return SizedBox(
width: double.infinity, // Make it full width
child: SegmentedButton<String>(
segments: expenseController.dateTypes segments: expenseController.dateTypes
.map( .map(
(type) => ButtonSegment( (type) => ButtonSegment(
value: type, value: type,
label: MyText( label: Center(
// Center label text
child: MyText(
type, type,
style: MyTextStyle.bodySmall( style: MyTextStyle.bodySmall(
fontWeight: 600, fontWeight: 600,
@ -143,12 +147,14 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
), ),
), ),
), ),
),
) )
.toList(), .toList(),
selected: {expenseController.selectedDateType.value}, selected: {expenseController.selectedDateType.value},
onSelectionChanged: (newSelection) { onSelectionChanged: (newSelection) {
if (newSelection.isNotEmpty) { if (newSelection.isNotEmpty) {
expenseController.selectedDateType.value = newSelection.first; expenseController.selectedDateType.value =
newSelection.first;
} }
}, },
style: ButtonStyle( style: ButtonStyle(
@ -181,6 +187,7 @@ class ExpenseFilterBottomSheet extends StatelessWidget {
), ),
), ),
), ),
),
); );
}), }),
MySpacing.height(16), MySpacing.height(16),