Skip to content

Commit

Permalink
release(app): v3.5.0+30500 (#1021)
Browse files Browse the repository at this point in the history
* feat: add extra dialog for delete account

* chore: update app generated files

* release(app): v3.5.0+30500
  • Loading branch information
Nirajn2311 authored Jun 21, 2023
1 parent 9a3a51f commit 8c66c8f
Show file tree
Hide file tree
Showing 6 changed files with 294 additions and 71 deletions.
133 changes: 133 additions & 0 deletions mobile-app/lib/app/app.router.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mobile-app/lib/enums/dialog_type.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
enum DialogType {
basic,
buttonForm,
deleteAccount
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,6 @@ class DeleteAccountView extends StatelessWidget {
const SizedBox(
height: 12,
),
// Row(
// children: [
// Expanded(
// child: TextButton(
// onPressed: () => Navigator.pop(context),
// style: TextButton.styleFrom(
// backgroundColor: const Color(0xFF0a0a23),
// side: const BorderSide(
// width: 2,
// color: Colors.white,
// ),
// ),
// child: const Text(
// "Nevermind, I don't want to delete my account",
// textAlign: TextAlign.center,
// style: paragraphTextStyle,
// ),
// ),
// ),
// ],
// ),
// const SizedBox(
// height: 12,
// ),
Row(
children: [
Expanded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:developer';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:freecodecamp/app/app.locator.dart';
import 'package:freecodecamp/enums/dialog_type.dart';
import 'package:freecodecamp/service/authentication/authentication_service.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
Expand All @@ -11,70 +12,82 @@ class DeleteAccountViewModel extends BaseViewModel {
final _authenticationService = locator<AuthenticationService>();
final _navigator = locator<NavigationService>();
final _snackbar = locator<SnackbarService>();
final _dialogService = locator<DialogService>();

final Dio _dio = Dio();
bool processing = false;

void deleteAccount(BuildContext context) async {
processing = true;
showDialog(
context: context,
barrierDismissible: false,
routeSettings: const RouteSettings(
name: 'Delete account processing',
),
builder: (context) {
return WillPopScope(
onWillPop: () async => false,
child: const SimpleDialog(
title: Text('Deleting account...'),
contentPadding: EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 24.0),
backgroundColor: Color(0xFF2A2A40),
children: [
Center(
child: CircularProgressIndicator(),
),
],
),
);
},
DialogResponse? res = await _dialogService.showCustomDialog(
barrierDismissible: true,
variant: DialogType.deleteAccount,
title: 'Delete account',
description:
'Are you sure you want to delete your account? - this deletes everything related to your account',
mainButtonTitle: 'Delete account',
);
notifyListeners();

try {
Response res = await _dio.post(
'${AuthenticationService.baseApiURL}/account/delete',
options: Options(
headers: {
'CSRF-Token': _authenticationService.csrfToken,
'Cookie':
'jwt_access_token=${_authenticationService.jwtAccessToken}; _csrf=${_authenticationService.csrf};',
},
if (res?.confirmed == true) {
showDialog(
context: context,
barrierDismissible: false,
routeSettings: const RouteSettings(
name: 'Delete account processing',
),
builder: (context) {
return WillPopScope(
onWillPop: () async => false,
child: const SimpleDialog(
title: Text('Deleting account...'),
contentPadding: EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 24.0),
backgroundColor: Color(0xFF2A2A40),
children: [
Center(
child: CircularProgressIndicator(),
),
],
),
);
},
);
notifyListeners();

if (res.statusCode == 200) {
log('Account deleted');
await _authenticationService.logout();
_navigator.clearStackAndShow('/');
_snackbar.showSnackbar(
title: 'Your account has been successfully deleted',
message: '',
try {
Response res = await _dio.post(
'${AuthenticationService.baseApiURL}/account/delete',
options: Options(
headers: {
'CSRF-Token': _authenticationService.csrfToken,
'Cookie':
'jwt_access_token=${_authenticationService.jwtAccessToken}; _csrf=${_authenticationService.csrf};',
},
),
);
} else {
log('Account deletion failed');

if (res.statusCode == 200) {
log('Account deleted');
await _authenticationService.logout();
_navigator.clearStackAndShow('/');
_snackbar.showSnackbar(
title: 'Your account has been successfully deleted',
message: '',
);
} else {
log('Account deletion failed');
_navigator.back();
_snackbar.showSnackbar(
title: 'Account deletion failed. Please try again later.',
message: '',
);
}
} catch (err) {
_navigator.back();
_snackbar.showSnackbar(
title: 'Account deletion failed. Please try again later.',
message: '',
);
}
} catch (err) {
_navigator.back();
_snackbar.showSnackbar(
title: 'Account deletion failed. Please try again later.',
message: '',
);
}

processing = false;
Expand Down
Loading

0 comments on commit 8c66c8f

Please sign in to comment.