Email templates

This commit is contained in:
Hillel Coren 2018-08-13 22:11:33 -07:00
parent 0683c789fd
commit a1ee7e91ab
5 changed files with 18 additions and 6 deletions

View File

@ -68,8 +68,15 @@ class InvoiceRepository {
} }
Future emailInvoice( Future emailInvoice(
CompanyEntity company, AuthState auth, InvoiceEntity invoice, String subject, String body) async { CompanyEntity company,
AuthState auth,
InvoiceEntity invoice,
EmailTemplate template,
String subject,
String body) async {
final data = { final data = {
'reminder': template == EmailTemplate.initial ? '' : template.toString(),
'template': { 'template': {
'body': body, 'body': body,
'subject': subject, 'subject': subject,

View File

@ -30,6 +30,7 @@ class EditInvoice implements PersistUI {
class ShowEmailInvoice { class ShowEmailInvoice {
final InvoiceEntity invoice; final InvoiceEntity invoice;
final BuildContext context; final BuildContext context;
ShowEmailInvoice({this.invoice, this.context}); ShowEmailInvoice({this.invoice, this.context});
//final Completer completer; //final Completer completer;
@ -163,10 +164,12 @@ class SaveInvoiceFailure implements StopSaving {
class EmailInvoiceRequest implements StartSaving { class EmailInvoiceRequest implements StartSaving {
final Completer completer; final Completer completer;
final int invoiceId; final int invoiceId;
final EmailTemplate template;
final String subject; final String subject;
final String body; final String body;
EmailInvoiceRequest({this.completer, this.invoiceId, this.subject, this.body}); EmailInvoiceRequest(
{this.completer, this.invoiceId, this.template, this.subject, this.body});
} }
class EmailInvoiceSuccess implements StopSaving, PersistData {} class EmailInvoiceSuccess implements StopSaving, PersistData {}

View File

@ -192,7 +192,7 @@ Middleware<AppState> _emailInvoice(InvoiceRepository repository) {
final origInvoice = store.state.invoiceState.map[action.invoiceId]; final origInvoice = store.state.invoiceState.map[action.invoiceId];
repository repository
.emailInvoice(store.state.selectedCompany, store.state.authState, .emailInvoice(store.state.selectedCompany, store.state.authState,
origInvoice, action.subject, action.body) origInvoice, action.template, action.subject, action.body)
.then((void _) { .then((void _) {
store.dispatch(EmailInvoiceSuccess()); store.dispatch(EmailInvoiceSuccess());
store.dispatch(LoadClient(clientId: origInvoice.clientId)); store.dispatch(LoadClient(clientId: origInvoice.clientId));

View File

@ -248,7 +248,8 @@ class _InvoiceEmailViewState extends State<InvoiceEmailView> {
IconButton( IconButton(
tooltip: localization.send, tooltip: localization.send,
icon: Icon(Icons.send), icon: Icon(Icons.send),
onPressed: () => viewModel.onSendPressed(emailSubject, emailBody), onPressed: () => viewModel.onSendPressed(
selectedTemplate, emailSubject, emailBody),
) )
], ],
), ),

View File

@ -42,7 +42,7 @@ class EmailInvoiceDialogVM {
final CompanyEntity company; final CompanyEntity company;
final InvoiceEntity invoice; final InvoiceEntity invoice;
final ClientEntity client; final ClientEntity client;
final Function(String, String) onSendPressed; final Function(EmailTemplate, String, String) onSendPressed;
//final List<ContactEntity> recipients; //final List<ContactEntity> recipients;
@ -62,8 +62,9 @@ class EmailInvoiceDialogVM {
company: state.selectedCompany, company: state.selectedCompany,
invoice: invoice, invoice: invoice,
client: state.clientState.map[invoice.clientId], client: state.clientState.map[invoice.clientId],
onSendPressed: (subject, body) => store.dispatch(EmailInvoiceRequest( onSendPressed: (template, subject, body) => store.dispatch(EmailInvoiceRequest(
invoiceId: invoice.id, invoiceId: invoice.id,
template: template,
subject: subject, subject: subject,
body: body, body: body,
)) ))