Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add duration in new leave notification #52

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/data/core/functions/shared_function.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:injectable/injectable.dart';
import '../../model/leave/leave.dart';

@Injectable()
class AppFunctions {
Expand All @@ -19,4 +20,22 @@ class AppFunctions {
return true;
}
}

String getNotificationDuration(
{required double total,
required LeaveDayDuration firstLeaveDayDuration}) {
if (total <= 1) {
if (firstLeaveDayDuration == LeaveDayDuration.firstHalfLeave) {
return "First Half";
} else if (firstLeaveDayDuration == LeaveDayDuration.secondHalfLeave) {
return "Second Half";
} else if (firstLeaveDayDuration == LeaveDayDuration.fullLeave) {
return "Full day";
} else {
return "$total day";
}
} else {
return "$total days";
}
}
}
2 changes: 2 additions & 0 deletions lib/data/services/mail_notification_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class NotificationService {
{required String name,
required String reason,
required DateTime startDate,
required String duration,
required DateTime endDate,
required String receiver}) async {
if (kDebugMode) return;
Expand All @@ -36,6 +37,7 @@ class NotificationService {
"date": getFormatDate(startDate: startDate, endDate: endDate),
"status": LeaveStatus.pending.value,
'reason': reason,
'duration': duration,
'receiver': receiver,
}));
if (response.statusCode == 200) {
Expand Down
14 changes: 9 additions & 5 deletions lib/ui/user/leaves/apply_leave/bloc/apply_leave_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,15 @@ class ApplyLeaveBloc extends Bloc<ApplyLeaveEvent, ApplyLeaveState>
_userStateNotifier.currentSpace!.notificationEmail;
if (notificationEmail != null) {
await _notificationService.notifyHRForNewLeave(
name: _userStateNotifier.employee.name,
startDate: leaveData.startDate,
endDate: leaveData.endDate,
reason: leaveData.reason,
receiver: notificationEmail);
name: _userStateNotifier.employee.name,
startDate: leaveData.startDate,
endDate: leaveData.endDate,
reason: leaveData.reason,
receiver: notificationEmail,
duration: _appFunctions.getNotificationDuration(
total: leaveData.total,
firstLeaveDayDuration: leaveData.perDayDuration.first),
);
}
emit(state.copyWith(
leaveRequestStatus: Status.success, leaveId: leaveData.leaveId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ class MockNotificationService extends _i1.Mock
required String? name,
required String? reason,
required DateTime? startDate,
required String? duration,
required DateTime? endDate,
required String? receiver,
}) =>
Expand All @@ -444,6 +445,7 @@ class MockNotificationService extends _i1.Mock
#name: name,
#reason: reason,
#startDate: startDate,
#duration: duration,
#endDate: endDate,
#receiver: receiver,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ class MockNotificationService extends _i1.Mock
required String? name,
required String? reason,
required DateTime? startDate,
required String? duration,
required DateTime? endDate,
required String? receiver,
}) =>
Expand All @@ -506,6 +507,7 @@ class MockNotificationService extends _i1.Mock
#name: name,
#reason: reason,
#startDate: startDate,
#duration: duration,
#endDate: endDate,
#receiver: receiver,
},
Expand Down
2 changes: 2 additions & 0 deletions test/unit_test/space/join_space/join_space_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ class MockNotificationService extends _i1.Mock
required String? name,
required String? reason,
required DateTime? startDate,
required String? duration,
required DateTime? endDate,
required String? receiver,
}) =>
Expand All @@ -712,6 +713,7 @@ class MockNotificationService extends _i1.Mock
#name: name,
#reason: reason,
#startDate: startDate,
#duration: duration,
#endDate: endDate,
#receiver: receiver,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ void main() {
receiver: '[email protected]',
name: "dummy",
startDate: leave.startDate,
duration: appFunctions.getNotificationDuration(total: leave.total, firstLeaveDayDuration:leave.perDayDuration.first),
endDate: leave.endDate))
.thenAnswer((realInvocation) async => true);
leaveRequestBloc.add(ApplyLeaveEndDateChangeEvent(endDate: futureDate));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ class MockNotificationService extends _i1.Mock
required String? name,
required String? reason,
required DateTime? startDate,
required String? duration,
required DateTime? endDate,
required String? receiver,
}) =>
Expand All @@ -406,6 +407,7 @@ class MockNotificationService extends _i1.Mock
#name: name,
#reason: reason,
#startDate: startDate,
#duration: duration,
#endDate: endDate,
#receiver: receiver,
},
Expand Down
Loading