diff --git a/lib/ui/account/delete_account_page.dart b/lib/ui/account/delete_account_page.dart index 39b5283bc..c84a4add4 100644 --- a/lib/ui/account/delete_account_page.dart +++ b/lib/ui/account/delete_account_page.dart @@ -27,14 +27,15 @@ class _DeleteAccountPageState extends State { bool _hasConfirmedDeletion = false; final _feedbackTextCtrl = TextEditingController(); final String _defaultSelection = 'Select reason'; - late String dropdownValue = _defaultSelection; - late List deletionReason = [ + late String _dropdownValue = _defaultSelection; + late final List _deletionReason = [ _defaultSelection, 'It’s missing a key feature that I need', 'I found another service that I like better', 'I use a different account', 'My reason isn’t listed', ]; + final List _reasonIndexesWhereFeedbackIsNecessary = [1, 4]; @override Widget build(BuildContext context) { @@ -72,14 +73,14 @@ class _DeleteAccountPageState extends State { ), child: DropdownButton2( alignment: AlignmentDirectional.topStart, - value: dropdownValue, + value: _dropdownValue, onChanged: (String? newValue) { setState(() { - dropdownValue = newValue!; + _dropdownValue = newValue!; }); }, underline: const SizedBox(), - items: deletionReason + items: _deletionReason .map>((String value) { return DropdownMenuItem( value: value, @@ -129,7 +130,20 @@ class _DeleteAccountPageState extends State { setState(() {}); }, ), - const SizedBox(height: 24), + _shouldAskForFeedback() + ? SizedBox( + height: 42, + child: Padding( + padding: const EdgeInsets.only(top: 4.0), + child: Text( + "Kindly help us with this information", + style: getEnteTextTheme(context) + .smallBold + .copyWith(color: colorScheme.warning700), + ), + ), + ) + : const SizedBox(height: 42), GestureDetector( onTap: () { setState(() { @@ -165,9 +179,10 @@ class _DeleteAccountPageState extends State { ButtonWidget( buttonType: ButtonType.critical, labelText: "Confirm Account Deletion", - isDisabled: !_hasConfirmedDeletion || - _defaultSelection == dropdownValue, - onTap: () async => {await _initiateDelete(context)}, + isDisabled: _shouldBlockDeletion(), + onTap: () async { + await _initiateDelete(context); + }, shouldSurfaceExecutionStates: true, ), const SizedBox(height: 8), @@ -193,6 +208,18 @@ class _DeleteAccountPageState extends State { ); } + bool _shouldBlockDeletion() { + return !_hasConfirmedDeletion || + _dropdownValue == _defaultSelection || + _shouldAskForFeedback(); + } + + bool _shouldAskForFeedback() { + return (_reasonIndexesWhereFeedbackIsNecessary + .contains(_deletionReason.indexOf(_dropdownValue)) && + _feedbackTextCtrl.text.trim().isEmpty); + } + Future _initiateDelete(BuildContext context) async { final deleteChallengeResponse = await UserService.instance.getDeleteChallenge(context); @@ -222,7 +249,7 @@ class _DeleteAccountPageState extends State { await UserService.instance.deleteAccount( context, challengeResponseStr, - reasonCategory: dropdownValue, + reasonCategory: _dropdownValue, feedback: _feedbackTextCtrl.text.trim(), ); Navigator.of(context).popUntil((route) => route.isFirst);