Skip to content

Commit

Permalink
Merge pull request #283 from mdgspace/casper/coupon-status
Browse files Browse the repository at this point in the history
rfac: removes isCouponOutdated from week_menu_tmp.dart
  • Loading branch information
A-Kashif108 committed Apr 20, 2024
2 parents ec045c3 + 70e9b18 commit 1ed52f8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
7 changes: 0 additions & 7 deletions lib/domain/models/menu/week_menu_tmp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ class Meal {
String? secretCode;
bool isOutdated;
bool isLeaveToggleOutdated;
bool isCouponOutdated;
DateTime startDateTime;
DateTime endDateTime;

Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
);
Expand Down
4 changes: 4 additions & 0 deletions lib/presentation/week_menu/bloc/week_menu_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ class WeekMenuBlocBloc extends Bloc<WeekMenuBlocEvent, WeekMenuBlocState> {
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));
Expand Down
18 changes: 5 additions & 13 deletions lib/presentation/week_menu/components/DayMenu/menu_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,24 +142,16 @@ class FeedbackOrCouponButton extends StatelessWidget {
}
},
onTap: () {
if (!meal.isCouponOutdated) {
// TODO: show dialog box and then add toggle event
context.read<WeekMenuBlocBloc>().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<WeekMenuBlocBloc>().add(MealCouponEvent(
coupon: meal.couponStatus,
mealId: meal.id,
));
}
},
child: FeedbackAndCouponWidget(
Expand Down
12 changes: 11 additions & 1 deletion lib/presentation/week_menu/menu_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class WeekMenuScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
return BlocBuilder<WeekMenuBlocBloc, WeekMenuBlocState>(
return BlocConsumer<WeekMenuBlocBloc, WeekMenuBlocState>(
builder: (context, state) {
return Column(
children: [
Expand Down Expand Up @@ -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,
),
);
}
},
);
}
}

0 comments on commit 1ed52f8

Please sign in to comment.