diff --git a/lib/data/repositories/auth_repository.dart b/lib/data/repositories/auth_repository.dart index 233a7c902..d3f334bb5 100644 --- a/lib/data/repositories/auth_repository.dart +++ b/lib/data/repositories/auth_repository.dart @@ -161,6 +161,14 @@ class AuthRepository { password: password); } + Future resendConfirmation( + {@required Credentials credentials, @required String userId}) async { + return webClient.post( + '${credentials.url}/user/$userId/reconfirm', + credentials.token, + ); + } + Future sendRequest({ String url, dynamic data, diff --git a/lib/redux/app/app_actions.dart b/lib/redux/app/app_actions.dart index e9853b6ee..ff84fff8c 100644 --- a/lib/redux/app/app_actions.dart +++ b/lib/redux/app/app_actions.dart @@ -151,6 +151,15 @@ class LoadAccountSuccess implements StopLoading { final LoginResponse loginResponse; } +class ResendConfirmation implements StartLoading {} + +class ResendConfirmationFailure implements StopLoading { + ResendConfirmationFailure(this.error); + final dynamic error; +} + +class ResendConfirmationSuccess implements StopLoading {} + class RefreshData implements StartLoading { RefreshData({ this.completer, diff --git a/lib/redux/auth/auth_middleware.dart b/lib/redux/auth/auth_middleware.dart index 6e3ee07a0..9f9c556a0 100644 --- a/lib/redux/auth/auth_middleware.dart +++ b/lib/redux/auth/auth_middleware.dart @@ -28,6 +28,7 @@ List> createStoreAuthMiddleware([ final addCompany = _createCompany(repository); final deleteCompany = _deleteCompany(repository); final purgeData = _purgeData(repository); + final resendConfirmation = _resendConfirmation(repository); return [ TypedMiddleware(userLogout), @@ -40,6 +41,7 @@ List> createStoreAuthMiddleware([ TypedMiddleware(addCompany), TypedMiddleware(deleteCompany), TypedMiddleware(purgeData), + TypedMiddleware(resendConfirmation), ]; } @@ -371,6 +373,25 @@ Middleware _purgeData(AuthRepository repository) { }; } +Middleware _resendConfirmation(AuthRepository repository) { + return (Store store, dynamic dynamicAction, + NextDispatcher next) async { + final action = dynamicAction as ResendConfirmation; + final state = store.state; + + repository + .resendConfirmation( + credentials: state.credentials, userId: state.user.id) + .then((dynamic value) { + store.dispatch(ResendConfirmationSuccess()); + }).catchError((Object error) { + store.dispatch(ResendConfirmationFailure(error)); + }); + + next(action); + }; +} + String _parseError(String error) { const errorPattern = 'failed due to: Deserializing'; if (error.contains(errorPattern)) { diff --git a/lib/ui/app/confirm_email.dart b/lib/ui/app/confirm_email.dart index 2f602bab1..b1675a89e 100644 --- a/lib/ui/app/confirm_email.dart +++ b/lib/ui/app/confirm_email.dart @@ -1,7 +1,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:invoiceninja_flutter/constants.dart'; -import 'package:invoiceninja_flutter/ui/app/buttons/elevated_button.dart'; import 'package:invoiceninja_flutter/ui/app/confirm_email_vm.dart'; import 'package:invoiceninja_flutter/ui/app/loading_indicator.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; diff --git a/lib/ui/app/confirm_email_vm.dart b/lib/ui/app/confirm_email_vm.dart index c6ee3c4a0..d23886a00 100644 --- a/lib/ui/app/confirm_email_vm.dart +++ b/lib/ui/app/confirm_email_vm.dart @@ -40,7 +40,7 @@ class ConfirmEmailVM { store.dispatch(RefreshData()); }, onResendPressed: () { - // + store.dispatch(ResendConfirmation()); }, ); }