Purge data

This commit is contained in:
Hillel Coren 2020-03-16 11:25:38 +02:00
parent dd0664fbf7
commit efdd8c2d1d
3 changed files with 56 additions and 21 deletions

View File

@ -101,6 +101,15 @@ class AuthRepository {
return webClient.delete('/companies/$companyId', token, password: password); return webClient.delete('/companies/$companyId', token, password: password);
} }
Future<dynamic> purgeData({
@required String token,
@required String companyId,
@required String password,
}) async {
//return webClient.delete('/companies/$companyId', token, password: password);
}
Future<LoginResponse> sendRequest( Future<LoginResponse> sendRequest(
{String url, dynamic data, String token, String secret}) async { {String url, dynamic data, String token, String secret}) async {
url += '?first_load=true&include_static=true'; url += '?first_load=true&include_static=true';

View File

@ -30,6 +30,7 @@ List<Middleware<AppState>> createStoreAuthMiddleware([
final recoverRequest = _createRecoverRequest(repository); final recoverRequest = _createRecoverRequest(repository);
final addCompany = _createCompany(repository); final addCompany = _createCompany(repository);
final deleteCompany = _deleteCompany(repository); final deleteCompany = _deleteCompany(repository);
final purgeData = _purgeData(repository);
return [ return [
TypedMiddleware<AppState, UserLogout>(userLogout), TypedMiddleware<AppState, UserLogout>(userLogout),
@ -40,6 +41,7 @@ List<Middleware<AppState>> createStoreAuthMiddleware([
TypedMiddleware<AppState, RecoverPasswordRequest>(recoverRequest), TypedMiddleware<AppState, RecoverPasswordRequest>(recoverRequest),
TypedMiddleware<AppState, AddCompany>(addCompany), TypedMiddleware<AppState, AddCompany>(addCompany),
TypedMiddleware<AppState, DeleteCompanyRequest>(deleteCompany), TypedMiddleware<AppState, DeleteCompanyRequest>(deleteCompany),
TypedMiddleware<AppState, PurgeDataRequest>(purgeData),
]; ];
} }
@ -278,3 +280,25 @@ Middleware<AppState> _deleteCompany(AuthRepository repository) {
next(action); next(action);
}; };
} }
Middleware<AppState> _purgeData(AuthRepository repository) {
return (Store<AppState> 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);
};
}

View File

@ -99,11 +99,12 @@ class _AccountManagementState extends State<AccountManagement>
], ],
), ),
), ),
/*
Padding( Padding(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: ElevatedButton( child: ElevatedButton(
label: localization.purgeData.toUpperCase(), label: localization.purgeData.toUpperCase(),
color: Colors.orange, color: Colors.red,
iconData: Icons.delete, iconData: Icons.delete,
onPressed: () { onPressed: () {
confirmCallback( confirmCallback(
@ -119,6 +120,7 @@ class _AccountManagementState extends State<AccountManagement>
}, },
), ),
), ),
*/
Padding( Padding(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: ElevatedButton( child: ElevatedButton(