This commit is contained in:
Hillel Coren 2018-09-04 21:16:01 -07:00
parent 815c724b17
commit f3370e521d
5 changed files with 70 additions and 7 deletions

View File

@ -45,9 +45,12 @@ class PaymentRepository {
}
response = await webClient.post(url, company.token, json.encode(data));
} else {
var url = auth.url + '/payments/' + payment.id.toString();
var url = '${auth.url}/payments/${payment.id}?';
if (sendEmail) {
url += '&email_receipt=true';
}
if (action != null) {
url += '?action=' + action.toString();
url += '&action=' + action.toString();
}
response = await webClient.put(url, company.token, json.encode(data));
}

View File

@ -6,12 +6,14 @@ import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
class ViewPaymentList implements PersistUI {
final BuildContext context;
ViewPaymentList(this.context);
}
class ViewPayment implements PersistUI {
final int paymentId;
final BuildContext context;
ViewPayment({this.paymentId, this.context});
}
@ -20,11 +22,14 @@ class EditPayment implements PersistUI {
final BuildContext context;
final Completer completer;
final bool trackRoute;
EditPayment({this.payment, this.context, this.completer, this.trackRoute = true});
EditPayment(
{this.payment, this.context, this.completer, this.trackRoute = true});
}
class UpdatePayment implements PersistUI {
final PaymentEntity payment;
UpdatePayment(this.payment);
}
@ -54,6 +59,7 @@ class LoadPaymentRequest implements StartLoading {}
class LoadPaymentFailure implements StopLoading {
final dynamic error;
LoadPaymentFailure(this.error);
@override
@ -64,6 +70,7 @@ class LoadPaymentFailure implements StopLoading {
class LoadPaymentSuccess implements StopLoading, PersistData {
final PaymentEntity payment;
LoadPaymentSuccess(this.payment);
@override
@ -76,6 +83,7 @@ class LoadPaymentsRequest implements StartLoading {}
class LoadPaymentsFailure implements StopLoading {
final dynamic error;
LoadPaymentsFailure(this.error);
@override
@ -86,6 +94,7 @@ class LoadPaymentsFailure implements StopLoading {
class LoadPaymentsSuccess implements StopLoading, PersistData {
final BuiltList<PaymentEntity> payments;
LoadPaymentsSuccess(this.payments);
@override
@ -94,11 +103,10 @@ class LoadPaymentsSuccess implements StopLoading, PersistData {
}
}
class SavePaymentRequest implements StartSaving {
final Completer completer;
final PaymentEntity payment;
SavePaymentRequest({this.completer, this.payment});
}
@ -110,12 +118,14 @@ class SavePaymentSuccess implements StopSaving, PersistData, PersistUI {
class AddPaymentSuccess implements StopSaving, PersistData, PersistUI {
final PaymentEntity payment;
AddPaymentSuccess(this.payment);
}
class SavePaymentFailure implements StopSaving {
final Object error;
SavePaymentFailure (this.error);
SavePaymentFailure(this.error);
}
class ArchivePaymentRequest implements StartSaving {
@ -127,11 +137,13 @@ class ArchivePaymentRequest implements StartSaving {
class ArchivePaymentSuccess implements StopSaving, PersistData {
final PaymentEntity payment;
ArchivePaymentSuccess(this.payment);
}
class ArchivePaymentFailure implements StopSaving {
final PaymentEntity payment;
ArchivePaymentFailure(this.payment);
}
@ -144,40 +156,59 @@ class DeletePaymentRequest implements StartSaving {
class DeletePaymentSuccess implements StopSaving, PersistData {
final PaymentEntity payment;
DeletePaymentSuccess(this.payment);
}
class DeletePaymentFailure implements StopSaving {
final PaymentEntity payment;
DeletePaymentFailure(this.payment);
}
class RestorePaymentRequest implements StartSaving {
final Completer completer;
final int paymentId;
RestorePaymentRequest(this.completer, this.paymentId);
}
class RestorePaymentSuccess implements StopSaving, PersistData {
final PaymentEntity payment;
RestorePaymentSuccess(this.payment);
}
class RestorePaymentFailure implements StopSaving {
final PaymentEntity payment;
RestorePaymentFailure(this.payment);
}
class EmailPaymentRequest implements StartSaving {
final Completer completer;
final PaymentEntity payment;
EmailPaymentRequest(this.completer, this.payment);
}
class EmailPaymentSuccess implements StopSaving, PersistData {}
class EmailPaymentFailure implements StopSaving {
final dynamic error;
EmailPaymentFailure(this.error);
}
class FilterPayments {
final String filter;
FilterPayments(this.filter);
}
class SortPayments implements PersistUI {
final String field;
SortPayments(this.field);
}
@ -205,4 +236,3 @@ class FilterPaymentsByEntity implements PersistUI {
FilterPaymentsByEntity({this.entityId, this.entityType});
}

View File

@ -24,6 +24,7 @@ List<Middleware<AppState>> createStorePaymentsMiddleware([
final archivePayment = _archivePayment(repository);
final deletePayment = _deletePayment(repository);
final restorePayment = _restorePayment(repository);
final emailPayment = _emailPayment(repository);
return [
TypedMiddleware<AppState, ViewPaymentList>(viewPaymentList),
@ -35,6 +36,7 @@ List<Middleware<AppState>> createStorePaymentsMiddleware([
TypedMiddleware<AppState, ArchivePaymentRequest>(archivePayment),
TypedMiddleware<AppState, DeletePaymentRequest>(deletePayment),
TypedMiddleware<AppState, RestorePaymentRequest>(restorePayment),
TypedMiddleware<AppState, EmailPaymentRequest>(emailPayment),
];
}
@ -169,6 +171,25 @@ Middleware<AppState> _savePayment(PaymentRepository repository) {
};
}
Middleware<AppState> _emailPayment(PaymentRepository repository) {
return (Store<AppState> store, dynamic action, NextDispatcher next) {
repository
.saveData(
store.state.selectedCompany, store.state.authState, action.payment, sendEmail: true)
.then((PaymentEntity payment) {
store.dispatch(SavePaymentSuccess(payment));
action.completer.complete(null);
}).catchError((Object error) {
print(error);
store.dispatch(SavePaymentFailure(error));
action.completer.completeError(error);
});
next(action);
};
}
/*
Middleware<AppState> _loadPayment(PaymentRepository repository) {
return (Store<AppState> store, dynamic action, NextDispatcher next) {

View File

@ -96,6 +96,11 @@ class PaymentListVM {
},
onEntityAction: (context, payment, action) {
switch (action) {
case EntityAction.email:
store.dispatch(EmailPaymentRequest(
popCompleter(context, AppLocalization.of(context).emailedPayment), payment
));
break;
case EntityAction.restore:
store.dispatch(RestorePaymentRequest(
popCompleter(

View File

@ -118,6 +118,7 @@ class AppLocalization {
'deleted_invoice': 'Successfully deleted invoice',
'restored_invoice': 'Successfully restored invoice',
'emailed_invoice': 'Successfully emailed invoice',
'emailed_payment': 'Successfully emailed payment',
'amount': 'Amount',
'invoice_number': 'Invoice Number',
'invoice_date': 'Invoice Date',
@ -7353,6 +7354,9 @@ class AppLocalization {
String get emailedInvoice =>
_localizedValues[locale.languageCode]['emailed_invoice'];
String get emailedPayment =>
_localizedValues[locale.languageCode]['emailed_payment'];
String get amount => _localizedValues[locale.languageCode]['amount'];
String get invoiceNumber =>