This commit is contained in:
Hillel Coren 2018-09-04 15:19:36 -07:00
parent d651e7fd66
commit 815c724b17
5 changed files with 42 additions and 21 deletions

View File

@ -24,8 +24,7 @@ class PaymentRepository {
url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}'; url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}';
} }
final dynamic response = final dynamic response = await webClient.get(url, company.token);
await webClient.get(url, company.token);
final PaymentListResponse paymentResponse = final PaymentListResponse paymentResponse =
serializers.deserializeWith(PaymentListResponse.serializer, response); serializers.deserializeWith(PaymentListResponse.serializer, response);
@ -33,14 +32,18 @@ class PaymentRepository {
return paymentResponse.data; return paymentResponse.data;
} }
Future<PaymentEntity> saveData(CompanyEntity company, AuthState auth, PaymentEntity payment, Future<PaymentEntity> saveData(
[EntityAction action]) async { CompanyEntity company, AuthState auth, PaymentEntity payment,
{EntityAction action, bool sendEmail}) async {
final data = serializers.serializeWith(PaymentEntity.serializer, payment); final data = serializers.serializeWith(PaymentEntity.serializer, payment);
dynamic response; dynamic response;
if (payment.isNew) { if (payment.isNew) {
response = await webClient.post( var url = auth.url + '/payments';
auth.url + '/payments', company.token, json.encode(data)); if (sendEmail) {
url += '?email_receipt=true';
}
response = await webClient.post(url, company.token, json.encode(data));
} else { } else {
var url = auth.url + '/payments/' + payment.id.toString(); var url = auth.url + '/payments/' + payment.id.toString();
if (action != null) { if (action != null) {

View File

@ -78,7 +78,7 @@ Middleware<AppState> _archivePayment(PaymentRepository repository) {
final origPayment = store.state.paymentState.map[action.paymentId]; final origPayment = store.state.paymentState.map[action.paymentId];
repository repository
.saveData(store.state.selectedCompany, store.state.authState, .saveData(store.state.selectedCompany, store.state.authState,
origPayment, EntityAction.archive) origPayment, action: EntityAction.archive)
.then((PaymentEntity payment) { .then((PaymentEntity payment) {
store.dispatch(ArchivePaymentSuccess(payment)); store.dispatch(ArchivePaymentSuccess(payment));
if (action.completer != null) { if (action.completer != null) {
@ -101,7 +101,7 @@ Middleware<AppState> _deletePayment(PaymentRepository repository) {
final origPayment = store.state.paymentState.map[action.paymentId]; final origPayment = store.state.paymentState.map[action.paymentId];
repository repository
.saveData(store.state.selectedCompany, store.state.authState, .saveData(store.state.selectedCompany, store.state.authState,
origPayment, EntityAction.delete) origPayment, action: EntityAction.delete)
.then((PaymentEntity payment) { .then((PaymentEntity payment) {
store.dispatch(DeletePaymentSuccess(payment)); store.dispatch(DeletePaymentSuccess(payment));
store.dispatch(LoadInvoice(invoiceId: payment.invoiceId)); store.dispatch(LoadInvoice(invoiceId: payment.invoiceId));
@ -125,7 +125,7 @@ Middleware<AppState> _restorePayment(PaymentRepository repository) {
final origPayment = store.state.paymentState.map[action.paymentId]; final origPayment = store.state.paymentState.map[action.paymentId];
repository repository
.saveData(store.state.selectedCompany, store.state.authState, .saveData(store.state.selectedCompany, store.state.authState,
origPayment, EntityAction.restore) origPayment, action: EntityAction.restore)
.then((PaymentEntity payment) { .then((PaymentEntity payment) {
store.dispatch(RestorePaymentSuccess(payment)); store.dispatch(RestorePaymentSuccess(payment));
store.dispatch(LoadInvoice(invoiceId: payment.invoiceId)); store.dispatch(LoadInvoice(invoiceId: payment.invoiceId));
@ -146,9 +146,11 @@ Middleware<AppState> _restorePayment(PaymentRepository repository) {
Middleware<AppState> _savePayment(PaymentRepository repository) { Middleware<AppState> _savePayment(PaymentRepository repository) {
return (Store<AppState> store, dynamic action, NextDispatcher next) { return (Store<AppState> store, dynamic action, NextDispatcher next) {
final PaymentEntity payment = action.payment;
final bool sendEmail = payment.isNew ? store.state.uiState.emailPayment : false;
repository repository
.saveData( .saveData(
store.state.selectedCompany, store.state.authState, action.payment) store.state.selectedCompany, store.state.authState, action.payment, sendEmail: sendEmail)
.then((PaymentEntity payment) { .then((PaymentEntity payment) {
if (action.payment.isNew) { if (action.payment.isNew) {
store.dispatch(AddPaymentSuccess(payment)); store.dispatch(AddPaymentSuccess(payment));

View File

@ -238,17 +238,15 @@ class _PaymentEditState extends State<PaymentEdit> {
), ),
], ],
), ),
FormCard(children: <Widget>[ payment.isNew ? FormCard(children: <Widget>[
SwitchListTile( SwitchListTile(
activeColor: Theme.of(context).accentColor, activeColor: Theme.of(context).accentColor,
title: Text(localization.sendEmail), title: Text(localization.sendEmail),
value: true, value: viewModel.uiState.emailPayment,
subtitle: Text(localization.sendReceiptToClient), subtitle: Text(localization.sendReceiptToClient),
//value: client.showTasksInPortal, onChanged: (value) => viewModel.onEmailChanged(value),
//onChanged: (value) => viewModel
//.onChanged(client.rebuild((b) => b..showTasksInPortal = value)),
), ),
]), ]) : Container(),
], ],
), ),
), ),

View File

@ -4,10 +4,13 @@ import 'package:built_collection/built_collection.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:invoiceninja_flutter/constants.dart';
import 'package:invoiceninja_flutter/data/models/client_model.dart'; import 'package:invoiceninja_flutter/data/models/client_model.dart';
import 'package:invoiceninja_flutter/data/models/invoice_model.dart'; import 'package:invoiceninja_flutter/data/models/invoice_model.dart';
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
import 'package:invoiceninja_flutter/redux/static/static_state.dart'; import 'package:invoiceninja_flutter/redux/static/static_state.dart';
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart'; import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
import 'package:invoiceninja_flutter/redux/ui/ui_state.dart';
import 'package:invoiceninja_flutter/ui/payment/payment_screen.dart'; import 'package:invoiceninja_flutter/ui/payment/payment_screen.dart';
import 'package:invoiceninja_flutter/ui/payment/view/payment_view_vm.dart'; import 'package:invoiceninja_flutter/ui/payment/view/payment_view_vm.dart';
import 'package:invoiceninja_flutter/utils/completers.dart'; import 'package:invoiceninja_flutter/utils/completers.dart';
@ -16,6 +19,7 @@ import 'package:invoiceninja_flutter/redux/payment/payment_actions.dart';
import 'package:invoiceninja_flutter/data/models/payment_model.dart'; import 'package:invoiceninja_flutter/data/models/payment_model.dart';
import 'package:invoiceninja_flutter/ui/payment/edit/payment_edit.dart'; import 'package:invoiceninja_flutter/ui/payment/edit/payment_edit.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:shared_preferences/shared_preferences.dart';
class PaymentEditScreen extends StatelessWidget { class PaymentEditScreen extends StatelessWidget {
static const String route = '/payment/edit'; static const String route = '/payment/edit';
@ -42,7 +46,9 @@ class PaymentEditVM {
final PaymentEntity origPayment; final PaymentEntity origPayment;
final Function(PaymentEntity) onChanged; final Function(PaymentEntity) onChanged;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(bool) onEmailChanged;
final BuiltMap<int, InvoiceEntity> invoiceMap; final BuiltMap<int, InvoiceEntity> invoiceMap;
final UIState uiState;
final BuiltList<int> invoiceList; final BuiltList<int> invoiceList;
final BuiltMap<int, ClientEntity> clientMap; final BuiltMap<int, ClientEntity> clientMap;
final BuiltList<int> clientList; final BuiltList<int> clientList;
@ -56,6 +62,8 @@ class PaymentEditVM {
@required this.origPayment, @required this.origPayment,
@required this.onChanged, @required this.onChanged,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onEmailChanged,
@required this.uiState,
@required this.invoiceMap, @required this.invoiceMap,
@required this.invoiceList, @required this.invoiceList,
@required this.clientMap, @required this.clientMap,
@ -75,6 +83,7 @@ class PaymentEditVM {
isDirty: payment.isNew, isDirty: payment.isNew,
origPayment: state.paymentState.map[payment.id], origPayment: state.paymentState.map[payment.id],
payment: payment, payment: payment,
uiState: state.uiState,
staticState: state.staticState, staticState: state.staticState,
invoiceMap: state.invoiceState.map, invoiceMap: state.invoiceState.map,
invoiceList: state.invoiceState.list, invoiceList: state.invoiceState.list,
@ -83,6 +92,11 @@ class PaymentEditVM {
onChanged: (PaymentEntity payment) { onChanged: (PaymentEntity payment) {
store.dispatch(UpdatePayment(payment)); store.dispatch(UpdatePayment(payment));
}, },
onEmailChanged: (value) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setBool(kSharedPrefEmailPayment, value);
store.dispatch(UserSettingsChanged(emailPayment: value));
},
onBackPressed: () { onBackPressed: () {
store.dispatch(UpdateCurrentRoute(PaymentScreen.route)); store.dispatch(UpdateCurrentRoute(PaymentScreen.route));
}, },

View File

@ -123,12 +123,16 @@ class _PaymentViewState extends State<PaymentView> {
height: 12.0, height: 12.0,
), ),
payment.privateNotes != null && payment.privateNotes.isNotEmpty payment.privateNotes != null && payment.privateNotes.isNotEmpty
? IconMessage(payment.privateNotes) ? Column(
: Container(), children: <Widget>[
IconMessage(payment.privateNotes),
Container( Container(
color: Theme.of(context).backgroundColor, color: Theme.of(context).backgroundColor,
height: 12.0, height: 12.0,
), ),
],
)
: Container(),
FieldGrid(fields), FieldGrid(fields),
], ],
)); ));