Only save if changed when using action on edit invoice page
This commit is contained in:
parent
fc303dcc58
commit
d69bf5c883
|
|
@ -6,6 +6,7 @@ import 'package:flutter_styled_toast/flutter_styled_toast.dart';
|
||||||
import 'package:invoiceninja_flutter/main_app.dart';
|
import 'package:invoiceninja_flutter/main_app.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/credit/credit_actions.dart';
|
import 'package:invoiceninja_flutter/redux/credit/credit_actions.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/credit/credit_selectors.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
|
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
|
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/credit/edit/credit_edit.dart';
|
import 'package:invoiceninja_flutter/ui/credit/edit/credit_edit.dart';
|
||||||
|
|
@ -84,39 +85,54 @@ class CreditEditVM extends AbstractInvoiceEditVM {
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Completer<InvoiceEntity> completer = Completer<InvoiceEntity>();
|
|
||||||
store.dispatch(
|
|
||||||
SaveCreditRequest(completer: completer, credit: credit));
|
|
||||||
return completer.future.then((savedCredit) {
|
|
||||||
showToast(credit.isNew
|
|
||||||
? localization.createdCredit
|
|
||||||
: localization.updatedCredit);
|
|
||||||
|
|
||||||
if (state.prefState.isMobile) {
|
if (!hasCreditChanges(credit, state.creditState.map) &&
|
||||||
store.dispatch(UpdateCurrentRoute(CreditViewScreen.route));
|
[
|
||||||
if (credit.isNew) {
|
EntityAction.emailCredit,
|
||||||
navigator.pushReplacementNamed(CreditViewScreen.route);
|
EntityAction.viewPdf,
|
||||||
|
].contains(action)) {
|
||||||
|
handleEntityAction(credit, action);
|
||||||
|
} else {
|
||||||
|
final Completer<InvoiceEntity> completer =
|
||||||
|
Completer<InvoiceEntity>();
|
||||||
|
store.dispatch(
|
||||||
|
SaveCreditRequest(completer: completer, credit: credit));
|
||||||
|
return completer.future.then((savedCredit) {
|
||||||
|
showToast(credit.isNew
|
||||||
|
? localization.createdCredit
|
||||||
|
: localization.updatedCredit);
|
||||||
|
|
||||||
|
if (state.prefState.isMobile) {
|
||||||
|
store.dispatch(UpdateCurrentRoute(CreditViewScreen.route));
|
||||||
|
if (credit.isNew) {
|
||||||
|
navigator.pushReplacementNamed(CreditViewScreen.route);
|
||||||
|
} else {
|
||||||
|
navigator.pop(savedCredit);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
navigator.pop(savedCredit);
|
viewEntity(entity: savedCredit);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
viewEntity(entity: savedCredit);
|
|
||||||
|
|
||||||
if (state.prefState.isEditorFullScreen(EntityType.credit)) {
|
if (state.prefState.isEditorFullScreen(EntityType.credit)) {
|
||||||
editEntity(
|
editEntity(
|
||||||
context: navigatorKey.currentContext, entity: savedCredit);
|
context: navigatorKey.currentContext,
|
||||||
|
entity: savedCredit);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([
|
||||||
|
EntityAction.emailCredit,
|
||||||
|
EntityAction.viewPdf,
|
||||||
|
].contains(action)) {
|
||||||
|
handleEntityAction(savedCredit, action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (action != null) {
|
}).catchError((Object error) {
|
||||||
handleEntityAction(savedCredit, action);
|
showDialog<ErrorDialog>(
|
||||||
}
|
context: navigatorKey.currentContext,
|
||||||
}
|
builder: (BuildContext context) {
|
||||||
}).catchError((Object error) {
|
return ErrorDialog(error);
|
||||||
showDialog<ErrorDialog>(
|
});
|
||||||
context: navigatorKey.currentContext,
|
});
|
||||||
builder: (BuildContext context) {
|
}
|
||||||
return ErrorDialog(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onItemsAdded: (items, clientId) {
|
onItemsAdded: (items, clientId) {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import 'package:flutter_redux/flutter_redux.dart';
|
||||||
import 'package:flutter_styled_toast/flutter_styled_toast.dart';
|
import 'package:flutter_styled_toast/flutter_styled_toast.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/quote/quote_actions.dart';
|
import 'package:invoiceninja_flutter/redux/quote/quote_actions.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/quote/quote_selectors.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
|
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
|
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/invoice/edit/invoice_edit_vm.dart';
|
import 'package:invoiceninja_flutter/ui/invoice/edit/invoice_edit_vm.dart';
|
||||||
|
|
@ -84,46 +85,55 @@ class QuoteEditVM extends AbstractInvoiceEditVM {
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Completer<InvoiceEntity> completer = Completer<InvoiceEntity>();
|
if (!hasQuoteChanges(quote, state.quoteState.map) &&
|
||||||
store.dispatch(SaveQuoteRequest(
|
[
|
||||||
completer: completer,
|
|
||||||
quote: quote,
|
|
||||||
action: action,
|
|
||||||
));
|
|
||||||
return completer.future.then((savedQuote) {
|
|
||||||
showToast(quote.isNew
|
|
||||||
? localization.createdQuote
|
|
||||||
: localization.updatedQuote);
|
|
||||||
|
|
||||||
if (state.prefState.isMobile) {
|
|
||||||
store.dispatch(UpdateCurrentRoute(QuoteViewScreen.route));
|
|
||||||
if (quote.isNew) {
|
|
||||||
navigator.pushReplacementNamed(QuoteViewScreen.route);
|
|
||||||
} else {
|
|
||||||
navigator.pop(savedQuote);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
viewEntity(entity: savedQuote);
|
|
||||||
|
|
||||||
if (state.prefState.isEditorFullScreen(EntityType.invoice)) {
|
|
||||||
editEntity(
|
|
||||||
context: navigatorKey.currentContext, entity: savedQuote);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([
|
|
||||||
EntityAction.emailQuote,
|
EntityAction.emailQuote,
|
||||||
EntityAction.viewPdf,
|
EntityAction.viewPdf,
|
||||||
].contains(action)) {
|
].contains(action)) {
|
||||||
handleEntityAction(savedQuote, action);
|
handleEntityAction(quote, action);
|
||||||
|
} else {
|
||||||
|
final Completer<InvoiceEntity> completer =
|
||||||
|
Completer<InvoiceEntity>();
|
||||||
|
store.dispatch(SaveQuoteRequest(
|
||||||
|
completer: completer,
|
||||||
|
quote: quote,
|
||||||
|
action: action,
|
||||||
|
));
|
||||||
|
return completer.future.then((savedQuote) {
|
||||||
|
showToast(quote.isNew
|
||||||
|
? localization.createdQuote
|
||||||
|
: localization.updatedQuote);
|
||||||
|
|
||||||
|
if (state.prefState.isMobile) {
|
||||||
|
store.dispatch(UpdateCurrentRoute(QuoteViewScreen.route));
|
||||||
|
if (quote.isNew) {
|
||||||
|
navigator.pushReplacementNamed(QuoteViewScreen.route);
|
||||||
|
} else {
|
||||||
|
navigator.pop(savedQuote);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
viewEntity(entity: savedQuote);
|
||||||
|
|
||||||
|
if (state.prefState.isEditorFullScreen(EntityType.invoice)) {
|
||||||
|
editEntity(
|
||||||
|
context: navigatorKey.currentContext, entity: savedQuote);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([
|
||||||
|
EntityAction.emailQuote,
|
||||||
|
EntityAction.viewPdf,
|
||||||
|
].contains(action)) {
|
||||||
|
handleEntityAction(savedQuote, action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}).catchError((Object error) {
|
||||||
}).catchError((Object error) {
|
showDialog<ErrorDialog>(
|
||||||
showDialog<ErrorDialog>(
|
context: navigatorKey.currentContext,
|
||||||
context: navigatorKey.currentContext,
|
builder: (BuildContext context) {
|
||||||
builder: (BuildContext context) {
|
return ErrorDialog(error);
|
||||||
return ErrorDialog(error);
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onItemsAdded: (items, clientId) {
|
onItemsAdded: (items, clientId) {
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import 'package:flutter_redux/flutter_redux.dart';
|
||||||
import 'package:flutter_styled_toast/flutter_styled_toast.dart';
|
import 'package:flutter_styled_toast/flutter_styled_toast.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/recurring_invoice/recurring_invoice_actions.dart';
|
import 'package:invoiceninja_flutter/redux/recurring_invoice/recurring_invoice_actions.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/recurring_invoice/recurring_invoice_selectors.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
|
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
|
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/invoice/edit/invoice_edit_vm.dart';
|
import 'package:invoiceninja_flutter/ui/invoice/edit/invoice_edit_vm.dart';
|
||||||
|
|
@ -85,44 +86,54 @@ class RecurringInvoiceEditVM extends AbstractInvoiceEditVM {
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final Completer<InvoiceEntity> completer = Completer<InvoiceEntity>();
|
if (!hasRecurringInvoiceChanges(
|
||||||
store.dispatch(SaveRecurringInvoiceRequest(
|
recurringInvoice, state.recurringInvoiceState.map) &&
|
||||||
completer: completer, recurringInvoice: recurringInvoice));
|
[
|
||||||
return completer.future.then((savedRecurringInvoice) {
|
EntityAction.emailInvoice,
|
||||||
showToast(recurringInvoice.isNew
|
EntityAction.viewPdf,
|
||||||
? localization.createdRecurringInvoice
|
].contains(action)) {
|
||||||
: localization.updatedRecurringInvoice);
|
handleEntityAction(recurringInvoice, action);
|
||||||
|
} else {
|
||||||
|
final Completer<InvoiceEntity> completer =
|
||||||
|
Completer<InvoiceEntity>();
|
||||||
|
store.dispatch(SaveRecurringInvoiceRequest(
|
||||||
|
completer: completer, recurringInvoice: recurringInvoice));
|
||||||
|
return completer.future.then((savedRecurringInvoice) {
|
||||||
|
showToast(recurringInvoice.isNew
|
||||||
|
? localization.createdRecurringInvoice
|
||||||
|
: localization.updatedRecurringInvoice);
|
||||||
|
|
||||||
if (state.prefState.isMobile) {
|
if (state.prefState.isMobile) {
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
UpdateCurrentRoute(RecurringInvoiceViewScreen.route));
|
UpdateCurrentRoute(RecurringInvoiceViewScreen.route));
|
||||||
if (recurringInvoice.isNew) {
|
if (recurringInvoice.isNew) {
|
||||||
navigator
|
navigator
|
||||||
.pushReplacementNamed(RecurringInvoiceViewScreen.route);
|
.pushReplacementNamed(RecurringInvoiceViewScreen.route);
|
||||||
|
} else {
|
||||||
|
navigator.pop(savedRecurringInvoice);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
navigator.pop(savedRecurringInvoice);
|
viewEntity(entity: savedRecurringInvoice);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
viewEntity(entity: savedRecurringInvoice);
|
|
||||||
|
|
||||||
if (state.prefState.isEditorFullScreen(EntityType.invoice)) {
|
if (state.prefState.isEditorFullScreen(EntityType.invoice)) {
|
||||||
editEntity(
|
editEntity(
|
||||||
context: navigatorKey.currentContext,
|
context: navigatorKey.currentContext,
|
||||||
entity: savedRecurringInvoice);
|
entity: savedRecurringInvoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([EntityAction.emailInvoice, EntityAction.viewPdf]
|
if ([EntityAction.emailInvoice, EntityAction.viewPdf]
|
||||||
.contains(action)) {
|
.contains(action)) {
|
||||||
handleEntityAction(savedRecurringInvoice, action);
|
handleEntityAction(savedRecurringInvoice, action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}).catchError((Object error) {
|
||||||
}).catchError((Object error) {
|
showDialog<ErrorDialog>(
|
||||||
showDialog<ErrorDialog>(
|
context: navigatorKey.currentContext,
|
||||||
context: navigatorKey.currentContext,
|
builder: (BuildContext context) {
|
||||||
builder: (BuildContext context) {
|
return ErrorDialog(error);
|
||||||
return ErrorDialog(error);
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onItemsAdded: (items, clientId) {
|
onItemsAdded: (items, clientId) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue