From ce4e01cead6b827350599479501bc3689c809b1c Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 30 May 2023 17:52:37 +0300 Subject: [PATCH] Choose template to use when emailing multiple invoices at once #472 --- lib/redux/invoice/invoice_actions.dart | 52 ++++++++++++++++++++++++++ lib/utils/i18n.dart | 5 +++ 2 files changed, 57 insertions(+) diff --git a/lib/redux/invoice/invoice_actions.dart b/lib/redux/invoice/invoice_actions.dart index c43d52580..1846ed24c 100644 --- a/lib/redux/invoice/invoice_actions.dart +++ b/lib/redux/invoice/invoice_actions.dart @@ -10,6 +10,8 @@ import 'package:built_collection/built_collection.dart'; import 'package:flutter_redux/flutter_redux.dart'; import 'package:http/http.dart'; import 'package:invoiceninja_flutter/constants.dart'; +import 'package:invoiceninja_flutter/main_app.dart'; +import 'package:invoiceninja_flutter/redux/client/client_selectors.dart'; import 'package:invoiceninja_flutter/redux/document/document_actions.dart'; import 'package:invoiceninja_flutter/redux/settings/settings_actions.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -677,6 +679,56 @@ void handleInvoiceAction(BuildContext context, List invoices, invoiceIds: invoiceIds, )); }); + + if (false) { + final template = await showDialog( + context: context, + builder: (context) { + final settings = getClientSettings(state, client); + final templates = { + EmailTemplate.invoice: localization.initialEmail, + EmailTemplate.reminder1: localization.firstReminder, + EmailTemplate.reminder2: localization.secondReminder, + EmailTemplate.reminder3: localization.thirdReminder, + EmailTemplate.reminder_endless: localization.endlessReminder, + if ((settings.emailSubjectCustom1 ?? '').isNotEmpty) + EmailTemplate.custom1: localization.firstCustom, + if ((settings.emailSubjectCustom2 ?? '').isNotEmpty) + EmailTemplate.custom2: localization.secondCustom, + if ((settings.emailSubjectCustom3 ?? '').isNotEmpty) + EmailTemplate.custom3: localization.thirdCustom, + }; + return SimpleDialog( + title: Text( + invoiceIds.length == 1 + ? localization.sendEmail + : localization.sendCountEmails + .replaceFirst(':count', '${invoiceIds.length}'), + ), + children: templates.keys + .map((template) => SimpleDialogOption( + child: Text(templates[template]), + onPressed: () { + Navigator.of(context).pop(template); + }, + )) + .toList(), + ); + }, + ); + + if (template != null) { + store.dispatch(BulkEmailInvoicesRequest( + completer: snackBarCompleter( + navigatorKey.currentContext, + invoiceIds.length == 1 + ? localization.emailedInvoice + : localization.emailedInvoices), + invoiceIds: invoiceIds, + template: template, + )); + } + } } break; case EntityAction.cloneToOther: diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index f9a022c2d..4b73c6aa2 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -18,6 +18,7 @@ mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { // STARTER: lang key - do not remove comment + 'send_count_emails': 'Send :count emails', 'location': 'Location', 'invoice_task_item_description': 'Invoice Task Item Description', 'invoice_task_item_description_help': @@ -102521,6 +102522,10 @@ mixin LocalizationsProvider on LocaleCodeAware { _localizedValues[localeCode]['location'] ?? _localizedValues['en']['location']; + String get sendCountEmails => + _localizedValues[localeCode]['send_count_emails'] ?? + _localizedValues['en']['send_count_emails']; + // STARTER: lang field - do not remove comment String lookup(String key) {