From 70e9b18c25ac09415fdd7a1aa62047b4ed0f448e Mon Sep 17 00:00:00 2001 From: Aayushmaan Date: Fri, 19 Apr 2024 00:56:07 +0530 Subject: [PATCH] rfac: removes isCouponOutdated from week_menu_tmp.dart --- lib/domain/models/menu/week_menu_tmp.dart | 7 ------- .../week_menu/bloc/week_menu_bloc.dart | 4 ++++ .../components/DayMenu/menu_card.dart | 18 +++++------------- lib/presentation/week_menu/menu_view.dart | 12 +++++++++++- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/lib/domain/models/menu/week_menu_tmp.dart b/lib/domain/models/menu/week_menu_tmp.dart index 5bbb548d..84471ba0 100644 --- a/lib/domain/models/menu/week_menu_tmp.dart +++ b/lib/domain/models/menu/week_menu_tmp.dart @@ -182,7 +182,6 @@ class Meal { String? secretCode; bool isOutdated; bool isLeaveToggleOutdated; - bool isCouponOutdated; DateTime startDateTime; DateTime endDateTime; @@ -201,7 +200,6 @@ class Meal { this.secretCode, required this.isOutdated, required this.isLeaveToggleOutdated, - required this.isCouponOutdated, required this.startDateTime, required this.endDateTime, required this.couponStatus, @@ -229,10 +227,6 @@ class Meal { !DateTimeUtils.getDateTimeFromDateAndTime(date, json['start_time']) .subtract(outdatedTime) .isAfter(DateTime.now()), - isCouponOutdated: - !DateTimeUtils.getDateTimeFromDateAndTime(date, json['start_time']) - .subtract(outdatedTime * 2) - .isAfter(DateTime.now()), startDateTime: DateTimeUtils.getDateTimeFromDateAndTime(date, json['start_time']), endDateTime: @@ -291,7 +285,6 @@ class Meal { isLeaveToggleOutdated: isLeaveToggleOutdated ?? this.isLeaveToggleOutdated, isOutdated: isOutdated ?? this.isOutdated, - isCouponOutdated: isCouponOutdated ?? this.isCouponOutdated, startDateTime: startDateTime ?? this.startDateTime, endDateTime: endDateTime ?? this.endDateTime, ); diff --git a/lib/presentation/week_menu/bloc/week_menu_bloc.dart b/lib/presentation/week_menu/bloc/week_menu_bloc.dart index 119478af..39078515 100644 --- a/lib/presentation/week_menu/bloc/week_menu_bloc.dart +++ b/lib/presentation/week_menu/bloc/week_menu_bloc.dart @@ -175,6 +175,10 @@ class WeekMenuBlocBloc extends Bloc { for (Meal meal in weekMenu.dayMenus[dayNumber].meals) { if (meal.id == event.mealId) { meal.couponStatus = newCouponStatus; + if (meal.couponStatus.status == CouponStatusEnum.N) { + emit((state as WeekMenuBlocDisplayState) + .copyWith(error: "Time's up, coupon applications closed!")); + } } } emit((state as WeekMenuBlocDisplayState).copyWith(weekMenu: weekMenu)); diff --git a/lib/presentation/week_menu/components/DayMenu/menu_card.dart b/lib/presentation/week_menu/components/DayMenu/menu_card.dart index c633797e..71715f80 100644 --- a/lib/presentation/week_menu/components/DayMenu/menu_card.dart +++ b/lib/presentation/week_menu/components/DayMenu/menu_card.dart @@ -142,24 +142,16 @@ class FeedbackOrCouponButton extends StatelessWidget { } }, onTap: () { - if (!meal.isCouponOutdated) { - // TODO: show dialog box and then add toggle event - context.read().add(MealCouponEvent( - coupon: meal.couponStatus, - mealId: meal.id, - )); - } else if (meal.couponStatus.status == CouponStatusEnum.A) { + if (meal.couponStatus.status == CouponStatusEnum.A) { showCouponDialog( "Coupon no: ${meal.couponStatus.id!}", context, ); } else { - const snackBar = SnackBar( - content: Text( - "Time's up, coupon applications closed", - ), - ); - ScaffoldMessenger.of(context).showSnackBar(snackBar); + context.read().add(MealCouponEvent( + coupon: meal.couponStatus, + mealId: meal.id, + )); } }, child: FeedbackAndCouponWidget( diff --git a/lib/presentation/week_menu/menu_view.dart b/lib/presentation/week_menu/menu_view.dart index 2ae516ba..fa987061 100644 --- a/lib/presentation/week_menu/menu_view.dart +++ b/lib/presentation/week_menu/menu_view.dart @@ -18,7 +18,7 @@ class WeekMenuScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocBuilder( + return BlocConsumer( builder: (context, state) { return Column( children: [ @@ -84,6 +84,16 @@ class WeekMenuScreen extends StatelessWidget { ], ); }, + listener: (BuildContext context, WeekMenuBlocState state) { + if (state is WeekMenuBlocDisplayState && state.error.isNotEmpty) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(state.error), + backgroundColor: AppTheme.customRed, + ), + ); + } + }, ); } }