diff --git a/lib/core/app_router.dart b/lib/core/app_router.dart index 9dc8612f..c5d173d2 100644 --- a/lib/core/app_router.dart +++ b/lib/core/app_router.dart @@ -228,7 +228,7 @@ class AppRouter { return '/auth-screen'; } } catch (e) { - rethrow; + return '/feed-screen'; } }, ), diff --git a/lib/features/profile/repositories/profile_repository.dart b/lib/features/profile/repositories/profile_repository.dart index 75879d15..05399457 100644 --- a/lib/features/profile/repositories/profile_repository.dart +++ b/lib/features/profile/repositories/profile_repository.dart @@ -203,4 +203,12 @@ class ProfileRepository { return false; } } + + Future deleteAccount() async { + try { + await profileService.deleteAccount(); + } catch (e) { + rethrow; + } + } } diff --git a/lib/features/profile/services/profile_service.dart b/lib/features/profile/services/profile_service.dart index 06af37b9..a1208526 100644 --- a/lib/features/profile/services/profile_service.dart +++ b/lib/features/profile/services/profile_service.dart @@ -119,4 +119,7 @@ abstract class ProfileService { Future tryVerifyEmailByCode({ @Body() required String code, }); + + @DELETE('/api/profile/delete_my_account') + Future deleteAccount(); } diff --git a/lib/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart b/lib/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart index d3995d6a..3cb047f6 100644 --- a/lib/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart +++ b/lib/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart @@ -67,4 +67,13 @@ class SettingsCubit extends Cubit { await init(); } } + + Future deleteAccount() async { + try { + await profileRepository.deleteAccount(); + return true; + } catch (e) { + return false; + } + } } diff --git a/lib/features/settings/presentation/pages/settings_screen.dart b/lib/features/settings/presentation/pages/settings_screen.dart index 67460955..af99f901 100644 --- a/lib/features/settings/presentation/pages/settings_screen.dart +++ b/lib/features/settings/presentation/pages/settings_screen.dart @@ -1,12 +1,19 @@ +import 'package:eatvio_app/core/app_router.dart'; import 'package:eatvio_app/core/const.dart'; +import 'package:eatvio_app/core/theme/custom_text_style.dart'; +import 'package:eatvio_app/core/widgets/bottom_sheet_handler_bar.dart'; +import 'package:eatvio_app/core/widgets/bottom_sheet_with_blur.dart'; +import 'package:eatvio_app/core/widgets/custom_outlined_button.dart'; import 'package:eatvio_app/core/widgets/data_error_widget.dart'; import 'package:eatvio_app/core/widgets/loader.dart'; +import 'package:eatvio_app/core/widgets/show_error_dialog.dart'; import 'package:eatvio_app/features/consultant/become_consultant/models/consultation_request_model.dart'; import 'package:eatvio_app/features/settings/entities/settings_entity.dart'; import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_cubit.dart'; import 'package:eatvio_app/features/settings/presentation/bloc/settings_cubit/settings_state.dart'; import 'package:eatvio_app/core/locator_service.dart'; import 'package:eatvio_app/core/theme/theme_helper.dart'; +import 'package:eatvio_app/generated/l10n.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -60,7 +67,7 @@ class _SettingsScreenState extends State { _aboutEatvio(state), const SizedBox(height: 12), _becomeConsultantButton(state), - _deleteAccountButton(state), + _deleteAccountButton(state, settingsCubit), ], ), ), @@ -428,11 +435,20 @@ class _SettingsScreenState extends State { return const SizedBox.shrink(); } - Padding _deleteAccountButton(SettingsStateLoaded state) { + Padding _deleteAccountButton(SettingsStateLoaded state, SettingsCubit settingsCubit) { return Padding( padding: const EdgeInsets.symmetric(horizontal: 16), child: InkWell( - onTap: () {}, + onTap: () async { + showBottomSheetWithBlur( + userRootNavigator: true, + context: context, + height: null, + child: DeleteAccountBottomSheet( + cubit: settingsCubit, + ), + ); + }, borderRadius: BorderRadius.circular(20), child: Ink( height: 52, @@ -495,3 +511,73 @@ class _SettingsScreenState extends State { ); } } + +class DeleteAccountBottomSheet extends StatefulWidget { + const DeleteAccountBottomSheet({super.key, required this.cubit}); + final SettingsCubit cubit; + + @override + State createState() => _DeleteAccountBottomSheet(); +} + +class _DeleteAccountBottomSheet extends State { + bool? isFailure; + @override + Widget build(BuildContext context) { + final s = S.of(context); + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 12.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox( + height: 8, + ), + const BottomSheetHandlerBar(), + const SizedBox( + height: 20, + ), + Text(s.accountDeleting, style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black)), + const SizedBox( + height: 16, + ), + Text( + s.youShureYouWantToDeleteAccount, + style: TextStyles.textSMedium.copyWith(color: appTheme.black), + textAlign: TextAlign.center, + ), + const SizedBox( + height: 8, + ), + Text( + s.itCantBeRecovered, + style: TextStyles.textSMedium.copyWith(color: appTheme.black), + textAlign: TextAlign.center, + ), + const SizedBox( + height: 8, + ), + CustomOutlinedButton( + text: s.delete, + height: 52, + buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700), + buttonStyle: ButtonStyle(side: const WidgetStatePropertyAll(BorderSide.none), backgroundColor: WidgetStatePropertyAll(appTheme.blueA400)), + onPressed: () async { + final result = await widget.cubit.deleteAccount(); + if (result == true) { + AppRouter.navigatorKey.currentContext?.go('/auth-screen'); + return; + } + AppRouter.navigatorKey.currentContext?.pop(); + if (!context.mounted) return; + showErrorDialog(context, description: s.cannotDeleteAccount); + }, + ), + const SizedBox( + height: 40, + ), + ], + ), + ); + } +} diff --git a/lib/generated/intl/messages_en.dart b/lib/generated/intl/messages_en.dart index 73db6f27..360b4288 100644 --- a/lib/generated/intl/messages_en.dart +++ b/lib/generated/intl/messages_en.dart @@ -51,6 +51,9 @@ class MessageLookup extends MessageLookupByLibrary { "about_diet": MessageLookupByLibrary.simpleMessage("Об этой диете"), "about_plan": MessageLookupByLibrary.simpleMessage("Об этом плане"), "about_recipe": MessageLookupByLibrary.simpleMessage("Об этом рецепте"), + "accountDeleting": MessageLookupByLibrary.simpleMessage( + "Удаление аккаунта", + ), "active": MessageLookupByLibrary.simpleMessage("Активен"), "active_consultations_count": MessageLookupByLibrary.simpleMessage( "Кол-во активных консультаций", @@ -124,6 +127,9 @@ class MessageLookup extends MessageLookupByLibrary { ), "cancel_diet": MessageLookupByLibrary.simpleMessage("Отменить диету?"), "cancel_order": MessageLookupByLibrary.simpleMessage("Отменить заказ"), + "cannotDeleteAccount": MessageLookupByLibrary.simpleMessage( + "Не получилось удалить ваш аккаунт", + ), "carb_type": MessageLookupByLibrary.simpleMessage("Мучное"), "carb_type_desc": MessageLookupByLibrary.simpleMessage( "Если вы любите мучные продукты, но хотите придерживаться диеты, вам подходит диета с добавленим мучных блюд на основе цельнозерновых вариантов. В них больше сложных углеводов и клетчатки, что способствует длительному чувству сытости и поддерживает здоровье пищеварительной системы.", @@ -256,6 +262,7 @@ class MessageLookup extends MessageLookupByLibrary { ), "days": MessageLookupByLibrary.simpleMessage("дней"), "deception": MessageLookupByLibrary.simpleMessage("Обман"), + "delete": MessageLookupByLibrary.simpleMessage("Удалить"), "deleteComment": MessageLookupByLibrary.simpleMessage( "Удалить комментарий", ), @@ -411,6 +418,9 @@ class MessageLookup extends MessageLookupByLibrary { "invited_people_count": MessageLookupByLibrary.simpleMessage( "Количество приглашенных", ), + "itCantBeRecovered": MessageLookupByLibrary.simpleMessage( + "Его нельзя будет восстановить", + ), "label": MessageLookupByLibrary.simpleMessage("Название"), "language": MessageLookupByLibrary.simpleMessage("Язык"), "last_name": MessageLookupByLibrary.simpleMessage("Фамилия"), @@ -780,6 +790,9 @@ class MessageLookup extends MessageLookupByLibrary { "youShureYouWantToCancelOrder": MessageLookupByLibrary.simpleMessage( "Вы уверены, что хотите отменить заказ?", ), + "youShureYouWantToDeleteAccount": MessageLookupByLibrary.simpleMessage( + "Вы уверены, что хотите удалить аккаунт?", + ), "you_can_not_open_this_day": MessageLookupByLibrary.simpleMessage( "Вы не можете перейти в этот день", ), diff --git a/lib/generated/l10n.dart b/lib/generated/l10n.dart index 5a4e420e..7df3cbcc 100644 --- a/lib/generated/l10n.dart +++ b/lib/generated/l10n.dart @@ -3414,6 +3414,51 @@ class S { args: [], ); } + + /// `Удаление аккаунта` + String get accountDeleting { + return Intl.message( + 'Удаление аккаунта', + name: 'accountDeleting', + desc: '', + args: [], + ); + } + + /// `Вы уверены, что хотите удалить аккаунт?` + String get youShureYouWantToDeleteAccount { + return Intl.message( + 'Вы уверены, что хотите удалить аккаунт?', + name: 'youShureYouWantToDeleteAccount', + desc: '', + args: [], + ); + } + + /// `Его нельзя будет восстановить` + String get itCantBeRecovered { + return Intl.message( + 'Его нельзя будет восстановить', + name: 'itCantBeRecovered', + desc: '', + args: [], + ); + } + + /// `Удалить` + String get delete { + return Intl.message('Удалить', name: 'delete', desc: '', args: []); + } + + /// `Не получилось удалить ваш аккаунт` + String get cannotDeleteAccount { + return Intl.message( + 'Не получилось удалить ваш аккаунт', + name: 'cannotDeleteAccount', + desc: '', + args: [], + ); + } } class AppLocalizationDelegate extends LocalizationsDelegate { diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 6a8fb162..452e2d5a 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -405,7 +405,12 @@ "allowAccess": "Разрешить доступ" , "copy": "Скопировать", "reply": "Ответить", - "deleteComment": "Удалить комментарий" + "deleteComment": "Удалить комментарий", + "accountDeleting": "Удаление аккаунта", + "youShureYouWantToDeleteAccount": "Вы уверены, что хотите удалить аккаунт?", + "itCantBeRecovered": "Его нельзя будет восстановить", + "delete": "Удалить", + "cannotDeleteAccount": "Не получилось удалить ваш аккаунт" }