Skip to content

Commit

Permalink
Update LeaveReviewAction to only show the leave review UI if the user…
Browse files Browse the repository at this point in the history
… has purchased the product

# Conflicts:
#	ecommerce_app/lib/src/features/products/presentation/product_screen/leave_review_action.dart
  • Loading branch information
bizz84 committed Nov 6, 2024
1 parent 2375658 commit 57a35fc
Showing 1 changed file with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:ecommerce_app/src/features/orders/domain/order.dart';
import 'package:ecommerce_app/src/features/orders/application/user_orders_provider.dart';
import 'package:ecommerce_app/src/features/products/domain/product.dart';
import 'package:ecommerce_app/src/features/reviews/application/reviews_service.dart';
import 'package:ecommerce_app/src/localization/string_hardcoded.dart';
import 'package:ecommerce_app/src/routing/app_router.dart';
import 'package:ecommerce_app/src/utils/date_formatter.dart';
Expand All @@ -18,18 +19,8 @@ class LeaveReviewAction extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
// TODO: Read from data source
final orders = [
Order(
id: 'abc',
userId: '123',
items: {productId: 1},
orderStatus: OrderStatus.confirmed,
orderDate: DateTime.now(),
total: 15.0,
)
];
if (orders.isNotEmpty) {
final orders = ref.watch(matchingUserOrdersProvider(productId)).value;
if (orders != null && orders.isNotEmpty) {
final dateFormatted =
ref.watch(dateFormatterProvider).format(orders.first.orderDate);
return Column(
Expand All @@ -45,16 +36,26 @@ class LeaveReviewAction extends ConsumerWidget {
rowCrossAxisAlignment: CrossAxisAlignment.center,
columnCrossAxisAlignment: CrossAxisAlignment.center,
startContent: Text('Purchased on $dateFormatted'.hardcoded),
endContent: CustomTextButton(
text: 'Leave a review'.hardcoded,
style: Theme.of(context)
.textTheme
.bodyLarge!
.copyWith(color: Colors.green[700]),
onPressed: () => context.goNamed(
AppRoute.leaveReview.name,
pathParameters: {'id': productId},
),
endContent: Consumer(
builder: (context, ref, child) {
final reviewValue =
ref.watch(userReviewStreamProvider(productId));

return CustomTextButton(
text: (reviewValue.value != null
? 'Update review'
: 'Leave a review')
.hardcoded,
style: Theme.of(context)
.textTheme
.bodyLarge!
.copyWith(color: Colors.green[700]),
onPressed: () => context.goNamed(
AppRoute.leaveReview.name,
pathParameters: {'id': productId},
),
);
},
),
),
gapH8,
Expand Down

0 comments on commit 57a35fc

Please sign in to comment.