6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 924f4567

AuthorEdmir Suljic<esu@dwarf.dk>
Date2025-05-19 12:47:31 +0200
Resolved bug where housekeeping state is not updated

Changed files

comwell_key_app/assets/translations/da-DK.json          |  1 +
 .../lib/booking_details/bloc/booking_details_bloc.dart  |  3 ++-
 .../lib/booking_details/bloc/booking_details_state.dart |  2 +-
 .../lib/booking_details/booking_details_page.dart       | 15 ++++++++++-----
 .../lib/booking_details/booking_details_repository.dart | 17 +++++++++++------
 .../booking_details/components/housekeeping_button.dart |  5 +++--
 .../lib/housekeeping/housekeeping_cubit.dart            |  8 ++++----
 comwell_key_app/lib/housekeeping/housekeeping_page.dart | 15 +++++++++------
 .../lib/housekeeping/housekeeping_repository.dart       | 10 ++++++----
 comwell_key_app/lib/routing/app_router.dart             |  3 ++-
 10 files changed, 49 insertions(+), 30 deletions(-)

Diff

diff --git a/comwell_key_app/assets/translations/da-DK.json b/comwell_key_app/assets/translations/da-DK.json
index f951cfd1..be8add42 100644
--- a/comwell_key_app/assets/translations/da-DK.json
+++ b/comwell_key_app/assets/translations/da-DK.json
@@ -138,6 +138,7 @@
"housekeeping_page_service_title_refill": "Genopfyldning af kaffe og te",
"housekeeping_page_service_title_trash": "Afhentning af skrald",
"housekeeping_page_service_title_soap": "Sæbe/shampoo",
+ "housekeeping_page_cleaning": "Rengøring",
"housekeeping_page_service_cleaning_subtitle": "Der bliver gjort rent mellem 11 og 14",
"housekeeping_page_supplies": "Forsyninger",
"booking_details_page_housekeeping_button_title": "Bestil housekeeping",
diff --git a/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart b/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart
index fdc652fd..99341957 100644
--- a/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart
+++ b/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart
@@ -58,7 +58,8 @@ class BookingDetailsBloc
Future<void> checkIfHouseKeepingOrdered(
Emitter<BookingDetailsState> emit) async {
final isHouseKeepingOrdered =
- await bookingDetailsRepository.isHousesKeepingOrdered();
+ await bookingDetailsRepository.isHousesKeepingOrdered(booking.roomNumber);
+
if (isHouseKeepingOrdered) {
emit(state.houseKeepingOrdered());
}
diff --git a/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart b/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
index 81b806d4..645a1848 100644
--- a/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
+++ b/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
@@ -27,7 +27,7 @@ class BookingDetailsState extends Equatable {
copyWith(status: BookingDetailsStatus.keysUpdated, keys: keys);
BookingDetailsState houseKeepingOrdered() => copyWith(
status: BookingDetailsStatus.houseKeepingOrdered,
- isHouseKeepingOrdered: isHouseKeepingOrdered);
+ isHouseKeepingOrdered: true);
BookingDetailsState updateGuests(Iterable<Guest> guests) =>
copyWith(status: BookingDetailsStatus.guestsUpdated, guests: guests);
diff --git a/comwell_key_app/lib/booking_details/booking_details_page.dart b/comwell_key_app/lib/booking_details/booking_details_page.dart
index 9161ab02..d8816ddb 100644
--- a/comwell_key_app/lib/booking_details/booking_details_page.dart
+++ b/comwell_key_app/lib/booking_details/booking_details_page.dart
@@ -26,9 +26,9 @@ class BookingDetailsPage extends StatelessWidget {
builder: (context, state) {
final cubit = context.read<BookingDetailsBloc>();
if (state.status == BookingDetailsStatus.initial) {
-
cubit.add(InitialEvent());
}
+
return Scaffold(
extendBodyBehindAppBar: true,
backgroundColor: sandColor[40],
@@ -83,8 +83,11 @@ class BookingDetailsPage extends StatelessWidget {
),
BottomSheetWidget(
widgetChildren: [
- HousekeepingButton(
- key: ValueKey(state.isHouseKeepingOrdered)),
+ cubit.booking.roomNumber != ''
+ ? HousekeepingButton(
+ key: ValueKey(state.isHouseKeepingOrdered),
+ roomNumber: cubit.booking.roomNumber)
+ : const SizedBox(),
const SizedBox(height: 20),
const CheckOutButton(),
const SizedBox(height: 20),
@@ -144,7 +147,8 @@ class BookingDetailsPage extends StatelessWidget {
);
}
- Widget _buildBookingDetails(BuildContext context, BookingDetailsState state, BookingDetailsBloc cubit) {
+ Widget _buildBookingDetails(BuildContext context, BookingDetailsState state,
+ BookingDetailsBloc cubit) {
final theme = Theme.of(context);
return InkWell(
@@ -199,7 +203,8 @@ class BookingDetailsPage extends StatelessWidget {
),
const SizedBox(width: 12),
Text(
- 'total_charge_value'.tr(args: [cubit.booking.totalCharge.toString()]),
+ 'total_charge_value'
+ .tr(args: [cubit.booking.totalCharge.toString()]),
style: theme.textTheme.bodyMedium?.copyWith(
color: Colors.white,
),
diff --git a/comwell_key_app/lib/booking_details/booking_details_repository.dart b/comwell_key_app/lib/booking_details/booking_details_repository.dart
index 364e4d81..146ad959 100644
--- a/comwell_key_app/lib/booking_details/booking_details_repository.dart
+++ b/comwell_key_app/lib/booking_details/booking_details_repository.dart
@@ -11,17 +11,22 @@ class BookingDetailsRepository {
final secureStorage = SecureStorage();
final ComwellDatabase database = locator<ComwellDatabase>();
- Future<bool> isHousesKeepingOrdered() async {
+ Future<bool> isHousesKeepingOrdered(String roomNumber) async {
final lastOrderedValue = await secureStorage
- .read(HouseKeepingRepository.houseKeepingLastOrderedKey);
+ .read(HouseKeepingRepository.houseKeepingLastOrderedKey(roomNumber));
if (lastOrderedValue != null) {
final lastOrdered =
- DateTime.fromMillisecondsSinceEpoch(int.parse(lastOrderedValue));
- final dayOfLastOrder = lastOrdered.day;
- final dayOfToday = DateTime.now().day;
+ DateTime.fromMillisecondsSinceEpoch(int.parse(lastOrderedValue))
+ .copyWith(hour: 0, minute: 0, second: 0);
+
+ final isToday = DateTime.now().copyWith(hour: 0, minute: 0, second: 0);
+ final isNextDay = DateTime.now().isAfter(isToday) &&
+ DateTime.now().isAfter(lastOrdered);
final timeOfToday = DateTime.now().hour;
- return dayOfToday > dayOfLastOrder &&
+ final isHouseKeepingAllowed = isNextDay &&
timeOfToday > 2; // If it's after 3am on the day after the order
+
+ return isHouseKeepingAllowed;
}
return false;
}
diff --git a/comwell_key_app/lib/booking_details/components/housekeeping_button.dart b/comwell_key_app/lib/booking_details/components/housekeeping_button.dart
index 9a003106..3c15f29e 100644
--- a/comwell_key_app/lib/booking_details/components/housekeeping_button.dart
+++ b/comwell_key_app/lib/booking_details/components/housekeeping_button.dart
@@ -9,7 +9,8 @@ import '../../themes/dark_theme.dart';
import '../bloc/booking_details_bloc.dart';
class HousekeepingButton extends StatelessWidget {
- const HousekeepingButton({super.key});
+ final String roomNumber;
+ const HousekeepingButton({super.key, required this.roomNumber});
@override
Widget build(BuildContext context) {
@@ -18,7 +19,7 @@ class HousekeepingButton extends StatelessWidget {
borderRadius: BorderRadius.circular(10),
onTap: () async {
if (bloc.state.isHouseKeepingOrdered) return;
- await context.pushNamed(AppRoutes.houseKeeping.name);
+ await context.pushNamed(AppRoutes.houseKeeping.name, extra: roomNumber);
if(!bloc.isClosed) bloc.add(CheckIfHouseKeepingOrdered());
},
child: Container(
diff --git a/comwell_key_app/lib/housekeeping/housekeeping_cubit.dart b/comwell_key_app/lib/housekeeping/housekeeping_cubit.dart
index 44ee0595..f568334d 100644
--- a/comwell_key_app/lib/housekeeping/housekeeping_cubit.dart
+++ b/comwell_key_app/lib/housekeeping/housekeeping_cubit.dart
@@ -39,10 +39,10 @@ class HouseKeepingCubit extends Cubit<HouseKeepingState> {
}
}
- Future<void> onOrderHousekeepingClicked() async {
- await houseKeepingRepository.saveHouseKeepingOrdered();
+ Future<void> onOrderHousekeepingClicked(String roomNumber) async {
+ await houseKeepingRepository.saveHouseKeepingOrdered(roomNumber);
final analyticsEventItem = AnalyticsEventItem(
- hotelName: "Comwell",// TODO: Add hotel name,
+ hotelName: "Comwell",
currency: "DKK",
value: 0,
placement: "housekeeping_page",
@@ -53,4 +53,4 @@ class HouseKeepingCubit extends Cubit<HouseKeepingState> {
quantity: 1);
tracking.trackAddToCart(analyticsEventItem);
}
-}
+}
\ No newline at end of file
diff --git a/comwell_key_app/lib/housekeeping/housekeeping_page.dart b/comwell_key_app/lib/housekeeping/housekeeping_page.dart
index d4dd9a11..55b2163f 100644
--- a/comwell_key_app/lib/housekeeping/housekeeping_page.dart
+++ b/comwell_key_app/lib/housekeeping/housekeeping_page.dart
@@ -10,15 +10,18 @@ import 'package:go_router/go_router.dart';
import '../common/components/comwell_app_bar.dart';
class HousekeepingPage extends StatefulWidget {
- const HousekeepingPage({super.key});
+ final String roomNumber;
+ const HousekeepingPage({super.key, required this.roomNumber});
@override
State<HousekeepingPage> createState() => _HousekeepingPageState();
}
class _HousekeepingPageState extends State<HousekeepingPage> {
+
@override
Widget build(BuildContext context) {
+ final theme = Theme.of(context);
return BlocProvider(
create: (context) => HouseKeepingCubit(),
child: BlocBuilder<HouseKeepingCubit, HouseKeepingState>(
@@ -42,7 +45,7 @@ class _HousekeepingPageState extends State<HousekeepingPage> {
padding: const EdgeInsets.all(16.0),
child: ElevatedButton(
onPressed: () async {
- await cubit.onOrderHousekeepingClicked();
+ await cubit.onOrderHousekeepingClicked(widget.roomNumber);
if (context.mounted) {
context.pop();
}
@@ -70,16 +73,16 @@ class _HousekeepingPageState extends State<HousekeepingPage> {
children: [
const SizedBox(height: 20),
Text("housekeeping_page_title".tr(),
- style: Theme.of(context).textTheme.headlineLarge),
+ style: theme.textTheme.headlineLarge),
const SizedBox(height: 8),
Text(
"housekeeping_page_subtitle".tr(),
- style: Theme.of(context).textTheme.bodyMedium,
+ style: theme.textTheme.bodySmall,
),
const SizedBox(height: 25),
Text(
"housekeeping_page_cleaning".tr(),
- style: Theme.of(context).textTheme.headlineMedium,
+ style: theme.textTheme.headlineMedium,
),
const SizedBox(height: 12),
SelectableService(
@@ -88,7 +91,7 @@ class _HousekeepingPageState extends State<HousekeepingPage> {
),
const SizedBox(height: 22),
Text("housekeeping_page_supplies".tr(),
- style: Theme.of(context).textTheme.headlineMedium),
+ style: theme.textTheme.headlineMedium),
const SizedBox(height: 12),
...cubit.servicesSupplies.map((service) {
return Column(
diff --git a/comwell_key_app/lib/housekeeping/housekeeping_repository.dart b/comwell_key_app/lib/housekeeping/housekeeping_repository.dart
index 1996b4f6..90be737f 100644
--- a/comwell_key_app/lib/housekeeping/housekeeping_repository.dart
+++ b/comwell_key_app/lib/housekeeping/housekeeping_repository.dart
@@ -3,9 +3,11 @@ import '../utils/secure_storage.dart';
class HouseKeepingRepository {
final secureStorage = SecureStorage();
- Future<void> saveHouseKeepingOrdered() async {
- await secureStorage.write(houseKeepingLastOrderedKey, DateTime.now().millisecondsSinceEpoch.toString());
+ Future<void> saveHouseKeepingOrdered(String roomNumber) async {
+ await secureStorage.write(houseKeepingLastOrderedKey(roomNumber),
+ DateTime.now().millisecondsSinceEpoch.toString());
}
- static const houseKeepingLastOrderedKey = 'housekeeping_last_ordered';
-}
\ No newline at end of file
+ static String houseKeepingLastOrderedKey(String roomNumber) =>
+ 'housekeeping_last_ordered_$roomNumber';
+}
diff --git a/comwell_key_app/lib/routing/app_router.dart b/comwell_key_app/lib/routing/app_router.dart
index 61f43078..05a5616f 100644
--- a/comwell_key_app/lib/routing/app_router.dart
+++ b/comwell_key_app/lib/routing/app_router.dart
@@ -318,7 +318,8 @@ GoRouter goRouter() {
path: "/${AppRoutes.houseKeeping.name}",
name: AppRoutes.houseKeeping.name,
builder: (context, state) {
- return const HousekeepingPage();
+ final roomNumber = state.extra as String;
+ return HousekeepingPage(roomNumber: roomNumber);
},
),
GoRoute(