chnaged the login api
This commit is contained in:
parent
3f3185c2f4
commit
3515cab0d5
@ -83,7 +83,7 @@ class AuthService {
|
|||||||
logSafe("Login payload (raw): $data");
|
logSafe("Login payload (raw): $data");
|
||||||
logSafe("Login payload (JSON): ${jsonEncode(data)}");
|
logSafe("Login payload (JSON): ${jsonEncode(data)}");
|
||||||
|
|
||||||
final responseData = await _post("/auth/app/login", data);
|
final responseData = await _post("/auth/login-mobile", data);
|
||||||
if (responseData == null)
|
if (responseData == null)
|
||||||
return {"error": "Network error. Please check your connection."};
|
return {"error": "Network error. Please check your connection."};
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ class AuthService {
|
|||||||
if (employeeInfo == null) return null;
|
if (employeeInfo == null) return null;
|
||||||
final token = await LocalStorage.getJwtToken();
|
final token = await LocalStorage.getJwtToken();
|
||||||
return _post(
|
return _post(
|
||||||
"/auth/login-mpin",
|
"/auth/login-mpin/v1",
|
||||||
{
|
{
|
||||||
"employeeId": employeeInfo.id,
|
"employeeId": employeeInfo.id,
|
||||||
"mpin": mpin,
|
"mpin": mpin,
|
||||||
@ -202,7 +202,7 @@ class AuthService {
|
|||||||
required String email,
|
required String email,
|
||||||
required String otp,
|
required String otp,
|
||||||
}) async {
|
}) async {
|
||||||
final data = await _post("/auth/login-otp", {"email": email, "otp": otp});
|
final data = await _post("/auth/login-otp/v1", {"email": email, "otp": otp});
|
||||||
if (data != null && data['data'] != null) {
|
if (data != null && data['data'] != null) {
|
||||||
await _handleLoginSuccess(data['data']);
|
await _handleLoginSuccess(data['data']);
|
||||||
return null;
|
return null;
|
||||||
|
@ -4,6 +4,7 @@ import 'package:marco/helpers/widgets/my_text.dart';
|
|||||||
|
|
||||||
class BaseBottomSheet extends StatelessWidget {
|
class BaseBottomSheet extends StatelessWidget {
|
||||||
final String title;
|
final String title;
|
||||||
|
final String? subtitle;
|
||||||
final Widget child;
|
final Widget child;
|
||||||
final VoidCallback onCancel;
|
final VoidCallback onCancel;
|
||||||
final VoidCallback onSubmit;
|
final VoidCallback onSubmit;
|
||||||
@ -20,6 +21,7 @@ class BaseBottomSheet extends StatelessWidget {
|
|||||||
required this.child,
|
required this.child,
|
||||||
required this.onCancel,
|
required this.onCancel,
|
||||||
required this.onSubmit,
|
required this.onSubmit,
|
||||||
|
this.subtitle,
|
||||||
this.isSubmitting = false,
|
this.isSubmitting = false,
|
||||||
this.submitText = 'Submit',
|
this.submitText = 'Submit',
|
||||||
this.submitColor = Colors.indigo,
|
this.submitColor = Colors.indigo,
|
||||||
@ -50,24 +52,37 @@ class BaseBottomSheet extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
// 👈 prevents overlap with nav bar
|
|
||||||
top: false,
|
top: false,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 32),
|
padding: const EdgeInsets.fromLTRB(20, 16, 20, 32),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
MySpacing.height(5),
|
MySpacing.height(5),
|
||||||
Container(
|
Center(
|
||||||
width: 40,
|
child: Container(
|
||||||
height: 5,
|
width: 40,
|
||||||
decoration: BoxDecoration(
|
height: 5,
|
||||||
color: Colors.grey.shade300,
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(10),
|
color: Colors.grey.shade300,
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
MySpacing.height(12),
|
MySpacing.height(12),
|
||||||
MyText.titleLarge(title, fontWeight: 700),
|
MyText.titleLarge(title, fontWeight: 700),
|
||||||
|
|
||||||
|
// ✅ Subtitle shown just below header if provided
|
||||||
|
if (subtitle != null && subtitle!.isNotEmpty) ...[
|
||||||
|
MySpacing.height(4),
|
||||||
|
MyText.bodySmall(
|
||||||
|
subtitle!,
|
||||||
|
fontWeight: 600,
|
||||||
|
color: Colors.grey[700],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
|
||||||
MySpacing.height(12),
|
MySpacing.height(12),
|
||||||
child,
|
child,
|
||||||
MySpacing.height(12),
|
MySpacing.height(12),
|
||||||
|
@ -7,6 +7,7 @@ import 'package:marco/controller/attendance/attendance_screen_controller.dart';
|
|||||||
import 'package:marco/helpers/utils/attendance_actions.dart';
|
import 'package:marco/helpers/utils/attendance_actions.dart';
|
||||||
import 'package:marco/controller/project_controller.dart';
|
import 'package:marco/controller/project_controller.dart';
|
||||||
import 'package:marco/helpers/utils/base_bottom_sheet.dart';
|
import 'package:marco/helpers/utils/base_bottom_sheet.dart';
|
||||||
|
import 'package:marco/helpers/widgets/my_text.dart';
|
||||||
|
|
||||||
class AttendanceActionButton extends StatefulWidget {
|
class AttendanceActionButton extends StatefulWidget {
|
||||||
final dynamic employee;
|
final dynamic employee;
|
||||||
@ -84,6 +85,8 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
|
|||||||
final controller = widget.attendanceController;
|
final controller = widget.attendanceController;
|
||||||
final projectController = Get.find<ProjectController>();
|
final projectController = Get.find<ProjectController>();
|
||||||
final selectedProjectId = projectController.selectedProject?.id;
|
final selectedProjectId = projectController.selectedProject?.id;
|
||||||
|
final projectName =
|
||||||
|
projectController.selectedProject?.name ?? 'Unknown Project';
|
||||||
|
|
||||||
if (selectedProjectId == null) {
|
if (selectedProjectId == null) {
|
||||||
showAppSnackbar(
|
showAppSnackbar(
|
||||||
@ -108,8 +111,10 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
final isOldCheckIn = AttendanceButtonHelper.isOlderThanDays(widget.employee.checkIn, 2);
|
final isOldCheckIn =
|
||||||
final isOldCheckOut = AttendanceButtonHelper.isOlderThanDays(widget.employee.checkOut, 2);
|
AttendanceButtonHelper.isOlderThanDays(widget.employee.checkIn, 2);
|
||||||
|
final isOldCheckOut =
|
||||||
|
AttendanceButtonHelper.isOlderThanDays(widget.employee.checkOut, 2);
|
||||||
|
|
||||||
if (widget.employee.checkOut == null && isOldCheckIn) {
|
if (widget.employee.checkOut == null && isOldCheckIn) {
|
||||||
action = 2;
|
action = 2;
|
||||||
@ -158,7 +163,9 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
|
|||||||
actionText,
|
actionText,
|
||||||
selectedTime: selectedTime,
|
selectedTime: selectedTime,
|
||||||
checkInDate: widget.employee.checkIn,
|
checkInDate: widget.employee.checkIn,
|
||||||
|
projectName: projectName,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (comment == null || comment.isEmpty) {
|
if (comment == null || comment.isEmpty) {
|
||||||
controller.uploadingStates[uniqueLogKey]?.value = false;
|
controller.uploadingStates[uniqueLogKey]?.value = false;
|
||||||
return;
|
return;
|
||||||
@ -167,7 +174,9 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
|
|||||||
String? markTime;
|
String? markTime;
|
||||||
if (actionText == ButtonActions.requestRegularize) {
|
if (actionText == ButtonActions.requestRegularize) {
|
||||||
selectedTime ??= await _pickRegularizationTime(widget.employee.checkIn!);
|
selectedTime ??= await _pickRegularizationTime(widget.employee.checkIn!);
|
||||||
markTime = selectedTime != null ? DateFormat("hh:mm a").format(selectedTime) : null;
|
markTime = selectedTime != null
|
||||||
|
? DateFormat("hh:mm a").format(selectedTime)
|
||||||
|
: null;
|
||||||
} else if (selectedTime != null) {
|
} else if (selectedTime != null) {
|
||||||
markTime = DateFormat("hh:mm a").format(selectedTime);
|
markTime = DateFormat("hh:mm a").format(selectedTime);
|
||||||
}
|
}
|
||||||
@ -205,13 +214,17 @@ class _AttendanceActionButtonState extends State<AttendanceActionButton> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
final controller = widget.attendanceController;
|
final controller = widget.attendanceController;
|
||||||
final isUploading = controller.uploadingStates[uniqueLogKey]?.value ?? false;
|
final isUploading =
|
||||||
|
controller.uploadingStates[uniqueLogKey]?.value ?? false;
|
||||||
final emp = widget.employee;
|
final emp = widget.employee;
|
||||||
|
|
||||||
final isYesterday = AttendanceButtonHelper.isLogFromYesterday(emp.checkIn, emp.checkOut);
|
final isYesterday =
|
||||||
final isTodayApproved = AttendanceButtonHelper.isTodayApproved(emp.activity, emp.checkIn);
|
AttendanceButtonHelper.isLogFromYesterday(emp.checkIn, emp.checkOut);
|
||||||
|
final isTodayApproved =
|
||||||
|
AttendanceButtonHelper.isTodayApproved(emp.activity, emp.checkIn);
|
||||||
final isApprovedButNotToday =
|
final isApprovedButNotToday =
|
||||||
AttendanceButtonHelper.isApprovedButNotToday(emp.activity, isTodayApproved);
|
AttendanceButtonHelper.isApprovedButNotToday(
|
||||||
|
emp.activity, isTodayApproved);
|
||||||
|
|
||||||
final isButtonDisabled = AttendanceButtonHelper.isButtonDisabled(
|
final isButtonDisabled = AttendanceButtonHelper.isButtonDisabled(
|
||||||
isUploading: isUploading,
|
isUploading: isUploading,
|
||||||
@ -288,15 +301,17 @@ class AttendanceActionButtonUI extends StatelessWidget {
|
|||||||
if (buttonText.toLowerCase() == 'rejected')
|
if (buttonText.toLowerCase() == 'rejected')
|
||||||
const Icon(Icons.close, size: 16, color: Colors.red),
|
const Icon(Icons.close, size: 16, color: Colors.red),
|
||||||
if (buttonText.toLowerCase() == 'requested')
|
if (buttonText.toLowerCase() == 'requested')
|
||||||
const Icon(Icons.hourglass_top, size: 16, color: Colors.orange),
|
const Icon(Icons.hourglass_top,
|
||||||
|
size: 16, color: Colors.orange),
|
||||||
if (['approved', 'rejected', 'requested']
|
if (['approved', 'rejected', 'requested']
|
||||||
.contains(buttonText.toLowerCase()))
|
.contains(buttonText.toLowerCase()))
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
Flexible(
|
Flexible(
|
||||||
child: Text(
|
child: MyText.bodySmall(
|
||||||
buttonText,
|
buttonText,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: const TextStyle(fontSize: 12),
|
fontWeight: 500,
|
||||||
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -311,15 +326,18 @@ Future<String?> _showCommentBottomSheet(
|
|||||||
String actionText, {
|
String actionText, {
|
||||||
DateTime? selectedTime,
|
DateTime? selectedTime,
|
||||||
DateTime? checkInDate,
|
DateTime? checkInDate,
|
||||||
|
String? projectName,
|
||||||
}) async {
|
}) async {
|
||||||
final commentController = TextEditingController();
|
final commentController = TextEditingController();
|
||||||
String? errorText;
|
String? errorText;
|
||||||
|
|
||||||
// Prepare title
|
String sheetTitle =
|
||||||
String sheetTitle = "Add Comment for ${capitalizeFirstLetter(actionText)}";
|
"Adding Comment for ${capitalizeFirstLetter(actionText)}";
|
||||||
if (selectedTime != null && checkInDate != null) {
|
if (selectedTime != null && checkInDate != null) {
|
||||||
sheetTitle =
|
sheetTitle =
|
||||||
"${capitalizeFirstLetter(actionText)} for ${DateFormat('dd MMM yyyy').format(checkInDate)} at ${DateFormat('hh:mm a').format(selectedTime)}";
|
"${capitalizeFirstLetter(actionText)} • ${DateFormat('dd MMM yyyy').format(checkInDate)} "
|
||||||
|
"at ${DateFormat('hh:mm a').format(selectedTime)}\n"
|
||||||
|
"${projectName ?? 'Project'}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return showModalBottomSheet<String>(
|
return showModalBottomSheet<String>(
|
||||||
@ -342,30 +360,42 @@ Future<String?> _showCommentBottomSheet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
|
padding: EdgeInsets.only(
|
||||||
|
bottom: MediaQuery.of(context).viewInsets.bottom),
|
||||||
child: BaseBottomSheet(
|
child: BaseBottomSheet(
|
||||||
title: sheetTitle, // 👈 now showing full sentence as title
|
title: sheetTitle,
|
||||||
|
subtitle: projectName,
|
||||||
onCancel: () => Navigator.of(context).pop(),
|
onCancel: () => Navigator.of(context).pop(),
|
||||||
onSubmit: submit,
|
onSubmit: submit,
|
||||||
isSubmitting: false,
|
isSubmitting: false,
|
||||||
submitText: 'Submit',
|
submitText: 'Submit',
|
||||||
child: TextField(
|
child: Column(
|
||||||
controller: commentController,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
maxLines: 4,
|
children: [
|
||||||
decoration: InputDecoration(
|
MyText.bodyMedium(
|
||||||
hintText: 'Type your comment here...',
|
'Add a comment to proceed',
|
||||||
border: OutlineInputBorder(
|
fontWeight: 500,
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
),
|
||||||
filled: true,
|
const SizedBox(height: 8),
|
||||||
fillColor: Colors.grey.shade100,
|
TextField(
|
||||||
errorText: errorText,
|
controller: commentController,
|
||||||
),
|
maxLines: 4,
|
||||||
onChanged: (_) {
|
decoration: InputDecoration(
|
||||||
if (errorText != null) {
|
hintText: 'Type your comment here...',
|
||||||
setModalState(() => errorText = null);
|
border: OutlineInputBorder(
|
||||||
}
|
borderRadius: BorderRadius.circular(8),
|
||||||
},
|
),
|
||||||
|
filled: true,
|
||||||
|
fillColor: Colors.grey.shade100,
|
||||||
|
errorText: errorText,
|
||||||
|
),
|
||||||
|
onChanged: (_) {
|
||||||
|
if (errorText != null) {
|
||||||
|
setModalState(() => errorText = null);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -375,6 +405,5 @@ Future<String?> _showCommentBottomSheet(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String capitalizeFirstLetter(String text) =>
|
String capitalizeFirstLetter(String text) =>
|
||||||
text.isEmpty ? text : text[0].toUpperCase() + text.substring(1);
|
text.isEmpty ? text : text[0].toUpperCase() + text.substring(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user