diff --git a/lib/redux/bank_account/bank_account_reducer.dart b/lib/redux/bank_account/bank_account_reducer.dart index 12d648bb7..94cbb5042 100644 --- a/lib/redux/bank_account/bank_account_reducer.dart +++ b/lib/redux/bank_account/bank_account_reducer.dart @@ -256,6 +256,5 @@ BankAccountState _setLoadedBankAccounts( BankAccountState _setLoadedCompany( BankAccountState bankAccountState, LoadCompanySuccess action) { final company = action.userCompany.company; - print('## setLoadedCompany: ${company.bankAccounts}'); return bankAccountState.loadBankAccounts(company.bankAccounts); } diff --git a/lib/ui/app/app_bottom_bar.dart b/lib/ui/app/app_bottom_bar.dart index 4a843a63b..206bcf20a 100644 --- a/lib/ui/app/app_bottom_bar.dart +++ b/lib/ui/app/app_bottom_bar.dart @@ -43,6 +43,7 @@ class AppBottomBar extends StatefulWidget { this.iconButtons = const [], this.onPaymentTypeChanged, this.paymentTypes = const [], + this.onRefreshPressed, }); final EntityType entityType; @@ -66,6 +67,7 @@ class AppBottomBar extends StatefulWidget { final List iconButtons; final List paymentTypes; final Function onPaymentTypeChanged; + final Function onRefreshPressed; @override _AppBottomBarState createState() => _AppBottomBarState(); @@ -545,7 +547,9 @@ class _AppBottomBarState extends State { ? localization.refreshData : '', child: InkWell( - onTap: () => store.dispatch(RefreshData()), + onTap: () => widget.onRefreshPressed != null + ? widget.onRefreshPressed() + : store.dispatch(RefreshData()), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 12), child: Icon(Icons.refresh), diff --git a/lib/ui/bank_account/bank_account_screen.dart b/lib/ui/bank_account/bank_account_screen.dart index 3b7213439..3a23cc3f7 100644 --- a/lib/ui/bank_account/bank_account_screen.dart +++ b/lib/ui/bank_account/bank_account_screen.dart @@ -117,6 +117,7 @@ class BankAccountScreen extends StatelessWidget { store.dispatch(FilterBankAccountsByCustom3(value)), onSelectedCustom4: (value) => store.dispatch(FilterBankAccountsByCustom4(value)), + onRefreshPressed: viewModel.onRefreshAccounts, ), floatingActionButton: state.prefState.isMenuFloated ? FloatingActionButton( diff --git a/lib/ui/bank_account/bank_account_screen_vm.dart b/lib/ui/bank_account/bank_account_screen_vm.dart index 4ca8622d4..2be08b02b 100644 --- a/lib/ui/bank_account/bank_account_screen_vm.dart +++ b/lib/ui/bank_account/bank_account_screen_vm.dart @@ -7,7 +7,10 @@ import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/bank_account/bank_account_actions.dart'; import 'package:invoiceninja_flutter/redux/bank_account/bank_account_selectors.dart'; import 'package:redux/redux.dart'; - +import 'package:invoiceninja_flutter/data/web_client.dart'; +import 'package:invoiceninja_flutter/main_app.dart'; +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; +import 'package:invoiceninja_flutter/utils/dialogs.dart'; import 'bank_account_screen.dart'; class BankAccountScreenBuilder extends StatelessWidget { @@ -33,6 +36,7 @@ class BankAccountScreenVM { @required this.userCompany, @required this.onEntityAction, @required this.bankAccountMap, + @required this.onRefreshAccounts, }); final bool isInMultiselect; @@ -40,6 +44,7 @@ class BankAccountScreenVM { final List bankAccountList; final Function(BuildContext, List, EntityAction) onEntityAction; final BuiltMap bankAccountMap; + final Function onRefreshAccounts; static BankAccountScreenVM fromStore(Store store) { final state = store.state; @@ -57,6 +62,22 @@ class BankAccountScreenVM { onEntityAction: (BuildContext context, List bankAccounts, EntityAction action) => handleBankAccountAction(context, bankAccounts, action), + onRefreshAccounts: () { + final webClient = WebClient(); + final credentials = state.credentials; + final url = '${credentials.url}/bank_integrations/refresh_accounts'; + + store.dispatch(StartSaving()); + + webClient.post(url, credentials.token).then((dynamic response) { + store.dispatch(StopSaving()); + store.dispatch(RefreshData()); + }).catchError((dynamic error) { + store.dispatch(StopSaving()); + showErrorDialog( + context: navigatorKey.currentContext, message: '$error'); + }); + }, ); } }