Procházet zdrojové kódy

Replaced 'Delete account' dialog with new one

ashilkn před 2 roky
rodič
revize
417aedcea7

+ 0 - 10
lib/services/user_service.dart

@@ -229,8 +229,6 @@ class UserService {
     BuildContext context,
     String challengeResponse,
   ) async {
-    final dialog = createProgressDialog(context, "Deleting account...");
-    await dialog.show();
     try {
       final response = await _enteDio.delete(
         "/users/delete",
@@ -241,19 +239,11 @@ class UserService {
       if (response != null && response.statusCode == 200) {
         // clear data
         await Configuration.instance.logout();
-        await dialog.hide();
-        showToast(
-          context,
-          "We have deleted your account and scheduled your uploaded data "
-          "for deletion.",
-        );
-        Navigator.of(context).popUntil((route) => route.isFirst);
       } else {
         throw Exception("delete action failed");
       }
     } catch (e) {
       _logger.severe(e);
-      await dialog.hide();
       showGenericErrorDialog(context);
     }
   }

+ 42 - 16
lib/ui/account/delete_account_page.dart

@@ -8,10 +8,13 @@ import 'package:photos/core/configuration.dart';
 import 'package:photos/models/delete_account.dart';
 import 'package:photos/services/local_authentication_service.dart';
 import 'package:photos/services/user_service.dart';
-import 'package:photos/ui/common/dialogs.dart';
 import 'package:photos/ui/common/gradient_button.dart';
+import 'package:photos/ui/components/button_widget.dart';
+import 'package:photos/ui/components/dialog_widget.dart';
+import 'package:photos/ui/components/models/button_type.dart';
 import 'package:photos/utils/crypto_util.dart';
 import 'package:photos/utils/email_util.dart';
+import 'package:photos/utils/toast_util.dart';
 
 class DeleteAccountPage extends StatelessWidget {
   const DeleteAccountPage({
@@ -150,26 +153,49 @@ class DeleteAccountPage extends StatelessWidget {
     );
 
     if (hasAuthenticated) {
-      final choice = await showChoiceDialog(
-        context,
-        'Are you sure you want to delete your account?',
-        'Your uploaded data will be scheduled for deletion, and your account '
+      final choice = await showDialogWidget(
+        context: context,
+        title: 'Are you sure you want to delete your account?',
+        body:
+            'Your uploaded data will be scheduled for deletion, and your account'
             'will be permanently deleted. \n\nThis action is not reversible.',
-        firstAction: 'Cancel',
-        secondAction: 'Delete',
-        firstActionColor: Theme.of(context).colorScheme.onSurface,
-        secondActionColor: Colors.red,
+        buttons: [
+          ButtonWidget(
+            labelText: "Delete",
+            isInAlert: true,
+            buttonType: ButtonType.neutral,
+            buttonSize: ButtonSize.large,
+            buttonAction: ButtonAction.first,
+            onTap: () async {
+              final decryptChallenge = CryptoUtil.openSealSync(
+                Sodium.base642bin(response.encryptedChallenge),
+                Sodium.base642bin(
+                    Configuration.instance.getKeyAttributes().publicKey),
+                Configuration.instance.getSecretKey(),
+              );
+              final challengeResponseStr = utf8.decode(decryptChallenge);
+              await UserService.instance
+                  .deleteAccount(context, challengeResponseStr);
+            },
+          ),
+          const ButtonWidget(
+            labelText: "Cancel",
+            isInAlert: true,
+            buttonType: ButtonType.secondary,
+            buttonSize: ButtonSize.large,
+            buttonAction: ButtonAction.cancel,
+          ),
+        ],
       );
-      if (choice != DialogUserChoice.secondChoice) {
+      if (choice != ButtonAction.first) {
         return;
       }
-      final decryptChallenge = CryptoUtil.openSealSync(
-        Sodium.base642bin(response.encryptedChallenge),
-        Sodium.base642bin(Configuration.instance.getKeyAttributes().publicKey),
-        Configuration.instance.getSecretKey(),
+      showToast(
+        context,
+        "We have deleted your account and scheduled your uploaded data "
+        "for deletion.",
       );
-      final challengeResponseStr = utf8.decode(decryptChallenge);
-      await UserService.instance.deleteAccount(context, challengeResponseStr);
+      Navigator.of(context).popUntil((route) => route.isFirst);
     }
   }