From a6d0e78f166292bd9892f96f9902daf7fc28c0d6 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 11 Oct 2019 09:50:04 +0300 Subject: [PATCH] Settings --- lib/redux/app/app_actions.dart | 2 + lib/redux/app/app_middleware.dart | 18 ++++++--- lib/redux/client/client_middleware.dart | 16 +++++--- lib/redux/client/client_reducer.dart | 4 ++ lib/redux/dashboard/dashboard_middleware.dart | 4 +- lib/redux/expense/expense_middleware.dart | 12 +++--- lib/redux/expense/expense_reducer.dart | 2 + lib/redux/group/group_middleware.dart | 12 +++--- lib/redux/group/group_reducer.dart | 2 + lib/redux/invoice/invoice_middleware.dart | 12 +++--- lib/redux/invoice/invoice_reducer.dart | 2 + lib/redux/payment/payment_middleware.dart | 12 +++--- lib/redux/payment/payment_reducer.dart | 4 +- lib/redux/product/product_middleware.dart | 12 +++--- lib/redux/product/product_reducer.dart | 2 + lib/redux/project/project_middleware.dart | 12 +++--- lib/redux/project/project_reducer.dart | 2 + lib/redux/quote/quote_middleware.dart | 12 +++--- lib/redux/quote/quote_reducer.dart | 2 + lib/redux/settings/settings_middleware.dart | 4 +- lib/redux/task/task_middleware.dart | 12 +++--- lib/redux/task/task_reducer.dart | 2 + lib/redux/vendor/vendor_middleware.dart | 12 +++--- lib/redux/vendor/vendor_reducer.dart | 2 + lib/ui/app/dialogs/alert_dialog.dart | 39 ++++++++++++------- lib/ui/app/forms/app_form.dart | 1 - lib/utils/i18n.dart | 5 ++- stubs/redux/stub/stub_middleware | 16 ++++---- stubs/redux/stub/stub_reducer | 2 + 29 files changed, 145 insertions(+), 94 deletions(-) diff --git a/lib/redux/app/app_actions.dart b/lib/redux/app/app_actions.dart index 9442bb7c4..39e11239b 100644 --- a/lib/redux/app/app_actions.dart +++ b/lib/redux/app/app_actions.dart @@ -84,6 +84,8 @@ class RefreshData { class ClearLastError {} +class DiscardChanges {} + class FilterCompany { FilterCompany(this.filter); diff --git a/lib/redux/app/app_middleware.dart b/lib/redux/app/app_middleware.dart index ccda9cafb..46d034fa5 100644 --- a/lib/redux/app/app_middleware.dart +++ b/lib/redux/app/app_middleware.dart @@ -448,20 +448,26 @@ void _setLastLoadWasSuccesfull() async { } */ -bool hasChanges({Store store, BuildContext context, bool force}) { +bool hasChanges({ + @required Store store, + @required BuildContext context, + @required dynamic action, +}) { + final localization = AppLocalization.of(context); + if (context == null) { print('WARNING: context is null in hasChanges'); return false; - } else if (force == null) { - print('WARNING: force is null in hasChanges'); - return false; } - if (store.state.hasChanges() && !isMobile(context) && !force) { + if (store.state.hasChanges() && !isMobile(context)) { showDialog( context: context, builder: (BuildContext context) { - return MessageDialog(AppLocalization.of(context).errorUnsavedChanges); + return MessageDialog(localization.errorUnsavedChanges, onDiscard: () { + store.dispatch(DiscardChanges()); + store.dispatch(action); + }); }); return true; } else { diff --git a/lib/redux/client/client_middleware.dart b/lib/redux/client/client_middleware.dart index a6aaf5183..d22dc5eb0 100644 --- a/lib/redux/client/client_middleware.dart +++ b/lib/redux/client/client_middleware.dart @@ -43,8 +43,8 @@ Middleware _editClient() { NextDispatcher next) async { final action = dynamicAction as EditClient; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && + hasChanges(store: store, context: action.context, action: action)) { return; } @@ -63,8 +63,10 @@ Middleware _viewClient() { NextDispatcher next) async { final action = dynamicAction as ViewClient; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, + context: action.context, + action: action)) { return; } @@ -82,8 +84,10 @@ Middleware _viewClientList() { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as ViewClientList; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, + context: action.context, + action: action)) { return; } diff --git a/lib/redux/client/client_reducer.dart b/lib/redux/client/client_reducer.dart index a72ccf487..eddf76100 100644 --- a/lib/redux/client/client_reducer.dart +++ b/lib/redux/client/client_reducer.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:invoiceninja_flutter/data/models/models.dart'; +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:invoiceninja_flutter/redux/client/client_actions.dart'; import 'package:invoiceninja_flutter/redux/client/client_state.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; @@ -92,6 +93,9 @@ final editingReducer = combineReducers([ TypedReducer((client, action) { return ClientEntity(); }), + TypedReducer((client, action) { + return ClientEntity(); + }), ]); final clientListReducer = combineReducers([ diff --git a/lib/redux/dashboard/dashboard_middleware.dart b/lib/redux/dashboard/dashboard_middleware.dart index e7a394bb3..fd6de9f5f 100644 --- a/lib/redux/dashboard/dashboard_middleware.dart +++ b/lib/redux/dashboard/dashboard_middleware.dart @@ -25,8 +25,8 @@ Middleware _createViewDashboard() { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as ViewDashboard; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } diff --git a/lib/redux/expense/expense_middleware.dart b/lib/redux/expense/expense_middleware.dart index 06359b5c3..0b5c4316c 100644 --- a/lib/redux/expense/expense_middleware.dart +++ b/lib/redux/expense/expense_middleware.dart @@ -45,8 +45,8 @@ Middleware _editExpense() { NextDispatcher next) async { final action = dynamicAction as EditExpense; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -70,8 +70,8 @@ Middleware _viewExpense() { NextDispatcher next) async { final action = dynamicAction as ViewExpense; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -89,8 +89,8 @@ Middleware _viewExpenseList() { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as ViewExpenseList; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } diff --git a/lib/redux/expense/expense_reducer.dart b/lib/redux/expense/expense_reducer.dart index f9a5b219a..3cf28b7a3 100644 --- a/lib/redux/expense/expense_reducer.dart +++ b/lib/redux/expense/expense_reducer.dart @@ -1,3 +1,4 @@ +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:redux/redux.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; @@ -32,6 +33,7 @@ final editingReducer = combineReducers([ return action.expense.rebuild((b) => b..isChanged = true); }), TypedReducer(_clearEditing), + TypedReducer(_clearEditing), ]); ExpenseEntity _clearEditing(ExpenseEntity expense, dynamic action) { diff --git a/lib/redux/group/group_middleware.dart b/lib/redux/group/group_middleware.dart index d5ec546ea..f6db589c9 100644 --- a/lib/redux/group/group_middleware.dart +++ b/lib/redux/group/group_middleware.dart @@ -44,8 +44,8 @@ Middleware _editGroup() { NextDispatcher next) async { final action = dynamicAction as EditGroup; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -69,8 +69,8 @@ Middleware _viewGroup() { NextDispatcher next) async { final action = dynamicAction as ViewGroup; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -88,8 +88,8 @@ Middleware _viewGroupList() { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as ViewGroupList; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } diff --git a/lib/redux/group/group_reducer.dart b/lib/redux/group/group_reducer.dart index ea242fb1e..3e2b0967a 100644 --- a/lib/redux/group/group_reducer.dart +++ b/lib/redux/group/group_reducer.dart @@ -1,4 +1,5 @@ import 'package:invoiceninja_flutter/data/models/group_model.dart'; +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:redux/redux.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; import 'package:invoiceninja_flutter/redux/ui/entity_ui_state.dart'; @@ -33,6 +34,7 @@ final editingReducer = combineReducers([ return action.group.rebuild((b) => b..isChanged = true); }), TypedReducer(_clearEditing), + TypedReducer(_clearEditing), ]); GroupEntity _clearEditing(GroupEntity group, dynamic action) { diff --git a/lib/redux/invoice/invoice_middleware.dart b/lib/redux/invoice/invoice_middleware.dart index 2a2c9d0e7..3e7168040 100644 --- a/lib/redux/invoice/invoice_middleware.dart +++ b/lib/redux/invoice/invoice_middleware.dart @@ -53,8 +53,8 @@ Middleware _viewInvoiceList() { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as ViewInvoiceList; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -78,8 +78,8 @@ Middleware _viewInvoice() { NextDispatcher next) async { final action = dynamicAction as ViewInvoice; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -98,8 +98,8 @@ Middleware _editInvoice() { NextDispatcher next) async { final action = dynamicAction as EditInvoice; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } diff --git a/lib/redux/invoice/invoice_reducer.dart b/lib/redux/invoice/invoice_reducer.dart index 6ec378655..58a7f6912 100644 --- a/lib/redux/invoice/invoice_reducer.dart +++ b/lib/redux/invoice/invoice_reducer.dart @@ -1,4 +1,5 @@ import 'package:invoiceninja_flutter/data/models/invoice_model.dart'; +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; import 'package:invoiceninja_flutter/redux/quote/quote_actions.dart'; import 'package:invoiceninja_flutter/redux/ui/entity_ui_state.dart'; @@ -59,6 +60,7 @@ final editingReducer = combineReducers([ TypedReducer(_removeInvoiceItem), TypedReducer(_updateInvoiceItem), TypedReducer(_clearEditing), + TypedReducer(_clearEditing), ]); InvoiceEntity _clearEditing(InvoiceEntity client, dynamic action) { diff --git a/lib/redux/payment/payment_middleware.dart b/lib/redux/payment/payment_middleware.dart index 0ad73c2ab..dbb238b09 100644 --- a/lib/redux/payment/payment_middleware.dart +++ b/lib/redux/payment/payment_middleware.dart @@ -47,8 +47,8 @@ Middleware _editPayment() { NextDispatcher next) async { final action = dynamicAction as EditPayment; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -69,8 +69,8 @@ Middleware _editPayment() { Middleware _viewPayment() { return (Store store, dynamic action, NextDispatcher next) async { - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -88,8 +88,8 @@ Middleware _viewPaymentList() { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as ViewPaymentList; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } diff --git a/lib/redux/payment/payment_reducer.dart b/lib/redux/payment/payment_reducer.dart index f2b0edd4b..3d07376e6 100644 --- a/lib/redux/payment/payment_reducer.dart +++ b/lib/redux/payment/payment_reducer.dart @@ -1,3 +1,4 @@ +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:redux/redux.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; @@ -32,9 +33,10 @@ final editingReducer = combineReducers([ return action.payment.rebuild((b) => b..isChanged = true); }), TypedReducer(_clearEditing), + TypedReducer(_clearEditing), ]); -PaymentEntity _clearEditing(PaymentEntity payment, SelectCompany action) { +PaymentEntity _clearEditing(PaymentEntity payment, dynamic action) { return PaymentEntity(); } diff --git a/lib/redux/product/product_middleware.dart b/lib/redux/product/product_middleware.dart index f316c5a56..8a34668a9 100644 --- a/lib/redux/product/product_middleware.dart +++ b/lib/redux/product/product_middleware.dart @@ -41,8 +41,8 @@ Middleware _editProduct() { NextDispatcher next) async { final action = dynamicAction as EditProduct; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -61,8 +61,8 @@ Middleware _viewProduct() { NextDispatcher next) async { final action = dynamicAction as ViewProduct; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -80,8 +80,8 @@ Middleware _viewProductList() { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as ViewProductList; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } diff --git a/lib/redux/product/product_reducer.dart b/lib/redux/product/product_reducer.dart index d38793c76..3d72e9da5 100644 --- a/lib/redux/product/product_reducer.dart +++ b/lib/redux/product/product_reducer.dart @@ -1,5 +1,6 @@ import 'package:invoiceninja_flutter/data/models/entities.dart'; import 'package:invoiceninja_flutter/data/models/product_model.dart'; +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; import 'package:invoiceninja_flutter/redux/product/product_actions.dart'; import 'package:invoiceninja_flutter/redux/product/product_state.dart'; @@ -34,6 +35,7 @@ final editingReducer = combineReducers([ TypedReducer(_updateEditing), TypedReducer(_updateEditing), TypedReducer(_clearEditing), + TypedReducer(_clearEditing), ]); ProductEntity _clearEditing(ProductEntity client, dynamic action) { diff --git a/lib/redux/project/project_middleware.dart b/lib/redux/project/project_middleware.dart index 6aa644e41..0cc2265f8 100644 --- a/lib/redux/project/project_middleware.dart +++ b/lib/redux/project/project_middleware.dart @@ -45,8 +45,8 @@ Middleware _editProject() { NextDispatcher next) async { final action = dynamicAction as EditProject; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -70,8 +70,8 @@ Middleware _viewProject() { NextDispatcher next) async { final action = dynamicAction as ViewProject; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -89,8 +89,8 @@ Middleware _viewProjectList() { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as ViewProjectList; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } diff --git a/lib/redux/project/project_reducer.dart b/lib/redux/project/project_reducer.dart index 3c1379084..adacc9d9b 100644 --- a/lib/redux/project/project_reducer.dart +++ b/lib/redux/project/project_reducer.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:redux/redux.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; @@ -48,6 +49,7 @@ final editingReducer = combineReducers([ }), TypedReducer(_updateEditing), TypedReducer(_clearEditing), + TypedReducer(_clearEditing), ]); ProjectEntity _clearEditing(ProjectEntity project, dynamic dynamicAction) { diff --git a/lib/redux/quote/quote_middleware.dart b/lib/redux/quote/quote_middleware.dart index a53e68b9e..6c1bfa0e9 100644 --- a/lib/redux/quote/quote_middleware.dart +++ b/lib/redux/quote/quote_middleware.dart @@ -53,8 +53,8 @@ Middleware _viewQuote() { NextDispatcher next) async { final action = dynamicAction as ViewQuote; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -72,8 +72,8 @@ Middleware _viewQuoteList() { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as ViewQuoteList; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -97,8 +97,8 @@ Middleware _editQuote() { NextDispatcher next) async { final action = dynamicAction as EditQuote; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } diff --git a/lib/redux/quote/quote_reducer.dart b/lib/redux/quote/quote_reducer.dart index 247bba64a..a64bb37a7 100644 --- a/lib/redux/quote/quote_reducer.dart +++ b/lib/redux/quote/quote_reducer.dart @@ -1,5 +1,6 @@ import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/data/models/invoice_model.dart'; +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; import 'package:invoiceninja_flutter/redux/quote/quote_actions.dart'; import 'package:invoiceninja_flutter/redux/quote/quote_state.dart'; @@ -57,6 +58,7 @@ final editingReducer = combineReducers([ TypedReducer(_removeQuoteItem), TypedReducer(_updateQuoteItem), TypedReducer(_clearEditing), + TypedReducer(_clearEditing), ]); InvoiceEntity _clearEditing(InvoiceEntity client, dynamic action) { diff --git a/lib/redux/settings/settings_middleware.dart b/lib/redux/settings/settings_middleware.dart index 93686592a..6462f6d43 100644 --- a/lib/redux/settings/settings_middleware.dart +++ b/lib/redux/settings/settings_middleware.dart @@ -30,8 +30,8 @@ Middleware _viewSettings() { final action = dynamicAction as ViewSettings; final uiState = store.state.uiState; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } diff --git a/lib/redux/task/task_middleware.dart b/lib/redux/task/task_middleware.dart index 6559ddbe0..cc5318911 100644 --- a/lib/redux/task/task_middleware.dart +++ b/lib/redux/task/task_middleware.dart @@ -44,8 +44,8 @@ Middleware _editTask() { NextDispatcher next) async { final action = dynamicAction as EditTask; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -69,8 +69,8 @@ Middleware _viewTask() { NextDispatcher next) async { final action = dynamicAction as ViewTask; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -88,8 +88,8 @@ Middleware _viewTaskList() { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as ViewTaskList; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } diff --git a/lib/redux/task/task_reducer.dart b/lib/redux/task/task_reducer.dart index 7fdd58a0f..6cbba6331 100644 --- a/lib/redux/task/task_reducer.dart +++ b/lib/redux/task/task_reducer.dart @@ -1,3 +1,4 @@ +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:redux/redux.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; @@ -44,6 +45,7 @@ final editingReducer = combineReducers([ TypedReducer(_removeTaskTime), TypedReducer(_updateTaskTime), TypedReducer(_clearEditing), + TypedReducer(_clearEditing), ]); TaskEntity _clearEditing(TaskEntity task, dynamic action) { diff --git a/lib/redux/vendor/vendor_middleware.dart b/lib/redux/vendor/vendor_middleware.dart index fcacd97b3..66afea5f3 100644 --- a/lib/redux/vendor/vendor_middleware.dart +++ b/lib/redux/vendor/vendor_middleware.dart @@ -45,8 +45,8 @@ Middleware _editVendor() { NextDispatcher next) async { final action = dynamicAction as EditVendor; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -70,8 +70,8 @@ Middleware _viewVendor() { NextDispatcher next) async { final action = dynamicAction as ViewVendor; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -89,8 +89,8 @@ Middleware _viewVendorList() { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as ViewVendorList; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } diff --git a/lib/redux/vendor/vendor_reducer.dart b/lib/redux/vendor/vendor_reducer.dart index 32b7c4523..7a76fc875 100644 --- a/lib/redux/vendor/vendor_reducer.dart +++ b/lib/redux/vendor/vendor_reducer.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:redux/redux.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; @@ -63,6 +64,7 @@ final editingReducer = combineReducers([ TypedReducer(_removeContact), TypedReducer(_updateContact), TypedReducer(_clearEditing), + TypedReducer(_clearEditing), ]); VendorEntity _clearEditing(VendorEntity vendor, dynamic action) { diff --git a/lib/ui/app/dialogs/alert_dialog.dart b/lib/ui/app/dialogs/alert_dialog.dart index fbf320c79..9044bafc7 100644 --- a/lib/ui/app/dialogs/alert_dialog.dart +++ b/lib/ui/app/dialogs/alert_dialog.dart @@ -3,10 +3,11 @@ import 'package:invoiceninja_flutter/ui/app/buttons/elevated_button.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; class MessageDialog extends StatelessWidget { - const MessageDialog(this.message, {this.onDismiss}); + const MessageDialog(this.message, {this.onDismiss, this.onDiscard}); final String message; final Function onDismiss; + final Function onDiscard; @override Widget build(BuildContext context) { @@ -22,24 +23,36 @@ class MessageDialog extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ - /* - Text(localization.anErrorOccurred, - style: Theme.of(context).textTheme.title), - */ SizedBox(height: 20.0), Text( message, style: Theme.of(context).textTheme.title, ), SizedBox(height: 40.0), - ElevatedButton( - onPressed: () { - Navigator.of(context).pop(); - if (onDismiss != null) { - onDismiss(); - } - }, - label: localization.dismiss, + Row( + mainAxisSize: MainAxisSize.min, + children: [ + if (onDiscard != null) + Padding( + padding: const EdgeInsets.only(right: 10), + child: FlatButton( + child: Text(localization.discardChanges), + onPressed: () { + Navigator.of(context).pop(); + onDiscard(); + } + ), + ), + ElevatedButton( + onPressed: () { + Navigator.of(context).pop(); + if (onDismiss != null) { + onDismiss(); + } + }, + label: localization.dismiss, + ), + ], ), ], ), diff --git a/lib/ui/app/forms/app_form.dart b/lib/ui/app/forms/app_form.dart index 1a2d28c7b..c072eea2d 100644 --- a/lib/ui/app/forms/app_form.dart +++ b/lib/ui/app/forms/app_form.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:invoiceninja_flutter/ui/app/form_card.dart'; class AppForm extends StatelessWidget { const AppForm({ diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index 437cc199b..dd6576f40 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -14,6 +14,7 @@ abstract class LocaleCodeAware { mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { + 'discard_changes': 'Discard Changes', 'default_value': 'Default value', 'disabled': 'Disabled', 'currency_format': 'Currency Format', @@ -112,7 +113,7 @@ mixin LocalizationsProvider on LocaleCodeAware { 'email_login': 'Email Login', 'create_new': 'Create New', 'no_record_selected': 'No record selected', - 'error_unsaved_changes': 'Please cancel or save your changes', + 'error_unsaved_changes': 'Your changes have not been saved', 'download': 'Download', 'requires_an_enterprise_plan': 'Requires an enterprise plan', 'take_picture': 'Take Picture', @@ -14835,6 +14836,8 @@ mixin LocalizationsProvider on LocaleCodeAware { String get defaultValue => _localizedValues[localeCode]['default_value']; + String get discardChanges => _localizedValues[localeCode]['discard_changes']; + String lookup(String key) { final lookupKey = toSnakeCase(key); diff --git a/stubs/redux/stub/stub_middleware b/stubs/redux/stub/stub_middleware index 7c73f93af..dfb805483 100644 --- a/stubs/redux/stub/stub_middleware +++ b/stubs/redux/stub/stub_middleware @@ -43,8 +43,8 @@ Middleware _editStub() { final action = dynamicAction as EditStub; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } @@ -68,10 +68,10 @@ Middleware _viewStub() { final action = dynamicAction as ViewStub; - if (hasChanges( - store: store, context: action.context, force: action.force)) { - return; - } + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { + return; + } next(action); @@ -88,8 +88,8 @@ Middleware _viewStubList() { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as ViewStubList; - if (hasChanges( - store: store, context: action.context, force: action.force)) { + if (!action.force && hasChanges( + store: store, context: action.context, action: action)) { return; } diff --git a/stubs/redux/stub/stub_reducer b/stubs/redux/stub/stub_reducer index 3de137233..1392d77e6 100644 --- a/stubs/redux/stub/stub_reducer +++ b/stubs/redux/stub/stub_reducer @@ -1,4 +1,5 @@ import 'package:redux/redux.dart'; +import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; import 'package:invoiceninja_flutter/redux/ui/entity_ui_state.dart'; @@ -32,6 +33,7 @@ final editingReducer = combineReducers([ return action.stub.rebuild((b) => b..isChanged = true); }), TypedReducer(_clearEditing), + TypedReducer(_clearEditing), ]); StubEntity _clearEditing(StubEntity stub, dynamic action) {