Skip to content

Commit 8b5f64b

Browse files
fix: coupon api (#218)
* chor: update the outdate period to 24hrs Signed-off-by: Aman <[email protected]> * rfac: update the coupon api Signed-off-by: Aman <[email protected]> * feat: Add dialog before updating status of coupon. (#217) * feat: add dialog for coupon number Signed-off-by: Aman <[email protected]> --------- Signed-off-by: Aman <[email protected]> Co-authored-by: Ayush Chaudhary <[email protected]>
1 parent 915f873 commit 8b5f64b

File tree

7 files changed

+87
-25
lines changed

7 files changed

+87
-25
lines changed

lib/models/menu/week_menu.dart

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

@@ -200,6 +201,7 @@ class Meal {
200201
this.secretCode,
201202
required this.isOutdated,
202203
required this.isLeaveToggleOutdated,
204+
required this.isCouponOutdated,
203205
required this.startDateTime,
204206
required this.endDateTime,
205207
required this.couponStatus,
@@ -227,6 +229,10 @@ class Meal {
227229
!DateTimeUtils.getDateTimeFromDateAndTime(date, json['start_time'])
228230
.subtract(outdatedTime)
229231
.isAfter(DateTime.now()),
232+
isCouponOutdated:
233+
!DateTimeUtils.getDateTimeFromDateAndTime(date, json['start_time'])
234+
.subtract(outdatedTime * 2)
235+
.isAfter(DateTime.now()),
230236
startDateTime:
231237
DateTimeUtils.getDateTimeFromDateAndTime(date, json['start_time']),
232238
endDateTime:
@@ -264,6 +270,7 @@ class Meal {
264270
String? secretCode,
265271
bool? isOutdated,
266272
bool? isLeaveToggleOutdated,
273+
bool? isCouponOutdated,
267274
DateTime? startDateTime,
268275
DateTime? endDateTime,
269276
}) {
@@ -284,6 +291,7 @@ class Meal {
284291
isLeaveToggleOutdated:
285292
isLeaveToggleOutdated ?? this.isLeaveToggleOutdated,
286293
isOutdated: isOutdated ?? this.isOutdated,
294+
isCouponOutdated: isCouponOutdated ?? this.isCouponOutdated,
287295
startDateTime: startDateTime ?? this.startDateTime,
288296
endDateTime: endDateTime ?? this.endDateTime,
289297
);

lib/services/api/coupon_api.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class CouponApi {
1515

1616
try {
1717
await ApiUtils.addTokenToHeaders(headers);
18-
var jsonResponse =
19-
await ApiUtils.post(uri, headers: headers, body: {'meal': mealId});
18+
var jsonResponse = await ApiUtils.post(uri,
19+
headers: headers, body: {'meal': mealId, 'is_active': true});
2020

2121
return CouponStatus(
2222
status: CouponStatusEnum.A,
@@ -34,7 +34,7 @@ class CouponApi {
3434

3535
try {
3636
await ApiUtils.addTokenToHeaders(headers);
37-
await ApiUtils.delete(uri, headers: headers);
37+
await ApiUtils.patch(uri, headers: headers, body: {'is_active': false});
3838

3939
return CouponStatus(status: CouponStatusEnum.N);
4040
} on Exception catch (e) {

lib/ui/menu/components/your_meal_menu_card.dart

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,49 @@ class _YourMealsMenuCardState extends State<YourMealsMenuCard> {
6060

6161
Widget _buildCouponCodeComponent() {
6262
if (_model.meal!.couponStatus.status == CouponStatusEnum.A &&
63-
_model.meal!.isOutdated) {
64-
return Container(
65-
decoration: BoxDecoration(
66-
color: AppTheme.secondary,
67-
borderRadius: BorderRadius.circular(24),
68-
),
69-
padding: EdgeInsets.symmetric(
70-
horizontal: 8.r,
71-
vertical: 4.r,
72-
),
73-
child: Text(
74-
'CPN - ${_model.meal!.couponStatus.id}',
75-
style: AppTheme.bodyText2.copyWith(color: AppTheme.white),
63+
_model.meal!.isCouponOutdated) {
64+
return GestureDetector(
65+
onTap: () {
66+
Get.dialog(
67+
SimpleDialog(
68+
contentPadding: EdgeInsets.symmetric(vertical: 10),
69+
shape: RoundedRectangleBorder(
70+
borderRadius: BorderRadius.circular(8.r),
71+
side: BorderSide(color: AppTheme.grey),
72+
),
73+
children: [
74+
Center(
75+
child: Text(
76+
'Coupon',
77+
style: AppTheme.headline6,
78+
),
79+
),
80+
Center(
81+
child: Text(
82+
'${_model.meal!.couponStatus.id}',
83+
style: AppTheme.headline1.copyWith(
84+
fontSize: 30.sp,
85+
color: AppTheme.tertiary,
86+
),
87+
),
88+
),
89+
],
90+
),
91+
);
92+
},
93+
child: Container(
94+
decoration: BoxDecoration(
95+
color: AppTheme.secondary,
96+
borderRadius: BorderRadius.circular(24),
97+
),
98+
padding: EdgeInsets.symmetric(
99+
horizontal: 8.r,
100+
vertical: 4.r,
101+
),
102+
child: Text(
103+
'CPN - ${_model.meal!.couponStatus.id}',
104+
style: AppTheme.bodyText2.copyWith(color: AppTheme.white),
105+
),
76106
),
77107
);
78108
}
@@ -202,11 +232,15 @@ class _YourMealsMenuCardState extends State<YourMealsMenuCard> {
202232
_model.onLeaveChanged(value).then((_) {
203233
context.read<YourMenuViewModel>().updateMeal =
204234
_model.meal!.copyWith(
205-
leaveStatus: LeaveStatus(
206-
status: _model.mealLeaveStatus
207-
? LeaveStatusEnum.N
208-
: LeaveStatusEnum.P,
209-
));
235+
leaveStatus: LeaveStatus(
236+
status: _model.mealLeaveStatus
237+
? LeaveStatusEnum.N
238+
: LeaveStatusEnum.P,
239+
),
240+
couponStatus: !_model.mealLeaveStatus
241+
? CouponStatus(status: CouponStatusEnum.N)
242+
: _model.meal!.couponStatus,
243+
);
210244
});
211245
},
212246
),

lib/ui/menu/your_menu_view.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import 'package:appetizer/ui/components/appetizer_error_widget.dart';
55
import 'package:appetizer/ui/components/appetizer_progress_widget.dart';
66
import 'package:appetizer/ui/menu/your_day_menu_view.dart';
77
import 'package:appetizer/utils/date_time_utils.dart';
8+
import 'package:appetizer/viewmodels/home_viewmodel.dart';
89
import 'package:appetizer/viewmodels/menu/your_menu_viewmodel.dart';
910
import 'package:flutter/material.dart';
11+
import 'package:provider/provider.dart';
1012

1113
class YourMenuView extends StatefulWidget {
1214
final DateTime selectedDateTime;
@@ -38,6 +40,11 @@ class _YourMenuViewState extends State<YourMenuView> {
3840
return BaseView<YourMenuViewModel>(
3941
onModelReady: (model) {
4042
_model = model;
43+
context.read<HomeViewModel>().addListener(() {
44+
_model.fetchSelectedWeekMenu(
45+
DateTimeUtils.getWeekNumber(widget.selectedDateTime),
46+
);
47+
});
4148
_model.fetchInitialCheckedStatus();
4249
_model.selectedDateTime = widget.selectedDateTime;
4350
_model.fetchSelectedWeekMenu(

lib/utils/menu_ui_utils.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:math' as math;
22

33
import 'package:appetizer/app_theme.dart';
4+
import 'package:appetizer/globals.dart';
45
import 'package:appetizer/models/menu/week_menu.dart';
56
import 'package:appetizer/ui/components/appetizer_outline_button.dart';
67
import 'package:appetizer/ui/components/appetizer_primary_button.dart';
@@ -82,7 +83,10 @@ class MenuUIUtils {
8283
),
8384
),
8485
),
85-
if (!meal.isOutdated && item.type == MealItemType.CPN)
86+
if (!meal.isCouponOutdated &&
87+
item.type == MealItemType.CPN &&
88+
meal.leaveStatus.status == LeaveStatusEnum.N &&
89+
!isCheckedOut)
8690
SizedBox(
8791
height: 20.r,
8892
child: meal.couponStatus.status == CouponStatusEnum.N

lib/viewmodels/menu/your_menu_card_viewmodel.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ class YourMenuCardViewModel extends BaseModel {
115115
if (_meal != null) {
116116
if (_meal!.couponStatus.status == CouponStatusEnum.A) {
117117
try {
118-
return await _couponApi.cancelCoupon(_meal!.couponStatus.id!);
118+
var _dialogResponse = await _dialogService.showConfirmationDialog(
119+
title: 'Coupon',
120+
description: 'Do you want to cancel your coupon?');
121+
if (_dialogResponse.confirmed) {
122+
return await _couponApi.cancelCoupon(_meal!.couponStatus.id!);
123+
}
119124
} on Failure catch (f) {
120125
print(f.toString());
121126
setErrorMessage(f.message);
@@ -126,7 +131,11 @@ class YourMenuCardViewModel extends BaseModel {
126131
}
127132
} else {
128133
try {
129-
return await _couponApi.applyForCoupon(_meal!.id);
134+
var _dialogResponse = await _dialogService.showConfirmationDialog(
135+
title: 'Coupon', description: 'Do you want to apply for coupon?');
136+
if (_dialogResponse.confirmed) {
137+
return await _couponApi.applyForCoupon(_meal!.id);
138+
}
130139
} on Failure catch (f) {
131140
print(f.toString());
132141
setErrorMessage(f.message);

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,5 +966,5 @@ packages:
966966
source: hosted
967967
version: "3.1.1"
968968
sdks:
969-
dart: ">=2.19.0-0 <4.0.0"
969+
dart: ">=2.19.0-0 <3.0.0"
970970
flutter: ">=3.7.0-0"

0 commit comments

Comments
 (0)