Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

add account deletion UI

AmanRajSinghMourya56c3200b2281
diff --git a/mobile/packages/account_deletion/lib/src/ui/delete_account_bottom_actions.dart b/mobile/packages/account_deletion/lib/src/ui/delete_account_bottom_actions.dart
new file mode 100644
index 0000000000..3b3efba08f
--- /dev/null
+++ b/mobile/packages/account_deletion/lib/src/ui/delete_account_bottom_actions.dart
@@ -0,0 +1,81 @@
+import 'package:ente_components/ente_components.dart';
+import 'package:ente_strings/ente_strings.dart';
+import 'package:flutter/material.dart';
+
+class DeleteAccountBottomActions extends StatelessWidget {
+ const DeleteAccountBottomActions({
+ super.key,
+ required this.isConfirmationStep,
+ required this.isActionEnabled,
+ required this.onContinue,
+ required this.onDelete,
+ });
+
+ final bool isConfirmationStep;
+ final bool isActionEnabled;
+ final VoidCallback onContinue;
+ final Future<void> Function() onDelete;
+
+ @override
+ Widget build(BuildContext context) {
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ _StepperIndicator(isConfirmationStep: isConfirmationStep),
+ const SizedBox(height: Spacing.lg),
+ ButtonComponent(
+ label: isConfirmationStep
+ ? context.strings.deleteEnteAccount
+ : context.strings.continueLabel,
+ variant: isConfirmationStep
+ ? ButtonComponentVariant.critical
+ : ButtonComponentVariant.primary,
+ isDisabled: !isActionEnabled,
+ shouldSurfaceExecutionStates: true,
+ shouldShowSuccessState: false,
+ onTap: isConfirmationStep ? onDelete : onContinue,
+ ),
+ ],
+ );
+ }
+}
+
+class _StepperIndicator extends StatelessWidget {
+ const _StepperIndicator({required this.isConfirmationStep});
+
+ final bool isConfirmationStep;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+
+ return Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ _StepDot(isActive: !isConfirmationStep, colors: colors),
+ const SizedBox(width: Spacing.md),
+ _StepDot(isActive: isConfirmationStep, colors: colors),
+ ],
+ );
+ }
+}
+
+class _StepDot extends StatelessWidget {
+ const _StepDot({required this.isActive, required this.colors});
+
+ final bool isActive;
+ final ColorTokens colors;
+
+ @override
+ Widget build(BuildContext context) {
+ return AnimatedContainer(
+ duration: Motion.quick,
+ width: isActive ? 20 : 10,
+ height: 10,
+ decoration: BoxDecoration(
+ color: isActive ? colors.warning : colors.fillDark,
+ borderRadius: BorderRadius.circular(14),
+ ),
+ );
+ }
+}
diff --git a/mobile/packages/account_deletion/lib/src/ui/delete_account_confirmation_step.dart b/mobile/packages/account_deletion/lib/src/ui/delete_account_confirmation_step.dart
new file mode 100644
index 0000000000..b428eca181
--- /dev/null
+++ b/mobile/packages/account_deletion/lib/src/ui/delete_account_confirmation_step.dart
@@ -0,0 +1,145 @@
+import 'package:ente_account_deletion/src/models/account_deletion_summary.dart';
+import 'package:ente_components/ente_components.dart';
+import 'package:ente_strings/ente_strings.dart';
+import 'package:flutter/material.dart';
+import 'package:hugeicons/hugeicons.dart';
+
+class DeleteAccountConfirmationStep extends StatelessWidget {
+ const DeleteAccountConfirmationStep({
+ super.key,
+ required this.summary,
+ required this.isLoading,
+ required this.confirmed,
+ required this.onConfirmationChanged,
+ required this.onRetrySummary,
+ });
+
+ final AccountDeletionSummary? summary;
+ final bool isLoading;
+ final bool confirmed;
+ final ValueChanged<bool> onConfirmationChanged;
+ final VoidCallback onRetrySummary;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ context.strings.permanentlyDeleteYourEnteAccount,
+ style: TextStyles.display3.copyWith(color: colors.textBase),
+ ),
+ const SizedBox(height: Spacing.sm),
+ Text(
+ context.strings.oneAccountAcrossEnteApps,
+ style: TextStyles.body.copyWith(color: colors.textLight),
+ ),
+ const SizedBox(height: Spacing.lg),
+ _buildSummary(context),
+ const SizedBox(height: Spacing.lg),
+ InkWell(
+ onTap: () => onConfirmationChanged(!confirmed),
+ borderRadius: BorderRadius.circular(Radii.sm),
+ child: LabeledControlComponent(
+ control: CheckboxComponent(
+ selected: confirmed,
+ onChanged: onConfirmationChanged,
+ selectedColor: colors.warning,
+ ),
+ label: context.strings.confirmDeleteAccountAcrossApps,
+ ),
+ ),
+ ],
+ );
+ }
+
+ Widget _buildSummary(BuildContext context) {
+ final colors = context.componentColors;
+ final summary = this.summary;
+
+ if (isLoading) {
+ return const SizedBox(
+ height: 196,
+ child: Center(child: CircularProgressIndicator()),
+ );
+ }
+ if (summary == null) {
+ return MenuComponent(
+ title: context.strings.somethingWentWrong,
+ subtitle: context.strings.tryAgain,
+ titleColor: colors.warning,
+ leading: HugeIcon(
+ icon: HugeIcons.strokeRoundedAlertCircle,
+ color: colors.warning,
+ size: IconSizes.small,
+ ),
+ trailing: HugeIcon(
+ icon: HugeIcons.strokeRoundedRefresh,
+ color: colors.textLight,
+ size: IconSizes.small,
+ ),
+ onTap: onRetrySummary,
+ );
+ }
+ return _SummaryRows(summary: summary);
+ }
+}
+
+class _SummaryRows extends StatelessWidget {
+ const _SummaryRows({required this.summary});
+
+ final AccountDeletionSummary summary;
+
+ @override
+ Widget build(BuildContext context) {
+ return Column(
+ children: [
+ _row(
+ assetName: 'photos.png',
+ title: context.strings.photosAndVideosCount(
+ summary.photosAndVideosCount,
+ ),
+ subtitle: context.strings.entePhotos,
+ ),
+ const SizedBox(height: Spacing.sm),
+ _row(
+ assetName: 'auth.png',
+ title: context.strings.authenticatorCodesCount(
+ summary.authenticatorCodesCount,
+ ),
+ subtitle: context.strings.enteAuth,
+ ),
+ const SizedBox(height: Spacing.sm),
+ _row(
+ assetName: 'locker.png',
+ title: context.strings.lockerRecordsCount(summary.lockerRecordsCount),
+ subtitle: context.strings.enteLocker,
+ ),
+ ],
+ );
+ }
+
+ Widget _row({
+ required String assetName,
+ required String title,
+ required String subtitle,
+ }) {
+ return MenuComponent(
+ title: title,
+ subtitle: subtitle,
+ titleMaxLines: 1,
+ subtitleMaxLines: 1,
+ leading: SizedBox(
+ width: 24,
+ height: 24,
+ child: Image.asset(
+ 'assets/$assetName',
+ package: 'ente_account_deletion',
+ fit: BoxFit.contain,
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/packages/account_deletion/lib/src/ui/delete_account_page.dart b/mobile/packages/account_deletion/lib/src/ui/delete_account_page.dart
new file mode 100644
index 0000000000..c79dc783b7
--- /dev/null
+++ b/mobile/packages/account_deletion/lib/src/ui/delete_account_page.dart
@@ -0,0 +1,176 @@
+import 'dart:async';
+
+import 'package:ente_account_deletion/src/account_deletion_settings.dart';
+import 'package:ente_account_deletion/src/models/account_deletion_summary.dart';
+import 'package:ente_account_deletion/src/ui/delete_account_bottom_actions.dart';
+import 'package:ente_account_deletion/src/ui/delete_account_confirmation_step.dart';
+import 'package:ente_account_deletion/src/ui/delete_account_reason_step.dart';
+import 'package:ente_components/ente_components.dart';
+import 'package:ente_strings/ente_strings.dart';
+import 'package:ente_ui/utils/toast_util.dart';
+import 'package:flutter/material.dart';
+import 'package:logging/logging.dart';
+
+class DeleteAccountPage extends StatefulWidget {
+ const DeleteAccountPage({super.key});
+
+ @override
+ State<DeleteAccountPage> createState() => _DeleteAccountPageState();
+}
+
+class _DeleteAccountPageState extends State<DeleteAccountPage> {
+ final _logger = Logger('DeleteAccountPage');
+ final _feedbackController = TextEditingController();
+ DeleteAccountReason? _selectedReason;
+ _DeleteAccountStep _step = _DeleteAccountStep.reason;
+ bool _confirmationAccepted = false;
+ bool _isDeleting = false;
+ AccountDeletionSummary? _summary;
+ bool _summaryLoading = false;
+
+ AccountDeletionSettings get _settings => AccountDeletionSettings.instance;
+
+ @override
+ void dispose() {
+ _feedbackController.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+ final isConfirmationStep = _step == _DeleteAccountStep.confirmation;
+ final isActionEnabled = isConfirmationStep
+ ? _summary != null && _confirmationAccepted && !_isDeleting
+ : _selectedReason != null && !_isDeleting;
+
+ return Scaffold(
+ backgroundColor: colors.backgroundBase,
+ bottomNavigationBar: SafeArea(
+ minimum: const EdgeInsets.fromLTRB(
+ Spacing.lg,
+ 0,
+ Spacing.lg,
+ Spacing.xl,
+ ),
+ child: DeleteAccountBottomActions(
+ isConfirmationStep: isConfirmationStep,
+ isActionEnabled: isActionEnabled,
+ onContinue: _goToConfirmation,
+ onDelete: _deleteAccount,
+ ),
+ ),
+ body: AppBarComponent(
+ title: context.strings.deleteAccount,
+ onBack: _handleBack,
+ slivers: [
+ SliverSafeArea(
+ top: false,
+ sliver: SliverPadding(
+ padding: const EdgeInsets.symmetric(horizontal: Spacing.lg),
+ sliver: SliverToBoxAdapter(
+ child: isConfirmationStep
+ ? DeleteAccountConfirmationStep(
+ summary: _summary,
+ isLoading: _summaryLoading,
+ confirmed: _confirmationAccepted,
+ onConfirmationChanged: (value) {
+ setState(() => _confirmationAccepted = value);
+ },
+ onRetrySummary: () => unawaited(_loadSummary()),
+ )
+ : DeleteAccountReasonStep(
+ selectedReason: _selectedReason,
+ feedbackController: _feedbackController,
+ onReasonChanged: (reason) {
+ setState(() => _selectedReason = reason);
+ },
+ ),
+ ),
+ ),
+ ),
+ const SliverToBoxAdapter(child: SizedBox(height: Spacing.xl)),
+ ],
+ ),
+ );
+ }
+
+ void _goToConfirmation() {
+ setState(() => _step = _DeleteAccountStep.confirmation);
+ if (_summary == null && !_summaryLoading) {
+ unawaited(_loadSummary());
+ }
+ }
+
+ void _handleBack() {
+ if (_isDeleting) {
+ return;
+ }
+ Navigator.of(context).pop();
+ }
+
+ Future<void> _loadSummary() async {
+ setState(() {
+ _summaryLoading = true;
+ });
+ try {
+ final summary = await _settings.service.getDeletionSummary();
+ if (!mounted) {
+ return;
+ }
+ setState(() {
+ _summary = summary;
+ _summaryLoading = false;
+ });
+ } catch (e, s) {
+ _logger.warning('Failed to load account deletion summary', e, s);
+ if (!mounted) {
+ return;
+ }
+ setState(() {
+ _summary = null;
+ _summaryLoading = false;
+ });
+ }
+ }
+
+ Future<void> _deleteAccount() async {
+ final reason = _selectedReason!;
+ try {
+ setState(() => _isDeleting = true);
+ final encryptedChallenge = await _settings.service.getDeleteChallenge();
+ final challenge = _settings.host.decryptDeleteChallenge(
+ encryptedChallenge,
+ );
+ await _settings.service.deleteAccount(
+ challenge: challenge,
+ reasonCategory: reason.apiValue,
+ feedback: _optionalFeedback,
+ );
+ await _settings.host.logout();
+ if (!mounted) {
+ return;
+ }
+ showToast(context, 'Your account is queued for deletion');
+ Navigator.of(context).popUntil((route) => route.isFirst);
+ } catch (e, s) {
+ _logger.severe('Failed to delete account', e, s);
+ if (!mounted) {
+ return;
+ }
+ setState(() => _isDeleting = false);
+ await showErrorBottomSheetComponent<void>(
+ context: context,
+ title: context.strings.error,
+ message: context.strings.somethingWentWrong,
+ );
+ }
+ }
+
+ String? get _optionalFeedback {
+ final feedback = _feedbackController.text.trim();
+ return feedback.isEmpty ? null : feedback;
+ }
+}
+
+enum _DeleteAccountStep { reason, confirmation }
diff --git a/mobile/packages/account_deletion/lib/src/ui/delete_account_reason_step.dart b/mobile/packages/account_deletion/lib/src/ui/delete_account_reason_step.dart
new file mode 100644
index 0000000000..5dd997eb9c
--- /dev/null
+++ b/mobile/packages/account_deletion/lib/src/ui/delete_account_reason_step.dart
@@ -0,0 +1,168 @@
+import 'package:ente_components/ente_components.dart';
+import 'package:ente_strings/ente_strings.dart';
+import 'package:flutter/material.dart';
+import 'package:hugeicons/hugeicons.dart';
+
+enum DeleteAccountReason {
+ missingFeature,
+ unexpectedBehaviour,
+ foundAnotherService,
+ notListed,
+}
+
+extension DeleteAccountReasonExtension on DeleteAccountReason {
+ String get apiValue {
+ return switch (this) {
+ DeleteAccountReason.missingFeature => 'missing_feature',
+ DeleteAccountReason.unexpectedBehaviour => 'unexpected_behaviour',
+ DeleteAccountReason.foundAnotherService => 'found_another_service',
+ DeleteAccountReason.notListed => 'not_listed',
+ };
+ }
+
+ String label(BuildContext context) {
+ return switch (this) {
+ DeleteAccountReason.missingFeature =>
+ context.strings.deleteReasonMissingFeature,
+ DeleteAccountReason.unexpectedBehaviour =>
+ context.strings.deleteReasonBehaviour,
+ DeleteAccountReason.foundAnotherService =>
+ context.strings.deleteReasonFoundAnotherService,
+ DeleteAccountReason.notListed => context.strings.deleteReasonNotListed,
+ };
+ }
+}
+
+class DeleteAccountReasonStep extends StatelessWidget {
+ const DeleteAccountReasonStep({
+ super.key,
+ required this.selectedReason,
+ required this.feedbackController,
+ required this.onReasonChanged,
+ });
+
+ final DeleteAccountReason? selectedReason;
+ final TextEditingController feedbackController;
+ final ValueChanged<DeleteAccountReason> onReasonChanged;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ context.strings.whyAreYouLeaving,
+ style: TextStyles.display3.copyWith(color: colors.textBase),
+ ),
+ const SizedBox(height: Spacing.sm),
+ Text(
+ context.strings.thisHelpsUsImproveEnte,
+ style: TextStyles.body.copyWith(color: colors.textLight),
+ ),
+ const SizedBox(height: Spacing.lg),
+ _ReasonPicker(
+ selectedReason: selectedReason,
+ onReasonChanged: onReasonChanged,
+ ),
+ const SizedBox(height: Spacing.lg),
+ TextInputComponent(
+ controller: feedbackController,
+ label: context.strings.anythingElse,
+ hintText: context.strings.shareYourFeedbackHere,
+ minLines: 5,
+ maxLines: 5,
+ keyboardType: TextInputType.multiline,
+ autocorrect: true,
+ ),
+ ],
+ );
+ }
+}
+
+class _ReasonPicker extends StatelessWidget {
+ const _ReasonPicker({
+ required this.selectedReason,
+ required this.onReasonChanged,
+ });
+
+ final DeleteAccountReason? selectedReason;
+ final ValueChanged<DeleteAccountReason> onReasonChanged;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+
+ return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ context.strings.reasonForLeaving,
+ style: TextStyles.bodyBold.copyWith(color: colors.textBase),
+ ),
+ const SizedBox(width: 2),
+ Text(
+ '*',
+ style: TextStyles.bodyBold.copyWith(color: colors.warning),
+ ),
+ ],
+ ),
+ const SizedBox(height: Spacing.sm),
+ LayoutBuilder(
+ builder: (context, constraints) {
+ return EntePopupMenuButton<DeleteAccountReason>(
+ menuWidth: constraints.maxWidth,
+ optionsBuilder: () => DeleteAccountReason.values.map((reason) {
+ return EntePopupMenuOption<DeleteAccountReason>(
+ value: reason,
+ label: reason.label(context),
+ isActive: reason == selectedReason,
+ activeTrailingWidget: HugeIcon(
+ icon: HugeIcons.strokeRoundedTick02,
+ color: colors.primary,
+ size: IconSizes.medium,
+ ),
+ );
+ }).toList(),
+ onSelected: onReasonChanged,
+ child: Padding(
+ padding: const EdgeInsets.only(bottom: Spacing.sm),
+ child: Container(
+ width: constraints.maxWidth,
+ height: 52,
+ padding: const EdgeInsets.symmetric(horizontal: Spacing.lg),
+ decoration: BoxDecoration(
+ color: colors.fillLight,
+ borderRadius: BorderRadius.circular(Radii.button),
+ ),
+ child: Row(
+ children: [
+ Expanded(
+ child: Text(
+ selectedReason?.label(context) ??
+ context.strings.selectReason,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: TextStyles.body.copyWith(
+ color: selectedReason == null
+ ? colors.textLighter
+ : colors.textBase,
+ ),
+ ),
+ ),
+ Icon(Icons.keyboard_arrow_down, color: colors.textLight),
+ ],
+ ),
+ ),
+ ),
+ );
+ },
+ ),
+ ],
+ );
+ }
+}