From c22be68d7997f32322ad3c6c744c308309af2499 Mon Sep 17 00:00:00 2001 From: Sneha Canopas <92501869+cp-sneha-s@users.noreply.github.com> Date: Thu, 14 Mar 2024 11:27:19 +0530 Subject: [PATCH] Fix Minor UI Issues (#75) * Fix Minor UI Issues * Fix Minor UI Issues --- lib/data/core/utils/date_formatter.dart | 10 ++++---- .../shared/events/bloc/celebrations_bloc.dart | 23 ++++++++++++------- .../events/celebrations_event_card.dart | 6 +++-- lib/ui/shared/events/model/event.dart | 9 ++++++-- .../events/celebration_event_bloc_test.dart | 6 +++-- 5 files changed, 36 insertions(+), 18 deletions(-) diff --git a/lib/data/core/utils/date_formatter.dart b/lib/data/core/utils/date_formatter.dart index d9d2134f..af4b82e3 100644 --- a/lib/data/core/utils/date_formatter.dart +++ b/lib/data/core/utils/date_formatter.dart @@ -96,15 +96,17 @@ class DateFormatter { } String showAnniversaries( - {required DateTime dateOfJoining, required String name, int? number}) { + {required DateTime dateOfJoining, + required DateTime upcomingDate, + required String name, + int? number}) { final today = DateTime.now().dateOnly; final difference = dateOfJoining.difference(today); int yearDifference = (difference.inDays / 365).floor().abs(); - final upcomingAnniversaryDate = dateOfJoining.convertToUpcomingDay(); - if (upcomingAnniversaryDate.isAtSameMomentAs(today)) { + if (upcomingDate.isAtSameMomentAs(today)) { return _localization.present_anniversary_text(name, yearDifference); } else { - return "${_localization.upcoming_anniversary_text(name, yearDifference)} ${getDateRepresentation(upcomingAnniversaryDate).toLowerCase()}!🎉"; + return "${_localization.upcoming_anniversary_text(name, yearDifference)} ${getDateRepresentation(upcomingDate).toLowerCase()}!🎉"; } } diff --git a/lib/ui/shared/events/bloc/celebrations_bloc.dart b/lib/ui/shared/events/bloc/celebrations_bloc.dart index f0aa359e..285d1470 100644 --- a/lib/ui/shared/events/bloc/celebrations_bloc.dart +++ b/lib/ui/shared/events/bloc/celebrations_bloc.dart @@ -38,19 +38,26 @@ class CelebrationsBloc extends Bloc { final birthdate = e.dateOfBirth!.convertToUpcomingDay(); final Event event = Event( name: e.name, - dateTime: DateUtils.dateOnly(birthdate), + dateTime: DateUtils.dateOnly(e.dateOfBirth!), + upcomingDate: DateUtils.dateOnly(birthdate), imageUrl: e.imageUrl); allBirthdayEvents.add(event); } - final Event event = Event( - name: e.name, - dateTime: DateUtils.dateOnly(e.dateOfJoining), - imageUrl: e.imageUrl); - allAnniversaryEvents.add(event); + if (e.role != Role.admin) { + final upcomingDate = e.dateOfJoining.convertToUpcomingDay(); + final Event event = Event( + name: e.name, + dateTime: DateUtils.dateOnly(e.dateOfJoining), + upcomingDate: DateUtils.dateOnly(upcomingDate), + imageUrl: e.imageUrl); + allAnniversaryEvents.add(event); + } return e; }).toList(); - allBirthdayEvents.sort((a, b) => a.dateTime.compareTo(b.dateTime)); - allAnniversaryEvents.sort((a, b) => a.dateTime.compareTo(b.dateTime)); + allBirthdayEvents + .sort((a, b) => a.upcomingDate.compareTo(b.upcomingDate)); + allAnniversaryEvents + .sort((a, b) => a.upcomingDate.compareTo(b.upcomingDate)); currentWeekBday = _getBirthdays(); currentWeekAnniversaries = _getAnniversaries(); diff --git a/lib/ui/shared/events/celebrations_event_card.dart b/lib/ui/shared/events/celebrations_event_card.dart index 2ac6a8f8..6c8e1cf1 100644 --- a/lib/ui/shared/events/celebrations_event_card.dart +++ b/lib/ui/shared/events/celebrations_event_card.dart @@ -163,7 +163,7 @@ class EventsList extends StatelessWidget { ? AllEventCard( imageUrl: event.imageUrl, name: event.name, - date: event.dateTime) + date: event.upcomingDate) : CurrentWeekEventCard( event: event, isAnniversary: isAnniversary); }).toList(), @@ -200,7 +200,9 @@ class CurrentWeekEventCard extends StatelessWidget { Expanded( child: Text(isAnniversary ? DateFormatter(context.l10n).showAnniversaries( - dateOfJoining: event.dateTime, name: event.name) + dateOfJoining: event.dateTime, + upcomingDate: event.upcomingDate, + name: event.name) : DateFormatter(context.l10n).showBirthdays( dateTime: event.dateTime, name: event.name))), ], diff --git a/lib/ui/shared/events/model/event.dart b/lib/ui/shared/events/model/event.dart index 31f0dd97..131944ab 100644 --- a/lib/ui/shared/events/model/event.dart +++ b/lib/ui/shared/events/model/event.dart @@ -4,9 +4,14 @@ class Event extends Equatable { final String name; final String? imageUrl; final DateTime dateTime; + final DateTime upcomingDate; - const Event({required this.name, required this.dateTime, this.imageUrl}); + const Event( + {required this.name, + required this.dateTime, + this.imageUrl, + required this.upcomingDate}); @override - List get props => [name, imageUrl, dateTime]; + List get props => [name, imageUrl, dateTime, upcomingDate]; } diff --git a/test/unit_test/shared/events/celebration_event_bloc_test.dart b/test/unit_test/shared/events/celebration_event_bloc_test.dart index 7eb66766..8613ebf4 100644 --- a/test/unit_test/shared/events/celebration_event_bloc_test.dart +++ b/test/unit_test/shared/events/celebration_event_bloc_test.dart @@ -45,11 +45,13 @@ void main() { Event event = Event( name: employee1.name, - dateTime: employee1.dateOfBirth!.convertToUpcomingDay(), + dateTime: employee1.dateOfBirth!, + upcomingDate: employee1.dateOfBirth!.convertToUpcomingDay(), imageUrl: employee1.imageUrl); Event event2 = Event( name: employee2.name, - dateTime: employee2.dateOfBirth!.convertToUpcomingDay(), + dateTime: employee2.dateOfBirth!, + upcomingDate: employee2.dateOfBirth!.convertToUpcomingDay(), imageUrl: employee2.imageUrl); setUp(() {