6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 09fa12d8

AuthorNKL<nikolaj.king@gmail.com>
Date2024-11-20 15:33:17 +0100
finished implementation waiting for backend support

Changed files

comwell_key_app/assets/translations/da-DK.json     |  6 +++-
 comwell_key_app/assets/translations/en-US.json     |  6 +++-
 .../authentication/authentication_repository.dart  |  4 +--
 .../lib/common/components/generic_dialog.dart      | 14 +++------
 comwell_key_app/lib/comwell_app.dart               |  2 +-
 comwell_key_app/lib/overview/overview_page.dart    |  3 +-
 .../cubit/profile_settings_cubit.dart              | 16 ++++++++++-
 .../profile_settings/profile_settings_page.dart    | 33 +++++++++++++++++++---
 .../profile_settings_repository.dart               |  6 +++-
 comwell_key_app/lib/routing/app_router.dart        |  3 +-
 comwell_key_app/lib/services/api.dart              |  4 +++
 11 files changed, 74 insertions(+), 23 deletions(-)

Diff

diff --git a/comwell_key_app/assets/translations/da-DK.json b/comwell_key_app/assets/translations/da-DK.json
index f27d68ef..b766a8a5 100644
--- a/comwell_key_app/assets/translations/da-DK.json
+++ b/comwell_key_app/assets/translations/da-DK.json
@@ -73,7 +73,11 @@
"booking_not_found": "Booking blev ikke fundet",
"booking_not_found_subtitle": "Den booking du leder efter, kunne ikke findes. \nHar du skrevet oplysningerne korrekt?",
"booking_not_found_button": "Prøv igen",
- "booking_not_found_cancel": "Annuller"
+ "booking_not_found_cancel": "Annuller",
+ "delete_profile_title": "Du er ved at slette din profil",
+ "delete_profile_description": "Når du sletter din profil, mister du overblik over tidligere ophold samt dine Comwell Club point",
+ "delete_profile_button": "Slet profil",
+ "delete_profile_cancel": "Annuller"
diff --git a/comwell_key_app/assets/translations/en-US.json b/comwell_key_app/assets/translations/en-US.json
index c885b1ec..895ff943 100644
--- a/comwell_key_app/assets/translations/en-US.json
+++ b/comwell_key_app/assets/translations/en-US.json
@@ -73,5 +73,9 @@
"booking_not_found": "Booking not found",
"booking_not_found_subtitle": "We could not find a booking with the information you provided.",
"booking_not_found_button": "Try again",
- "booking_not_found_cancel": "Cancel"
+ "booking_not_found_cancel": "Cancel",
+ "delete_profile_title": "You are about to delete your profile",
+ "delete_profile_description": "Are you sure you want to delete your profile? This action cannot be undone.",
+ "delete_profile_button": "Delete profile",
+ "delete_profile_cancel": "Cancel"
}
\ No newline at end of file
diff --git a/comwell_key_app/lib/authentication/authentication_repository.dart b/comwell_key_app/lib/authentication/authentication_repository.dart
index f4d40600..18f18de1 100644
--- a/comwell_key_app/lib/authentication/authentication_repository.dart
+++ b/comwell_key_app/lib/authentication/authentication_repository.dart
@@ -22,8 +22,8 @@ class AuthenticationRepository {
_controller.sink.add(AuthenticationStatus.authenticated);
}
- void logOut() {
- secureStorage.deleteAll();
+ Future logOut() async{
+ await secureStorage.deleteAll();
_controller.sink.add(AuthenticationStatus.unauthenticated);
}
diff --git a/comwell_key_app/lib/common/components/generic_dialog.dart b/comwell_key_app/lib/common/components/generic_dialog.dart
index 0088bf14..3a1f2371 100644
--- a/comwell_key_app/lib/common/components/generic_dialog.dart
+++ b/comwell_key_app/lib/common/components/generic_dialog.dart
@@ -6,6 +6,7 @@ class GenericDialog extends StatelessWidget {
final String title;
final String content;
final String confirmButtonText;
+ final Color confirmButtonTextColor;
final String cancelButtonText;
final VoidCallback onConfirm;
final VoidCallback onCancel;
@@ -15,6 +16,7 @@ class GenericDialog extends StatelessWidget {
required this.title,
required this.content,
required this.confirmButtonText,
+ required this.confirmButtonTextColor,
required this.cancelButtonText,
required this.onConfirm,
required this.onCancel,
@@ -57,11 +59,7 @@ class GenericDialog extends StatelessWidget {
onPressed: onConfirm,
child: Text(
confirmButtonText,
- style: const TextStyle(
- fontSize: 16,
- fontWeight: FontWeight.w600,
- color: Colors.black,
- ),
+ style: theme.textTheme.headlineSmall?.copyWith(color: confirmButtonTextColor),
),
),
),
@@ -76,11 +74,7 @@ class GenericDialog extends StatelessWidget {
onPressed: onCancel,
child: Text(
cancelButtonText,
- style: const TextStyle(
- fontSize: 16,
- fontWeight: FontWeight.w600,
- color: Colors.white,
- ),
+ style: theme.textTheme.headlineSmall?.copyWith(color: Colors.white)
),
),
),
diff --git a/comwell_key_app/lib/comwell_app.dart b/comwell_key_app/lib/comwell_app.dart
index 9d35d8b1..d432d711 100644
--- a/comwell_key_app/lib/comwell_app.dart
+++ b/comwell_key_app/lib/comwell_app.dart
@@ -66,7 +66,7 @@ final List<BlocProvider> blocProviderList = [
),
BlocProvider<ProfileSettingsCubit>(
lazy: false,
- create: (BuildContext context) => ProfileSettingsCubit(profileSettingsRepository: ProfileSettingsRepository()),
+ create: (BuildContext context) => ProfileSettingsCubit(profileSettingsRepository: ProfileSettingsRepository(), authenticationRepository: AuthenticationRepository()),
),
];
diff --git a/comwell_key_app/lib/overview/overview_page.dart b/comwell_key_app/lib/overview/overview_page.dart
index 44bcd131..e72df975 100644
--- a/comwell_key_app/lib/overview/overview_page.dart
+++ b/comwell_key_app/lib/overview/overview_page.dart
@@ -114,7 +114,7 @@ class OverviewTabViewState extends State<OverviewPage>
],
),
)
- : ,
+ : const Center(child: CircularProgressIndicator()),
OutlinedButton.icon(
onPressed: () async {
context.pushNamed(AppRoutes.findBooking.name);
@@ -148,6 +148,7 @@ class OverviewTabViewState extends State<OverviewPage>
title: "booking_not_found".tr(),
content: "booking_not_found_subtitle".tr(),
confirmButtonText: "booking_not_found_button".tr(),
+ confirmButtonTextColor: Colors.black,
cancelButtonText: "booking_not_found_cancel".tr(),
onConfirm: () {
context.pushNamed(AppRoutes.findBooking.name);
diff --git a/comwell_key_app/lib/profile_settings/cubit/profile_settings_cubit.dart b/comwell_key_app/lib/profile_settings/cubit/profile_settings_cubit.dart
index 2051aaa3..444633c1 100644
--- a/comwell_key_app/lib/profile_settings/cubit/profile_settings_cubit.dart
+++ b/comwell_key_app/lib/profile_settings/cubit/profile_settings_cubit.dart
@@ -1,4 +1,5 @@
import 'package:bloc/bloc.dart';
+import 'package:comwell_key_app/authentication/authentication_repository.dart';
import 'package:comwell_key_app/profile_settings/model/user.dart';
import 'package:comwell_key_app/profile_settings/profile_settings_repository.dart';
import 'package:equatable/equatable.dart';
@@ -7,7 +8,8 @@ part 'profile_settings_state.dart';
class ProfileSettingsCubit extends Cubit<ProfileSettingsState> {
final ProfileSettingsRepository profileSettingsRepository;
- ProfileSettingsCubit({required this.profileSettingsRepository}) : super(ProfileSettingsInitial());
+ final AuthenticationRepository authenticationRepository;
+ ProfileSettingsCubit({required this.profileSettingsRepository, required this.authenticationRepository}) : super(ProfileSettingsInitial());
void fetchProfileSettings() async {
emit(ProfileSettingsLoading());
@@ -19,4 +21,16 @@ class ProfileSettingsCubit extends Cubit<ProfileSettingsState> {
emit(ProfileSettingsError());
}
}
+
+ void deleteProfile() async {
+ try {
+ // Delete profile
+ //await profileSettingsRepository.deleteProfile();
+ //await authenticationRepository.logOut();
+
+
+ } catch (e) {
+ emit(ProfileSettingsError());
+ }
+ }
}
diff --git a/comwell_key_app/lib/profile_settings/profile_settings_page.dart b/comwell_key_app/lib/profile_settings/profile_settings_page.dart
index 152d2156..a25aa337 100644
--- a/comwell_key_app/lib/profile_settings/profile_settings_page.dart
+++ b/comwell_key_app/lib/profile_settings/profile_settings_page.dart
@@ -1,4 +1,7 @@
+import 'package:comwell_key_app/authentication/bloc/authentication_bloc.dart';
+import 'package:comwell_key_app/authentication/bloc/authentication_bloc.dart';
import 'package:comwell_key_app/common/components/comwell_app_bar.dart';
+import 'package:comwell_key_app/common/components/generic_dialog.dart';
import 'package:comwell_key_app/profile_settings/components/Text_field_trailing_icon.dart';
import 'package:comwell_key_app/common/components/comwell_text_field.dart';
import 'package:comwell_key_app/profile_settings/components/date_time_picker.dart';
@@ -28,7 +31,7 @@ class ProfileSettingsPage extends StatelessWidget {
backgroundColor: Colors.white,
body: Center(child: CircularProgressIndicator()));
} else if (state is ProfileSettingsLoaded) {
- return _buildProfileSettingsPage(theme, state);
+ return _buildProfileSettingsPage(theme, state, context);
} else {
return Scaffold(
appBar: const ComwellAppBar(
@@ -46,7 +49,7 @@ class ProfileSettingsPage extends StatelessWidget {
}
Widget _buildProfileSettingsPage(
- ThemeData theme, ProfileSettingsState state) {
+ ThemeData theme, ProfileSettingsState state, BuildContext context) {
final ProfileSettingsLoaded loadedState = state as ProfileSettingsLoaded;
return Scaffold(
backgroundColor: Colors.white,
@@ -89,7 +92,6 @@ class ProfileSettingsPage extends StatelessWidget {
),
const SizedBox(height: 8),
TextFieldWithTrailingIcon(
-
title: "profil_settings_address".tr(),
text:
"${loadedState.user.address.street}, ${loadedState.user.address.city}, ${loadedState.user.address.zipCode}, ${loadedState.user.address.country}",
@@ -111,7 +113,9 @@ class ProfileSettingsPage extends StatelessWidget {
const SizedBox(height: 40),
Center(
child: OutlinedButton(
- onPressed: () {},
+ onPressed: () {
+ showDeleteProfileDialog(context);
+ },
style: OutlinedButton.styleFrom(
side: const BorderSide(color: colorDivider),
backgroundColor: Colors.transparent,
@@ -142,4 +146,25 @@ class ProfileSettingsPage extends StatelessWidget {
),
);
}
+
+ Future<void> showDeleteProfileDialog(BuildContext context) {
+ return showDialog<void>(
+ context: context,
+ builder: (BuildContext context) {
+ return GenericDialog(
+ title: 'delete_profile_title'.tr(),
+ content: 'delete_profile_description'.tr(),
+ confirmButtonText: 'delete_profile_button'.tr(),
+ confirmButtonTextColor: Colors.red,
+ cancelButtonText: 'delete_profile_cancel'.tr(),
+ onConfirm: () => {
+ context.read<ProfileSettingsCubit>().deleteProfile(),
+ context
+ .read<AuthenticationBloc>()
+ .add(AuthenticationLogoutPressed())
+ },
+ onCancel: () => Navigator.of(context).pop());
+ },
+ );
+ }
}
diff --git a/comwell_key_app/lib/profile_settings/profile_settings_repository.dart b/comwell_key_app/lib/profile_settings/profile_settings_repository.dart
index 87be0d10..98a793ed 100644
--- a/comwell_key_app/lib/profile_settings/profile_settings_repository.dart
+++ b/comwell_key_app/lib/profile_settings/profile_settings_repository.dart
@@ -1,6 +1,5 @@
import 'package:comwell_key_app/profile_settings/model/user.dart';
import 'package:comwell_key_app/services/api.dart';
-import 'package:shared_preferences/shared_preferences.dart';
import 'dart:convert';
class ProfileSettingsRepository {
@@ -14,4 +13,9 @@ class ProfileSettingsRepository {
}
return null;
}
+
+ Future<void> deleteProfile() {
+
+ return api.deleteProfile();
+ }
}
\ No newline at end of file
diff --git a/comwell_key_app/lib/routing/app_router.dart b/comwell_key_app/lib/routing/app_router.dart
index 2e535a72..07522b6f 100644
--- a/comwell_key_app/lib/routing/app_router.dart
+++ b/comwell_key_app/lib/routing/app_router.dart
@@ -21,7 +21,7 @@ final _rootNavigatorKey = GlobalKey<NavigatorState>();
GoRouter goRouter(AuthenticationBloc authBloc) {
return GoRouter(
- initialLocation: '/oauthredirect',
+ initialLocation: '/login',
navigatorKey: _rootNavigatorKey,
debugLogDiagnostics: true,
refreshListenable:
@@ -51,6 +51,7 @@ GoRouter goRouter(AuthenticationBloc authBloc) {
return null;
},
routes: <RouteBase>[
+
GoRoute(
path: '/loading_page',
name: AppRoutes.loadingPage.name,
diff --git a/comwell_key_app/lib/services/api.dart b/comwell_key_app/lib/services/api.dart
index 179baa54..cf7ac715 100644
--- a/comwell_key_app/lib/services/api.dart
+++ b/comwell_key_app/lib/services/api.dart
@@ -53,4 +53,8 @@ class Api {
}
''';
}
+
+ Future<void> deleteProfile() {
+ return dio.post('/deleteProfile');
+ }
}