Skip to content

Commit 1ed52f8

Browse files
authored
Merge pull request #283 from mdgspace/casper/coupon-status
rfac: removes isCouponOutdated from week_menu_tmp.dart
2 parents ec045c3 + 70e9b18 commit 1ed52f8

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

lib/domain/models/menu/week_menu_tmp.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ class Meal {
182182
String? secretCode;
183183
bool isOutdated;
184184
bool isLeaveToggleOutdated;
185-
bool isCouponOutdated;
186185
DateTime startDateTime;
187186
DateTime endDateTime;
188187

@@ -201,7 +200,6 @@ class Meal {
201200
this.secretCode,
202201
required this.isOutdated,
203202
required this.isLeaveToggleOutdated,
204-
required this.isCouponOutdated,
205203
required this.startDateTime,
206204
required this.endDateTime,
207205
required this.couponStatus,
@@ -229,10 +227,6 @@ class Meal {
229227
!DateTimeUtils.getDateTimeFromDateAndTime(date, json['start_time'])
230228
.subtract(outdatedTime)
231229
.isAfter(DateTime.now()),
232-
isCouponOutdated:
233-
!DateTimeUtils.getDateTimeFromDateAndTime(date, json['start_time'])
234-
.subtract(outdatedTime * 2)
235-
.isAfter(DateTime.now()),
236230
startDateTime:
237231
DateTimeUtils.getDateTimeFromDateAndTime(date, json['start_time']),
238232
endDateTime:
@@ -291,7 +285,6 @@ class Meal {
291285
isLeaveToggleOutdated:
292286
isLeaveToggleOutdated ?? this.isLeaveToggleOutdated,
293287
isOutdated: isOutdated ?? this.isOutdated,
294-
isCouponOutdated: isCouponOutdated ?? this.isCouponOutdated,
295288
startDateTime: startDateTime ?? this.startDateTime,
296289
endDateTime: endDateTime ?? this.endDateTime,
297290
);

lib/presentation/week_menu/bloc/week_menu_bloc.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ class WeekMenuBlocBloc extends Bloc<WeekMenuBlocEvent, WeekMenuBlocState> {
175175
for (Meal meal in weekMenu.dayMenus[dayNumber].meals) {
176176
if (meal.id == event.mealId) {
177177
meal.couponStatus = newCouponStatus;
178+
if (meal.couponStatus.status == CouponStatusEnum.N) {
179+
emit((state as WeekMenuBlocDisplayState)
180+
.copyWith(error: "Time's up, coupon applications closed!"));
181+
}
178182
}
179183
}
180184
emit((state as WeekMenuBlocDisplayState).copyWith(weekMenu: weekMenu));

lib/presentation/week_menu/components/DayMenu/menu_card.dart

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,16 @@ class FeedbackOrCouponButton extends StatelessWidget {
142142
}
143143
},
144144
onTap: () {
145-
if (!meal.isCouponOutdated) {
146-
// TODO: show dialog box and then add toggle event
147-
context.read<WeekMenuBlocBloc>().add(MealCouponEvent(
148-
coupon: meal.couponStatus,
149-
mealId: meal.id,
150-
));
151-
} else if (meal.couponStatus.status == CouponStatusEnum.A) {
145+
if (meal.couponStatus.status == CouponStatusEnum.A) {
152146
showCouponDialog(
153147
"Coupon no: ${meal.couponStatus.id!}",
154148
context,
155149
);
156150
} else {
157-
const snackBar = SnackBar(
158-
content: Text(
159-
"Time's up, coupon applications closed",
160-
),
161-
);
162-
ScaffoldMessenger.of(context).showSnackBar(snackBar);
151+
context.read<WeekMenuBlocBloc>().add(MealCouponEvent(
152+
coupon: meal.couponStatus,
153+
mealId: meal.id,
154+
));
163155
}
164156
},
165157
child: FeedbackAndCouponWidget(

lib/presentation/week_menu/menu_view.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class WeekMenuScreen extends StatelessWidget {
1818

1919
@override
2020
Widget build(BuildContext context) {
21-
return BlocBuilder<WeekMenuBlocBloc, WeekMenuBlocState>(
21+
return BlocConsumer<WeekMenuBlocBloc, WeekMenuBlocState>(
2222
builder: (context, state) {
2323
return Column(
2424
children: [
@@ -84,6 +84,16 @@ class WeekMenuScreen extends StatelessWidget {
8484
],
8585
);
8686
},
87+
listener: (BuildContext context, WeekMenuBlocState state) {
88+
if (state is WeekMenuBlocDisplayState && state.error.isNotEmpty) {
89+
ScaffoldMessenger.of(context).showSnackBar(
90+
SnackBar(
91+
content: Text(state.error),
92+
backgroundColor: AppTheme.customRed,
93+
),
94+
);
95+
}
96+
},
8797
);
8898
}
8999
}

0 commit comments

Comments
 (0)