6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 505731c3
Changed files
comwell_key_app/assets/translations/da-DK.json | 6 +- comwell_key_app/assets/translations/en-US.json | 6 +- .../lib/check_out/bloc/check_out_cubit.dart | 9 +-- .../lib/check_out/bloc/check_out_state.dart | 3 +- .../check_out/components/accept_terms_toggle.dart | 21 +++-- .../check_out/components/apply_club_points.dart | 27 +++---- .../components/checkout_itemized_bill.dart | 21 ++--- .../lib/check_out/pages/checkout_payment_page.dart | 64 +++++++-------- .../template_pages/payment_page_template.dart | 82 ++++++++++++++++++++ .../components/balance_bottom_sheet.dart | 2 +- .../lib/my_booking/cubit/my_booking_cubit.dart | 48 ++++++++++-- .../lib/my_booking/cubit/my_booking_state.dart | 90 +++++++++++++++++++++- .../my_booking/pages/my_booking_payment_page.dart | 63 +++++++++++++++ comwell_key_app/lib/routing/app_router.dart | 16 +++- 14 files changed, 368 insertions(+), 90 deletions(-)
Diff
diff --git a/comwell_key_app/assets/translations/da-DK.json b/comwell_key_app/assets/translations/da-DK.json
index 625483aa..3303af4a 100644
--- a/comwell_key_app/assets/translations/da-DK.json
+++ b/comwell_key_app/assets/translations/da-DK.json
@@ -173,7 +173,7 @@
"checkout_page_payment_total": "Total",
"checkout_page_payment_price": "{} kr.",
"checkout_page_payment_club_points_title": "Brug Comwell Club Point",
- "checkout_page_payment_club_points_subtitle": "Du har {} point, anvend og spar {} kr.",
+ "checkout_page_payment_club_points_subtitle": "Du har {} point, anvend og spar {}kr.",
"checkout_page_payment_club_points_subtitle_zero": "Du har ingen point at anvende",
"checkout_page_payment_payment_title": "Betal og check ud",
"checkout_page_confirmation": "Gå til check-out",
@@ -327,5 +327,7 @@
"up_sales_confirmation_no_up_sales": "Ingen tilvalg valgt.",
"facilities": "Faciliteter",
"remove": "Fjern",
- "up_sales_processing_error_title": "Kunne ikke tilføje tilkøb"
+ "up_sales_processing_error_title": "Kunne ikke tilføje tilkøb",
+ "pay_bill": "Betal regning",
+ "discount": "Rabat"
}
\ No newline at end of file
diff --git a/comwell_key_app/assets/translations/en-US.json b/comwell_key_app/assets/translations/en-US.json
index eb61f550..743ae9fb 100644
--- a/comwell_key_app/assets/translations/en-US.json
+++ b/comwell_key_app/assets/translations/en-US.json
@@ -176,7 +176,7 @@
"checkout_page_payment_total": "Total",
"checkout_page_payment_price": "{} kr.",
"checkout_page_payment_club_points_title": "Use Comwell Club Points",
- "checkout_page_payment_club_points_subtitle": "You have {} points, use them and save {} kr.",
+ "checkout_page_payment_club_points_subtitle": "You have {} points, use them and save {}kr.",
"checkout_page_payment_club_points_subtitle_zero": "You have no points to use",
"checkout_page_payment_payment_title": "Pay and check out",
"checkout_page_confirmation": "Go to checkout",
@@ -330,5 +330,7 @@
"up_sales_confirmation_no_up_sales": "No upgrades selected.",
"facilities": "Facilities",
"remove": "Remove",
- "up_sales_processing_error_title": "Failed to add addons"
+ "up_sales_processing_error_title": "Failed to add addons",
+ "pay_bill": "Pay bill",
+ "discount": "Discount"
}
diff --git a/comwell_key_app/lib/check_out/bloc/check_out_cubit.dart b/comwell_key_app/lib/check_out/bloc/check_out_cubit.dart
index 4ba4d0e4..d43cb75e 100644
--- a/comwell_key_app/lib/check_out/bloc/check_out_cubit.dart
+++ b/comwell_key_app/lib/check_out/bloc/check_out_cubit.dart
@@ -173,7 +173,7 @@ class CheckoutCubit extends Cubit<CheckoutState> {
Future<void> createSession() async {
try {
- final bookingPrice = totalPriceAfterDiscount;
+ final bookingPrice = state.totalPriceAfterDiscount;
final amount = Amount(
value: bookingPrice,
currency: currency,
@@ -219,12 +219,7 @@ class CheckoutCubit extends Cubit<CheckoutState> {
launchUrl(Uri.parse(ComwellUrls.termsAndConditions));
}
- int get totalPriceAfterDiscount {
- if (state.applyClubPoints) {
- return trimmedBalance - state.clubPoints;
- }
- return trimmedBalance;
- }
+
//Removes the decimal point from the balance if it is .0
int get trimmedBalance {
diff --git a/comwell_key_app/lib/check_out/bloc/check_out_state.dart b/comwell_key_app/lib/check_out/bloc/check_out_state.dart
index 3cac4821..91361b75 100644
--- a/comwell_key_app/lib/check_out/bloc/check_out_state.dart
+++ b/comwell_key_app/lib/check_out/bloc/check_out_state.dart
@@ -3,6 +3,7 @@ import 'package:comwell_key_app/check_out/models/checkout_processing_state.dart'
import 'package:comwell_key_app/check_out/models/payment_method.dart';
import 'package:comwell_key_app/services/models/booking_dto.dart';
import 'package:comwell_key_app/check_out/pages/check_out_page.dart';
+import 'package:easy_localization/easy_localization.dart';
import 'package:equatable/equatable.dart';
class CheckoutState extends Equatable {
@@ -26,7 +27,7 @@ class CheckoutState extends Equatable {
Iterable<BookingAddonItem> get items {
if (applyClubPoints) {
- return [..._items, BookingAddonItem("Rabat", "Rabat", clubPoints * -1, clubPoints * -1)];
+ return [..._items, BookingAddonItem("discount".tr(), "discount".tr(), clubPoints * -1, clubPoints * -1)];
}
return _items;
diff --git a/comwell_key_app/lib/check_out/components/accept_terms_toggle.dart b/comwell_key_app/lib/check_out/components/accept_terms_toggle.dart
index 22c6ce7d..8e382da1 100644
--- a/comwell_key_app/lib/check_out/components/accept_terms_toggle.dart
+++ b/comwell_key_app/lib/check_out/components/accept_terms_toggle.dart
@@ -1,16 +1,21 @@
-import 'package:comwell_key_app/check_out/bloc/check_out_cubit.dart';
import 'package:comwell_key_app/themes/dark_theme.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
-import 'package:flutter_bloc/flutter_bloc.dart';
class AcceptTermsToggle extends StatelessWidget {
- const AcceptTermsToggle({super.key});
+ final bool isTermsAccepted;
+ final void Function(bool) onAcceptTermsChanged;
+ final void Function() onShowTermsAndConditions;
+ final bool showError;
+ const AcceptTermsToggle(
+ {super.key,
+ required this.isTermsAccepted,
+ required this.onAcceptTermsChanged,
+ required this.showError,
+ required this.onShowTermsAndConditions});
@override
Widget build(BuildContext context) {
- final cubit = context.read<CheckoutCubit>();
- final showError = cubit.state.showTermsError;
final theme = Theme.of(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -21,12 +26,12 @@ class AcceptTermsToggle extends StatelessWidget {
Row(
children: [
Checkbox(
- value: cubit.state.isTermsAccepted,
+ value: isTermsAccepted,
visualDensity: VisualDensity.comfortable,
checkColor: Colors.white,
activeColor: sandColor[80],
onChanged: (value) {
- cubit.onAcceptTermsChanged(value ?? false);
+ onAcceptTermsChanged(value ?? false);
},
),
const SizedBox(width: 4),
@@ -41,7 +46,7 @@ class AcceptTermsToggle extends StatelessWidget {
const SizedBox(width: 4),
GestureDetector(
onTap: () {
- cubit.showTermsAndConditions();
+ onShowTermsAndConditions();
},
child: Text(
"approve_conditions_subtitle".tr(),
diff --git a/comwell_key_app/lib/check_out/components/apply_club_points.dart b/comwell_key_app/lib/check_out/components/apply_club_points.dart
index 7f1e3e5d..290d1ee7 100644
--- a/comwell_key_app/lib/check_out/components/apply_club_points.dart
+++ b/comwell_key_app/lib/check_out/components/apply_club_points.dart
@@ -1,15 +1,19 @@
-import 'package:comwell_key_app/check_out/bloc/check_out_cubit.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
-import 'package:flutter_bloc/flutter_bloc.dart';
class ApplyClubPoints extends StatelessWidget {
- const ApplyClubPoints({super.key});
+ final bool applyClubPoints;
+ final int clubPoints;
+ final void Function(bool) onApplyClubPointsChanged;
+ const ApplyClubPoints(
+ {super.key,
+ required this.applyClubPoints,
+ required this.clubPoints,
+ required this.onApplyClubPointsChanged});
@override
Widget build(BuildContext context) {
- final cubit = context.read<CheckoutCubit>();
return Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -20,12 +24,9 @@ class ApplyClubPoints extends StatelessWidget {
children: [
Text("checkout_page_payment_club_points_title".tr()),
Text(
- cubit.state.clubPoints > 0
+ clubPoints > 0
? "checkout_page_payment_club_points_subtitle".tr(
- args: [
- "${cubit.state.clubPoints}",
- "${cubit.state.clubPoints}"
- ],
+ args: ["$clubPoints", "$clubPoints"],
)
: "checkout_page_payment_club_points_subtitle_zero".tr(),
style: TextStyle(color: colorBlack[65]),
@@ -33,16 +34,16 @@ class ApplyClubPoints extends StatelessWidget {
],
),
),
- const SizedBox(width: 20),
- if (cubit.state.clubPoints > 0)
+ const SizedBox(width: 10),
+ if (clubPoints > 0)
Switch(
- value: cubit.state.applyClubPoints,
+ value: applyClubPoints,
activeColor: sandColor[80],
inactiveTrackColor: Colors.grey[200],
inactiveThumbColor: Colors.white,
trackOutlineColor: const WidgetStatePropertyAll(Colors.white),
onChanged: (value) {
- cubit.onApplyClubPointsClicked(value);
+ onApplyClubPointsChanged(value);
},
)
],
diff --git a/comwell_key_app/lib/check_out/components/checkout_itemized_bill.dart b/comwell_key_app/lib/check_out/components/checkout_itemized_bill.dart
index f4001d77..4bef3ee4 100644
--- a/comwell_key_app/lib/check_out/components/checkout_itemized_bill.dart
+++ b/comwell_key_app/lib/check_out/components/checkout_itemized_bill.dart
@@ -1,21 +1,24 @@
import 'package:comwell_key_app/check_out/bloc/check_out_cubit.dart';
import 'package:comwell_key_app/check_out/components/check_out_bill_list_item.dart';
+import 'package:comwell_key_app/services/models/booking_dto.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class CheckoutItemizedBill extends StatelessWidget {
- const CheckoutItemizedBill({super.key});
+ final Iterable<BookingAddonItem> addOnItems;
+ final bool applyClubPoints;
+ final int totalPriceBeforeDiscount;
+ final int totalPriceAfterDiscount;
+ final int trimmedBalance;
+ const CheckoutItemizedBill({super.key, required this.addOnItems, required this.applyClubPoints, required this.totalPriceBeforeDiscount, required this.totalPriceAfterDiscount, required this.trimmedBalance});
@override
Widget build(BuildContext context) {
- final cubit = context.read<CheckoutCubit>();
- final items = cubit.state.items;
-
return Column(
children: [
- ...items.map((item) => Column(
+ ...addOnItems.map((item) => Column(
children: [
CheckOutBillListItem(item: item),
const SizedBox(height: 14)
@@ -28,22 +31,22 @@ class CheckoutItemizedBill extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("checkout_page_payment_total".tr()),
- if (cubit.state.applyClubPoints)
+ if (applyClubPoints)
Row(
children: [
Text(
- "${cubit.state.totalPriceBeforeDiscount}",
+ "${totalPriceBeforeDiscount}",
style: const TextStyle(
decoration: TextDecoration.lineThrough,
decorationColor: colorDivider,
color: colorDivider),
),
const SizedBox(width: 4),
- Text("${cubit.totalPriceAfterDiscount}"),
+ Text("${totalPriceAfterDiscount}"),
],
)
else
- Text(cubit.trimmedBalance.toString()),
+ Text(trimmedBalance.toString()),
],
),
const SizedBox(height: 12),
diff --git a/comwell_key_app/lib/check_out/pages/checkout_payment_page.dart b/comwell_key_app/lib/check_out/pages/checkout_payment_page.dart
index 500bdf47..cc040992 100644
--- a/comwell_key_app/lib/check_out/pages/checkout_payment_page.dart
+++ b/comwell_key_app/lib/check_out/pages/checkout_payment_page.dart
@@ -1,45 +1,37 @@
-import 'package:comwell_key_app/check_out/components/accept_terms_toggle.dart';
-import 'package:comwell_key_app/check_out/components/apply_club_points.dart';
-import 'package:comwell_key_app/check_out/components/checkout_itemized_bill.dart';
-import 'package:comwell_key_app/themes/light_theme.dart';
-import 'package:easy_localization/easy_localization.dart';
+import 'package:comwell_key_app/check_out/bloc/check_out_cubit.dart';
+import 'package:comwell_key_app/common/template_pages/payment_page_template.dart';
import 'package:flutter/material.dart';
-
+import 'package:flutter_bloc/flutter_bloc.dart';
class CheckoutPaymentPage extends StatelessWidget {
const CheckoutPaymentPage({super.key});
@override
Widget build(BuildContext context) {
- // Calculate dynamic bottom padding to account for bottom sheet
- const bottomSheetHeight = 120.0; // Approximate height of bottom sheet
- final safeAreaBottom = MediaQuery.of(context).padding.bottom;
- final dynamicBottomPadding = bottomSheetHeight + safeAreaBottom + 20.0; // Extra 20px for comfort
-
- return SingleChildScrollView(
- key: PageStorageKey("$runtimeType"),
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const SizedBox(height: 40),
- Text(
- "checkout_page_payment_title".tr(),
- style: Theme.of(context).textTheme.headlineLarge,
- ),
- const SizedBox(height: 26),
- const CheckoutItemizedBill(),
- const SizedBox(height: 52),
- const ApplyClubPoints(),
- const SizedBox(height: 20),
- const Divider(color: colorDivider),
- const SizedBox(height: 20),
- const AcceptTermsToggle(),
- SizedBox(height: dynamicBottomPadding),
- ],
- ),
- ),
- );
+ final cubit = context.read<CheckoutCubit>();
+ final addOnItems = cubit.state.items;
+ final applyClubPoints = cubit.state.applyClubPoints;
+ final totalPriceBeforeDiscount = cubit.state.totalPriceBeforeDiscount;
+ final totalPriceAfterDiscount = cubit.state.totalPriceAfterDiscount;
+ final trimmedBalance = cubit.trimmedBalance;
+ final clubPoints = cubit.state.clubPoints;
+ final isTermsAccepted = cubit.state.isTermsAccepted;
+ final onAcceptTermsChanged = cubit.onAcceptTermsChanged;
+ final showError = cubit.state.showTermsError;
+ final onShowTermsAndConditions = cubit.showTermsAndConditions;
+ final onApplyClubPointsChanged = cubit.onApplyClubPointsClicked;
+
+ return PaymentPageTemplate(
+ addOnItems: addOnItems,
+ applyClubPoints: applyClubPoints,
+ totalPriceBeforeDiscount: totalPriceBeforeDiscount,
+ totalPriceAfterDiscount: totalPriceAfterDiscount,
+ trimmedBalance: trimmedBalance,
+ clubPoints: clubPoints,
+ isTermsAccepted: isTermsAccepted,
+ onAcceptTermsChanged: onAcceptTermsChanged,
+ showError: showError,
+ onShowTermsAndConditions: onShowTermsAndConditions,
+ onApplyClubPointsChanged: onApplyClubPointsChanged);
}
}
diff --git a/comwell_key_app/lib/common/template_pages/payment_page_template.dart b/comwell_key_app/lib/common/template_pages/payment_page_template.dart
new file mode 100644
index 00000000..275b17f7
--- /dev/null
+++ b/comwell_key_app/lib/common/template_pages/payment_page_template.dart
@@ -0,0 +1,82 @@
+import 'package:comwell_key_app/check_out/components/accept_terms_toggle.dart';
+import 'package:comwell_key_app/check_out/components/apply_club_points.dart';
+import 'package:comwell_key_app/check_out/components/checkout_itemized_bill.dart';
+import 'package:comwell_key_app/services/models/booking_dto.dart';
+import 'package:comwell_key_app/themes/light_theme.dart';
+import 'package:flutter/material.dart';
+import 'package:easy_localization/easy_localization.dart';
+
+class PaymentPageTemplate extends StatelessWidget {
+ final Iterable<BookingAddonItem> addOnItems;
+ final bool applyClubPoints;
+ final int totalPriceBeforeDiscount;
+ final int totalPriceAfterDiscount;
+ final int trimmedBalance;
+ final int clubPoints;
+ final bool isTermsAccepted;
+ final void Function(bool) onAcceptTermsChanged;
+ final bool showError;
+ final void Function() onShowTermsAndConditions;
+ final void Function(bool) onApplyClubPointsChanged;
+ const PaymentPageTemplate(
+ {super.key,
+ required this.addOnItems,
+ required this.applyClubPoints,
+ required this.totalPriceBeforeDiscount,
+ required this.totalPriceAfterDiscount,
+ required this.trimmedBalance,
+ required this.clubPoints,
+ required this.isTermsAccepted,
+ required this.onAcceptTermsChanged,
+ required this.showError,
+ required this.onShowTermsAndConditions,
+ required this.onApplyClubPointsChanged});
+
+ @override
+ Widget build(BuildContext context) {
+ // Calculate dynamic bottom padding to account for bottom sheet
+ const bottomSheetHeight = 120.0; // Approximate height of bottom sheet
+ final safeAreaBottom = MediaQuery.of(context).padding.bottom;
+ final dynamicBottomPadding =
+ bottomSheetHeight + safeAreaBottom + 20.0; // Extra 20px for comfort
+
+ return SingleChildScrollView(
+ key: PageStorageKey("$runtimeType"),
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16.0),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(height: 40),
+ Text(
+ "checkout_page_payment_title".tr(),
+ style: Theme.of(context).textTheme.headlineLarge,
+ ),
+ const SizedBox(height: 26),
+ CheckoutItemizedBill(
+ addOnItems: addOnItems,
+ applyClubPoints: applyClubPoints,
+ totalPriceBeforeDiscount: totalPriceBeforeDiscount,
+ totalPriceAfterDiscount: totalPriceAfterDiscount,
+ trimmedBalance: trimmedBalance),
+ const SizedBox(height: 52),
+ ApplyClubPoints(
+ applyClubPoints: applyClubPoints,
+ clubPoints: clubPoints,
+ onApplyClubPointsChanged: onApplyClubPointsChanged,
+ ),
+ const SizedBox(height: 20),
+ const Divider(color: colorDivider),
+ const SizedBox(height: 20),
+ AcceptTermsToggle(
+ isTermsAccepted: isTermsAccepted,
+ onAcceptTermsChanged: onAcceptTermsChanged,
+ showError: showError,
+ onShowTermsAndConditions: onShowTermsAndConditions),
+ SizedBox(height: dynamicBottomPadding),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/comwell_key_app/lib/my_booking/components/balance_bottom_sheet.dart b/comwell_key_app/lib/my_booking/components/balance_bottom_sheet.dart
index 7171e207..fdb28f29 100644
--- a/comwell_key_app/lib/my_booking/components/balance_bottom_sheet.dart
+++ b/comwell_key_app/lib/my_booking/components/balance_bottom_sheet.dart
@@ -160,7 +160,7 @@ class BalanceBottomSheet extends StatelessWidget {
child: SizedBox(
width: double.infinity,
child: ElevatedButton(
- onPressed: () => cubit.canContinueToPayment ? context.pushNamed(AppRoutes.payMyBooking.name) : null,
+ onPressed: () => cubit.canContinueToPayment ? context.pushNamed(AppRoutes.payMyBooking.name, extra: booking) : null,
style: theme.elevatedButtonTheme.style?.copyWith(
backgroundColor: WidgetStatePropertyAll(cubit.canContinueToPayment ? sandColor : Colors.grey),
padding: const WidgetStatePropertyAll(
diff --git a/comwell_key_app/lib/my_booking/cubit/my_booking_cubit.dart b/comwell_key_app/lib/my_booking/cubit/my_booking_cubit.dart
index 1a0cde57..adc1280d 100644
--- a/comwell_key_app/lib/my_booking/cubit/my_booking_cubit.dart
+++ b/comwell_key_app/lib/my_booking/cubit/my_booking_cubit.dart
@@ -2,27 +2,63 @@ import 'package:comwell_key_app/my_booking/cubit/my_booking_state.dart';
import 'package:comwell_key_app/my_booking/my_booking_repository.dart';
import 'package:comwell_key_app/overview/models/booking.dart';
import 'package:comwell_key_app/profile/profile_repository.dart';
+import 'package:comwell_key_app/profile/utils/urls.dart';
import 'package:comwell_key_app/utils/locator.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:url_launcher/url_launcher.dart';
class MyBookingCubit extends Cubit<MyBookingState> {
final MyBookingRepository myBookingRepository;
final ProfileRepository profileRepository = locator<ProfileRepository>();
late Booking booking;
-
- MyBookingCubit(
- this.myBookingRepository,
- {required Booking initialBooking})
+
+ MyBookingCubit(this.myBookingRepository, {required Booking initialBooking})
: super(MyBookingState(
booking: initialBooking,
isLoading: false,
error: null,
+ applyClubPoints: false,
+ clubPoints: 500,
+ isTermsAccepted: false,
+ showTermsError: false,
+ items: initialBooking.addOnItems ?? [],
)) {
booking = initialBooking;
}
- int get totalAddonBalance => booking.addOnItems?.fold(0, (sum, item) => sum! + item.price.toInt()) ?? 0;
+ void init() async {
+ try {
+ // final user = await profileRepository.fetchProfileSettings();
+ // emit(state.clubPointsFetched(user.points));
+ } catch (e) {
+ emit(state.copyWith(error: e as Error));
+ }
+ }
+
+ int get totalAddonBalance =>
+ booking.addOnItems?.fold(0, (sum, item) => sum! + item.price.toInt()) ??
+ 0;
+
+ bool get canContinueToPayment =>
+ booking.balance != 0 || (booking.addOnItems?.isNotEmpty ?? false);
- bool get canContinueToPayment => booking.balance != 0 || (booking.addOnItems?.isNotEmpty ?? false);
+ void onAcceptTermsChanged(bool value) {
+ if (value) {
+ emit(state.termsAccepted());
+ } else {
+ emit(state.termsDenied());
+ }
+ }
+
+ void onApplyClubPointsClicked(bool value) {
+ if (value) {
+ emit(state.clubPointsApplied());
+ } else {
+ emit(state.clubPointsRemoved());
+ }
+ }
+ void showTermsAndConditions() {
+ launchUrl(Uri.parse(ComwellUrls.termsAndConditions));
+ }
}
diff --git a/comwell_key_app/lib/my_booking/cubit/my_booking_state.dart b/comwell_key_app/lib/my_booking/cubit/my_booking_state.dart
index 5c40753c..dc85e800 100644
--- a/comwell_key_app/lib/my_booking/cubit/my_booking_state.dart
+++ b/comwell_key_app/lib/my_booking/cubit/my_booking_state.dart
@@ -1,25 +1,107 @@
import 'package:comwell_key_app/overview/models/booking.dart';
+import 'package:comwell_key_app/services/models/booking_dto.dart';
+import 'package:easy_localization/easy_localization.dart';
import 'package:equatable/equatable.dart';
class MyBookingState extends Equatable {
+ final Iterable<BookingAddonItem> _items;
final Error? error;
final bool isLoading;
final Booking? booking;
+ final bool applyClubPoints;
+ final int clubPoints;
+ final bool isTermsAccepted;
+ final bool showTermsError;
const MyBookingState({
required this.booking,
+ required Iterable<BookingAddonItem> items,
this.error,
required this.isLoading,
- });
+ required this.applyClubPoints,
+ required this.clubPoints,
+ required this.isTermsAccepted,
+ required this.showTermsError,
+ }) : _items = items;
+
+ int get totalPriceBeforeDiscount => _sumOfList(_items);
+
+ int get totalPriceAfterDiscount => _sumOfList(items);
+
+ int get totalPrice => _sumOfList(items);
+
+ Iterable<BookingAddonItem> get items {
+ if (applyClubPoints) {
+ return [
+ ..._items,
+ BookingAddonItem(
+ "discount".tr(), "discount".tr(), clubPoints * -1, clubPoints * -1)
+ ];
+ }
+
+ return _items;
+ }
+
+ int _sumOfList(Iterable<BookingAddonItem> list) {
+ if (list.isEmpty) return 0;
+ return list
+ .map((item) => item.price)
+ .reduce((total, price) => total + price);
+ }
+
+ MyBookingState.initial(Booking booking)
+ : isTermsAccepted = false,
+ error = null,
+ isLoading = false,
+ showTermsError = false,
+ clubPoints = 0,
+ applyClubPoints = false,
+ booking = booking,
+ _items = [];
+
+ MyBookingState termsAccepted() =>
+ copyWith(isTermsAccepted: true, showTermsError: false);
+
+ MyBookingState termsDenied() => copyWith(isTermsAccepted: false);
+
+ MyBookingState clubPointsApplied() => copyWith(applyClubPoints: true);
+
+ MyBookingState clubPointsRemoved() => copyWith(applyClubPoints: false);
+
+ MyBookingState clubPointsFetched(int clubPoints) =>
+ copyWith(clubPoints: clubPoints, items: _items);
+
+ MyBookingState showAcceptTermsError() => copyWith(showTermsError: true);
@override
- List<Object?> get props => [booking, error, isLoading];
+ List<Object?> get props => [
+ booking,
+ error,
+ isLoading,
+ applyClubPoints,
+ clubPoints,
+ isTermsAccepted,
+ showTermsError,
+ _items
+ ];
- MyBookingState copyWith({Booking? booking}) {
+ MyBookingState copyWith(
+ {Booking? booking,
+ bool? applyClubPoints,
+ Error? error,
+ int? clubPoints,
+ bool? isTermsAccepted,
+ bool? showTermsError,
+ Iterable<BookingAddonItem>? items}) {
return MyBookingState(
booking: booking ?? this.booking,
- error: error,
+ error: error ?? this.error,
isLoading: isLoading,
+ applyClubPoints: applyClubPoints ?? this.applyClubPoints,
+ clubPoints: clubPoints ?? this.clubPoints,
+ isTermsAccepted: isTermsAccepted ?? this.isTermsAccepted,
+ showTermsError: showTermsError ?? this.showTermsError,
+ items: items ?? _items,
);
}
}
diff --git a/comwell_key_app/lib/my_booking/pages/my_booking_payment_page.dart b/comwell_key_app/lib/my_booking/pages/my_booking_payment_page.dart
new file mode 100644
index 00000000..ad2def50
--- /dev/null
+++ b/comwell_key_app/lib/my_booking/pages/my_booking_payment_page.dart
@@ -0,0 +1,63 @@
+import 'package:comwell_key_app/common/components/comwell_app_bar.dart';
+import 'package:comwell_key_app/common/template_pages/payment_page_template.dart';
+import 'package:comwell_key_app/my_booking/cubit/my_booking_cubit.dart';
+import 'package:comwell_key_app/my_booking/cubit/my_booking_state.dart';
+import 'package:comwell_key_app/themes/light_theme.dart';
+import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+
+class MyBookingPaymentPage extends StatelessWidget {
+ const MyBookingPaymentPage({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return BlocBuilder<MyBookingCubit, MyBookingState>(
+ builder: (context, state) {
+ final theme = Theme.of(context);
+ final cubit = context.read<MyBookingCubit>();
+ final addOnItems = cubit.state.items;
+ final applyClubPoints = cubit.state.applyClubPoints;
+ final totalPriceBeforeDiscount = cubit.state.totalPriceBeforeDiscount;
+ final totalPriceAfterDiscount = cubit.state.totalPriceAfterDiscount;
+ final trimmedBalance = cubit.totalAddonBalance;
+ final clubPoints = cubit.state.clubPoints;
+ final isTermsAccepted = cubit.state.isTermsAccepted;
+ final onAcceptTermsChanged = cubit.onAcceptTermsChanged;
+ final showError = cubit.state.showTermsError;
+ final onShowTermsAndConditions = cubit.showTermsAndConditions;
+ final onApplyClubPointsChanged = cubit.onApplyClubPointsClicked;
+
+ return Scaffold(
+ appBar: const ComwellAppBar(),
+ body: PaymentPageTemplate(
+ addOnItems: addOnItems,
+ applyClubPoints: applyClubPoints,
+ totalPriceBeforeDiscount: totalPriceBeforeDiscount,
+ totalPriceAfterDiscount: totalPriceAfterDiscount,
+ trimmedBalance: trimmedBalance,
+ clubPoints: clubPoints,
+ isTermsAccepted: isTermsAccepted,
+ onAcceptTermsChanged: onAcceptTermsChanged,
+ showError: showError,
+ onShowTermsAndConditions: onShowTermsAndConditions,
+ onApplyClubPointsChanged: onApplyClubPointsChanged),
+ bottomNavigationBar: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ const Divider(color: colorDivider),
+ Padding(
+ padding: const EdgeInsets.only(left: 16.0, right: 16.0, bottom: 24.0, top: 16.0),
+ child: ElevatedButton(
+ onPressed: () {},
+ child: Text("pay_bill".tr(),
+ style: theme.textTheme.bodyMedium
+ ?.copyWith(color: Colors.white)),
+ ),
+ ),
+ ],
+ ),
+ );
+ });
+ }
+}
diff --git a/comwell_key_app/lib/routing/app_router.dart b/comwell_key_app/lib/routing/app_router.dart
index 2400296a..37b4f89f 100644
--- a/comwell_key_app/lib/routing/app_router.dart
+++ b/comwell_key_app/lib/routing/app_router.dart
@@ -29,6 +29,7 @@ import 'package:comwell_key_app/login/login_page.dart';
import 'package:comwell_key_app/my_booking/cubit/my_booking_cubit.dart';
import 'package:comwell_key_app/my_booking/my_booking_page.dart';
import 'package:comwell_key_app/my_booking/my_booking_repository.dart';
+import 'package:comwell_key_app/my_booking/pages/my_booking_payment_page.dart';
import 'package:comwell_key_app/notifications/cubit/notifications_cubit.dart';
import 'package:comwell_key_app/notifications/notifications_page.dart';
import 'package:comwell_key_app/notifications/notifications_repository.dart';
@@ -300,6 +301,19 @@ GoRouter goRouter() {
child: MyBookingPage(booking: booking),
);
}),
+ GoRoute(
+ path: "/${AppRoutes.payMyBooking.name}",
+ name: AppRoutes.payMyBooking.name,
+ builder: (context, state) {
+ final booking = state.extra as Booking;
+ return BlocProvider(
+ create: (context) => MyBookingCubit(
+ locator<MyBookingRepository>(),
+ initialBooking: booking,
+ )..init(),
+ child: const MyBookingPaymentPage(),
+ );
+ }),
GoRoute(
path: "/${AppRoutes.paymentCards.name}",
name: AppRoutes.paymentCards.name,
@@ -483,7 +497,7 @@ GoRouter goRouter() {
builder: (context, state) {
final cubit = context.read<UpSalesCubit>();
cubit.addUpSalesToBooking();
-
+
return BlocBuilder<UpSalesCubit, UpSalesState>(
builder: (context, state) {
return UpSalesProcessingPage(key: ValueKey(state));