diff --git a/lib/data/repositories/auth_repository.dart b/lib/data/repositories/auth_repository.dart index 20a80f599..07ea52d58 100644 --- a/lib/data/repositories/auth_repository.dart +++ b/lib/data/repositories/auth_repository.dart @@ -101,6 +101,15 @@ class AuthRepository { return webClient.delete('/companies/$companyId', token, password: password); } + + Future purgeData({ + @required String token, + @required String companyId, + @required String password, + }) async { + //return webClient.delete('/companies/$companyId', token, password: password); + } + Future sendRequest( {String url, dynamic data, String token, String secret}) async { url += '?first_load=true&include_static=true'; diff --git a/lib/redux/auth/auth_middleware.dart b/lib/redux/auth/auth_middleware.dart index 2c707df08..53281938c 100644 --- a/lib/redux/auth/auth_middleware.dart +++ b/lib/redux/auth/auth_middleware.dart @@ -30,6 +30,7 @@ List> createStoreAuthMiddleware([ final recoverRequest = _createRecoverRequest(repository); final addCompany = _createCompany(repository); final deleteCompany = _deleteCompany(repository); + final purgeData = _purgeData(repository); return [ TypedMiddleware(userLogout), @@ -40,6 +41,7 @@ List> createStoreAuthMiddleware([ TypedMiddleware(recoverRequest), TypedMiddleware(addCompany), TypedMiddleware(deleteCompany), + TypedMiddleware(purgeData), ]; } @@ -278,3 +280,25 @@ Middleware _deleteCompany(AuthRepository repository) { next(action); }; } + +Middleware _purgeData(AuthRepository repository) { + return (Store store, dynamic dynamicAction, + NextDispatcher next) async { + final action = dynamicAction as DeleteCompanyRequest; + final state = store.state; + + repository + .purgeData( + token: state.credentials.token, + password: action.password, + companyId: state.company.id) + .then((dynamic value) { + action.completer.complete(null); + store.dispatch(PurgeDataSuccess()); + }).catchError((Object error) { + store.dispatch(PurgeDataFailure(error)); + }); + + next(action); + }; +} diff --git a/lib/ui/settings/account_management.dart b/lib/ui/settings/account_management.dart index 6da23a3c3..f6ae17154 100644 --- a/lib/ui/settings/account_management.dart +++ b/lib/ui/settings/account_management.dart @@ -77,33 +77,34 @@ class _AccountManagementState extends State SizedBox(height: 14), //if (isSelfHosted(context)) if (false) - Padding( - padding: const EdgeInsets.all(14), - child: Row( - children: [ - Expanded( - child: ElevatedButton( - label: localization.purchaseLicense, - iconData: Icons.cloud_download, - onPressed: () {}, + Padding( + padding: const EdgeInsets.all(14), + child: Row( + children: [ + Expanded( + child: ElevatedButton( + label: localization.purchaseLicense, + iconData: Icons.cloud_download, + onPressed: () {}, + ), ), - ), - SizedBox(width: 14), - Expanded( - child: ElevatedButton( - label: localization.applyLicense, - iconData: Icons.cloud_done, - onPressed: () {}, + SizedBox(width: 14), + Expanded( + child: ElevatedButton( + label: localization.applyLicense, + iconData: Icons.cloud_done, + onPressed: () {}, + ), ), - ), - ], + ], + ), ), - ), + /* Padding( padding: const EdgeInsets.all(16), child: ElevatedButton( label: localization.purgeData.toUpperCase(), - color: Colors.orange, + color: Colors.red, iconData: Icons.delete, onPressed: () { confirmCallback( @@ -118,7 +119,8 @@ class _AccountManagementState extends State }); }, ), - ), + ), + */ Padding( padding: const EdgeInsets.all(16), child: ElevatedButton(