This commit is contained in:
Hillel Coren 2019-11-06 20:52:31 +02:00
parent 55fe33559d
commit b7c0a5bdaf
14 changed files with 32 additions and 61 deletions

View File

@ -39,7 +39,6 @@ class ClientPortalVM {
@required this.onCompanyChanged, @required this.onCompanyChanged,
@required this.onSettingsChanged, @required this.onSettingsChanged,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onCancelPressed,
}); });
static ClientPortalVM fromStore(Store<AppState> store) { static ClientPortalVM fromStore(Store<AppState> store) {
@ -53,7 +52,6 @@ class ClientPortalVM {
store.dispatch(UpdateSettings(settings: settings)), store.dispatch(UpdateSettings(settings: settings)),
onCompanyChanged: (company) => onCompanyChanged: (company) =>
store.dispatch(UpdateCompany(company: company)), store.dispatch(UpdateCompany(company: company)),
onCancelPressed: (context) => store.dispatch(ResetSettings()),
onSavePressed: (context) { onSavePressed: (context) {
final settingsUIState = state.uiState.settingsUIState; final settingsUIState = state.uiState.settingsUIState;
final completer = snackBarCompleter( final completer = snackBarCompleter(
@ -81,7 +79,6 @@ class ClientPortalVM {
final CompanyEntity company; final CompanyEntity company;
final SettingsEntity settings; final SettingsEntity settings;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(BuildContext) onCancelPressed;
final Function(CompanyEntity) onCompanyChanged; final Function(CompanyEntity) onCompanyChanged;
final Function(SettingsEntity) onSettingsChanged; final Function(SettingsEntity) onSettingsChanged;
} }

View File

@ -12,6 +12,7 @@ import 'package:invoiceninja_flutter/ui/app/forms/decorated_form_field.dart';
import 'package:invoiceninja_flutter/ui/app/resources/cached_image.dart'; import 'package:invoiceninja_flutter/ui/app/resources/cached_image.dart';
import 'package:invoiceninja_flutter/ui/settings/company_details_vm.dart'; import 'package:invoiceninja_flutter/ui/settings/company_details_vm.dart';
import 'package:invoiceninja_flutter/ui/settings/settings_scaffold.dart'; import 'package:invoiceninja_flutter/ui/settings/settings_scaffold.dart';
import 'package:invoiceninja_flutter/utils/completers.dart';
import 'package:invoiceninja_flutter/utils/formatting.dart'; import 'package:invoiceninja_flutter/utils/formatting.dart';
import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/utils/localization.dart';
@ -34,6 +35,7 @@ class _CompanyDetailsState extends State<CompanyDetails>
final FocusScopeNode _focusNode = FocusScopeNode(); final FocusScopeNode _focusNode = FocusScopeNode();
TabController _controller; TabController _controller;
bool autoValidate = false; bool autoValidate = false;
final _debouncer = Debouncer();
final _nameController = TextEditingController(); final _nameController = TextEditingController();
final _idNumberController = TextEditingController(); final _idNumberController = TextEditingController();
@ -139,31 +141,33 @@ class _CompanyDetailsState extends State<CompanyDetails>
} }
void _onSettingsChanged() { void _onSettingsChanged() {
final settings = widget.viewModel.settings.rebuild((b) => b _debouncer.run(() {
..name = _nameController.text.trim() final settings = widget.viewModel.settings.rebuild((b) => b
..idNumber = _idNumberController.text.trim() ..name = _nameController.text.trim()
..vatNumber = _vatNumberController.text.trim() ..idNumber = _idNumberController.text.trim()
..phone = _phoneController.text.trim() ..vatNumber = _vatNumberController.text.trim()
..email = _emailController.text.trim() ..phone = _phoneController.text.trim()
..website = _websiteController.text.trim() ..email = _emailController.text.trim()
..address1 = _address1Controller.text.trim() ..website = _websiteController.text.trim()
..address2 = _address2Controller.text.trim() ..address1 = _address1Controller.text.trim()
..city = _cityController.text.trim() ..address2 = _address2Controller.text.trim()
..state = _stateController.text.trim() ..city = _cityController.text.trim()
..postalCode = _postalCodeController.text.trim() ..state = _stateController.text.trim()
..defaultTaskRate = parseDouble(_taskRateController.text) ?? 0 ..postalCode = _postalCodeController.text.trim()
..defaultPaymentTerms = int.tryParse(_paymentTermsController.text) ?? 0 ..defaultTaskRate = parseDouble(_taskRateController.text) ?? 0
..customValue1 = _custom1Controller.text.trim() ..defaultPaymentTerms = int.tryParse(_paymentTermsController.text) ?? 0
..customValue2 = _custom2Controller.text.trim() ..customValue1 = _custom1Controller.text.trim()
..customValue3 = _custom3Controller.text.trim() ..customValue2 = _custom2Controller.text.trim()
..customValue4 = _custom4Controller.text.trim() ..customValue3 = _custom3Controller.text.trim()
..defaultInvoiceFooter = _invoiceFooterController.text.trim() ..customValue4 = _custom4Controller.text.trim()
..defaultInvoiceTerms = _invoiceTermsController.text.trim() ..defaultInvoiceFooter = _invoiceFooterController.text.trim()
..defaultQuoteFooter = _quoteFooterController.text.trim() ..defaultInvoiceTerms = _invoiceTermsController.text.trim()
..defaultQuoteTerms = _quoteTermsController.text.trim()); ..defaultQuoteFooter = _quoteFooterController.text.trim()
if (settings != widget.viewModel.settings) { ..defaultQuoteTerms = _quoteTermsController.text.trim());
widget.viewModel.onSettingsChanged(settings); if (settings != widget.viewModel.settings) {
} widget.viewModel.onSettingsChanged(settings);
}
});
} }
@override @override

View File

@ -38,7 +38,6 @@ class CompanyDetailsVM {
@required this.onCompanyChanged, @required this.onCompanyChanged,
@required this.onSettingsChanged, @required this.onSettingsChanged,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onCancelPressed,
@required this.onUploadLogo, @required this.onUploadLogo,
}); });
@ -53,7 +52,6 @@ class CompanyDetailsVM {
store.dispatch(UpdateSettings(settings: settings)), store.dispatch(UpdateSettings(settings: settings)),
onCompanyChanged: (company) => onCompanyChanged: (company) =>
store.dispatch(UpdateCompany(company: company)), store.dispatch(UpdateCompany(company: company)),
onCancelPressed: (context) => store.dispatch(ResetSettings()),
onSavePressed: (context) { onSavePressed: (context) {
final settingsUIState = state.uiState.settingsUIState; final settingsUIState = state.uiState.settingsUIState;
final completer = snackBarCompleter( final completer = snackBarCompleter(
@ -89,6 +87,5 @@ class CompanyDetailsVM {
final Function(SettingsEntity) onSettingsChanged; final Function(SettingsEntity) onSettingsChanged;
final Function(CompanyEntity) onCompanyChanged; final Function(CompanyEntity) onCompanyChanged;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(BuildContext) onCancelPressed;
final Function(BuildContext, String) onUploadLogo; final Function(BuildContext, String) onUploadLogo;
} }

View File

@ -35,7 +35,6 @@ class CustomFieldsVM {
CustomFieldsVM({ CustomFieldsVM({
@required this.state, @required this.state,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onCancelPressed,
@required this.company, @required this.company,
@required this.onCompanyChanged, @required this.onCompanyChanged,
}); });
@ -48,7 +47,6 @@ class CustomFieldsVM {
company: state.uiState.settingsUIState.userCompany.company, company: state.uiState.settingsUIState.userCompany.company,
onCompanyChanged: (company) => onCompanyChanged: (company) =>
store.dispatch(UpdateCompany(company: company)), store.dispatch(UpdateCompany(company: company)),
onCancelPressed: (context) => store.dispatch(ResetSettings()),
onSavePressed: (context) { onSavePressed: (context) {
final settingsUIState = state.uiState.settingsUIState; final settingsUIState = state.uiState.settingsUIState;
final completer = snackBarCompleter( final completer = snackBarCompleter(
@ -73,7 +71,6 @@ class CustomFieldsVM {
final AppState state; final AppState state;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(BuildContext) onCancelPressed;
final CompanyEntity company; final CompanyEntity company;
final Function(CompanyEntity) onCompanyChanged; final Function(CompanyEntity) onCompanyChanged;
} }

View File

@ -37,7 +37,6 @@ class EmailSettingsVM {
@required this.settings, @required this.settings,
@required this.onSettingsChanged, @required this.onSettingsChanged,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onCancelPressed,
}); });
static EmailSettingsVM fromStore(Store<AppState> store) { static EmailSettingsVM fromStore(Store<AppState> store) {
@ -49,7 +48,6 @@ class EmailSettingsVM {
onSettingsChanged: (settings) { onSettingsChanged: (settings) {
store.dispatch(UpdateSettings(settings: settings)); store.dispatch(UpdateSettings(settings: settings));
}, },
onCancelPressed: (context) => store.dispatch(ResetSettings()),
onSavePressed: (context) { onSavePressed: (context) {
final settingsUIState = state.uiState.settingsUIState; final settingsUIState = state.uiState.settingsUIState;
final completer = snackBarCompleter( final completer = snackBarCompleter(
@ -74,7 +72,6 @@ class EmailSettingsVM {
final AppState state; final AppState state;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(BuildContext) onCancelPressed;
final SettingsEntity settings; final SettingsEntity settings;
final Function(SettingsEntity) onSettingsChanged; final Function(SettingsEntity) onSettingsChanged;
} }

View File

@ -35,7 +35,6 @@ class GeneratedNumbersVM {
GeneratedNumbersVM({ GeneratedNumbersVM({
@required this.state, @required this.state,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onCancelPressed,
@required this.settings, @required this.settings,
@required this.onSettingsChanged, @required this.onSettingsChanged,
@required this.company, @required this.company,
@ -54,7 +53,6 @@ class GeneratedNumbersVM {
onSettingsChanged: (settings) { onSettingsChanged: (settings) {
store.dispatch(UpdateSettings(settings: settings)); store.dispatch(UpdateSettings(settings: settings));
}, },
onCancelPressed: (context) => store.dispatch(ResetSettings()),
onSavePressed: (context) { onSavePressed: (context) {
final settingsUIState = state.uiState.settingsUIState; final settingsUIState = state.uiState.settingsUIState;
final completer = snackBarCompleter( final completer = snackBarCompleter(
@ -79,7 +77,6 @@ class GeneratedNumbersVM {
final AppState state; final AppState state;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(BuildContext) onCancelPressed;
final SettingsEntity settings; final SettingsEntity settings;
final Function(SettingsEntity) onSettingsChanged; final Function(SettingsEntity) onSettingsChanged;
final CompanyEntity company; final CompanyEntity company;

View File

@ -36,7 +36,6 @@ class InvoiceDesignVM {
@required this.state, @required this.state,
@required this.company, @required this.company,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onCancelPressed,
@required this.settings, @required this.settings,
@required this.onSettingsChanged, @required this.onSettingsChanged,
}); });
@ -51,7 +50,6 @@ class InvoiceDesignVM {
onSettingsChanged: (settings) { onSettingsChanged: (settings) {
store.dispatch(UpdateSettings(settings: settings)); store.dispatch(UpdateSettings(settings: settings));
}, },
onCancelPressed: (context) => store.dispatch(ResetSettings()),
onSavePressed: (context) { onSavePressed: (context) {
final settingsUIState = state.uiState.settingsUIState; final settingsUIState = state.uiState.settingsUIState;
final completer = snackBarCompleter( final completer = snackBarCompleter(
@ -79,5 +77,4 @@ class InvoiceDesignVM {
final CompanyEntity company; final CompanyEntity company;
final Function(SettingsEntity) onSettingsChanged; final Function(SettingsEntity) onSettingsChanged;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(BuildContext) onCancelPressed;
} }

View File

@ -39,7 +39,6 @@ class LocalizationSettingsVM {
@required this.onSettingsChanged, @required this.onSettingsChanged,
@required this.onCompanyChanged, @required this.onCompanyChanged,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onCancelPressed,
}); });
static LocalizationSettingsVM fromStore(Store<AppState> store) { static LocalizationSettingsVM fromStore(Store<AppState> store) {
@ -54,7 +53,6 @@ class LocalizationSettingsVM {
}, },
onCompanyChanged: (company) => onCompanyChanged: (company) =>
store.dispatch(UpdateCompany(company: company)), store.dispatch(UpdateCompany(company: company)),
onCancelPressed: (context) => store.dispatch(ResetSettings()),
onSavePressed: (context) { onSavePressed: (context) {
final settingsUIState = state.uiState.settingsUIState; final settingsUIState = state.uiState.settingsUIState;
final completer = snackBarCompleter( final completer = snackBarCompleter(
@ -83,5 +81,4 @@ class LocalizationSettingsVM {
final SettingsEntity settings; final SettingsEntity settings;
final Function(SettingsEntity) onSettingsChanged; final Function(SettingsEntity) onSettingsChanged;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(BuildContext) onCancelPressed;
} }

View File

@ -34,7 +34,6 @@ class ProductSettingsVM {
@required this.company, @required this.company,
@required this.onCompanyChanged, @required this.onCompanyChanged,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onCancelPressed,
}); });
static ProductSettingsVM fromStore(Store<AppState> store) { static ProductSettingsVM fromStore(Store<AppState> store) {
@ -45,7 +44,6 @@ class ProductSettingsVM {
company: state.uiState.settingsUIState.userCompany.company, company: state.uiState.settingsUIState.userCompany.company,
onCompanyChanged: (company) => onCompanyChanged: (company) =>
store.dispatch(UpdateCompany(company: company)), store.dispatch(UpdateCompany(company: company)),
onCancelPressed: (context) => store.dispatch(ResetSettings()),
onSavePressed: (context) { onSavePressed: (context) {
final settingsUIState = state.uiState.settingsUIState; final settingsUIState = state.uiState.settingsUIState;
final completer = snackBarCompleter( final completer = snackBarCompleter(
@ -58,7 +56,6 @@ class ProductSettingsVM {
final AppState state; final AppState state;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(BuildContext) onCancelPressed;
final CompanyEntity company; final CompanyEntity company;
final Function(CompanyEntity) onCompanyChanged; final Function(CompanyEntity) onCompanyChanged;
} }

View File

@ -44,6 +44,8 @@ class SettingsScaffold extends StatelessWidget {
style: TextStyle(color: Colors.white), style: TextStyle(color: Colors.white),
), ),
onPressed: () { onPressed: () {
store.dispatch(ResetSettings());
/*
FocusScope.of(context).requestFocus(FocusNode()); FocusScope.of(context).requestFocus(FocusNode());
store.dispatch(ViewSettings( store.dispatch(ViewSettings(
context: context, context: context,
@ -51,6 +53,7 @@ class SettingsScaffold extends StatelessWidget {
section: state.uiState.previousSubRoute, section: state.uiState.previousSubRoute,
force: true, force: true,
)); ));
*/
}, },
); );
}), }),

View File

@ -36,7 +36,6 @@ class TaxSettingsVM {
@required this.onSettingsChanged, @required this.onSettingsChanged,
@required this.onCompanyChanged, @required this.onCompanyChanged,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onCancelPressed,
@required this.onConfigureRatesPressed, @required this.onConfigureRatesPressed,
}); });
@ -52,7 +51,6 @@ class TaxSettingsVM {
}, },
onCompanyChanged: (company) => onCompanyChanged: (company) =>
store.dispatch(UpdateCompany(company: company)), store.dispatch(UpdateCompany(company: company)),
onCancelPressed: (context) => store.dispatch(ResetSettings()),
onSavePressed: (context) { onSavePressed: (context) {
final settingsUIState = state.uiState.settingsUIState; final settingsUIState = state.uiState.settingsUIState;
final completer = snackBarCompleter( final completer = snackBarCompleter(
@ -74,7 +72,6 @@ class TaxSettingsVM {
final AppState state; final AppState state;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(BuildContext) onCancelPressed;
final SettingsEntity settings; final SettingsEntity settings;
final Function(SettingsEntity) onSettingsChanged; final Function(SettingsEntity) onSettingsChanged;
final CompanyEntity company; final CompanyEntity company;

View File

@ -37,7 +37,6 @@ class TemplatesAndRemindersVM {
@required this.settings, @required this.settings,
@required this.onSettingsChanged, @required this.onSettingsChanged,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onCancelPressed,
@required this.loadTemplate, @required this.loadTemplate,
}); });
@ -50,7 +49,6 @@ class TemplatesAndRemindersVM {
onSettingsChanged: (settings) { onSettingsChanged: (settings) {
store.dispatch(UpdateSettings(settings: settings)); store.dispatch(UpdateSettings(settings: settings));
}, },
onCancelPressed: (context) => store.dispatch(ResetSettings()),
onSavePressed: (context) { onSavePressed: (context) {
final settingsUIState = state.uiState.settingsUIState; final settingsUIState = state.uiState.settingsUIState;
final completer = snackBarCompleter( final completer = snackBarCompleter(
@ -88,5 +86,4 @@ class TemplatesAndRemindersVM {
final Function(String) loadTemplate; final Function(String) loadTemplate;
final Function(SettingsEntity) onSettingsChanged; final Function(SettingsEntity) onSettingsChanged;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(BuildContext) onCancelPressed;
} }

View File

@ -33,7 +33,6 @@ class UserDetailsVM {
@required this.state, @required this.state,
@required this.onChanged, @required this.onChanged,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onCancelPressed,
}); });
static UserDetailsVM fromStore(Store<AppState> store) { static UserDetailsVM fromStore(Store<AppState> store) {
@ -43,7 +42,6 @@ class UserDetailsVM {
state: state, state: state,
user: state.uiState.settingsUIState.userCompany.user, user: state.uiState.settingsUIState.userCompany.user,
onChanged: (user) => store.dispatch(UpdateUser(user: user)), onChanged: (user) => store.dispatch(UpdateUser(user: user)),
onCancelPressed: (context) => store.dispatch(ResetSettings()),
onSavePressed: (context) { onSavePressed: (context) {
final completer = snackBarCompleter( final completer = snackBarCompleter(
context, AppLocalization.of(context).savedSettings); context, AppLocalization.of(context).savedSettings);
@ -57,5 +55,4 @@ class UserDetailsVM {
final UserEntity user; final UserEntity user;
final Function(UserEntity) onChanged; final Function(UserEntity) onChanged;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(BuildContext) onCancelPressed;
} }

View File

@ -37,7 +37,6 @@ class WorkflowSettingsVM {
@required this.settings, @required this.settings,
@required this.onSettingsChanged, @required this.onSettingsChanged,
@required this.onSavePressed, @required this.onSavePressed,
@required this.onCancelPressed,
}); });
static WorkflowSettingsVM fromStore(Store<AppState> store) { static WorkflowSettingsVM fromStore(Store<AppState> store) {
@ -49,7 +48,6 @@ class WorkflowSettingsVM {
onSettingsChanged: (settings) { onSettingsChanged: (settings) {
store.dispatch(UpdateSettings(settings: settings)); store.dispatch(UpdateSettings(settings: settings));
}, },
onCancelPressed: (context) => store.dispatch(ResetSettings()),
onSavePressed: (context) { onSavePressed: (context) {
final settingsUIState = state.uiState.settingsUIState; final settingsUIState = state.uiState.settingsUIState;
final completer = snackBarCompleter( final completer = snackBarCompleter(
@ -74,7 +72,6 @@ class WorkflowSettingsVM {
final AppState state; final AppState state;
final Function(BuildContext) onSavePressed; final Function(BuildContext) onSavePressed;
final Function(BuildContext) onCancelPressed;
final SettingsEntity settings; final SettingsEntity settings;
final Function(SettingsEntity) onSettingsChanged; final Function(SettingsEntity) onSettingsChanged;
} }