From 263c053c86bbe7eb0832df6749baf1a28d42f06e Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 17 Oct 2019 15:35:48 +0300 Subject: [PATCH] Settings --- lib/data/models/company_gateway_model.dart | 5 ++ lib/data/models/company_gateway_model.g.dart | 64 +++++++++++++------ lib/redux/app/app_state.dart | 9 ++- .../company_gateway_reducer.dart | 15 +++++ .../company_gateway_list_vm.dart | 2 + .../edit/company_gateway_edit.dart | 47 +++++++++++++- lib/utils/i18n.dart | 22 +++++++ 7 files changed, 141 insertions(+), 23 deletions(-) diff --git a/lib/data/models/company_gateway_model.dart b/lib/data/models/company_gateway_model.dart index 935ac8916..47cb668d6 100644 --- a/lib/data/models/company_gateway_model.dart +++ b/lib/data/models/company_gateway_model.dart @@ -57,6 +57,7 @@ abstract class CompanyGatewayEntity extends Object updateDetails: true, customValue1: '', customValue2: '', + config: '', ); } @@ -82,12 +83,16 @@ abstract class CompanyGatewayEntity extends Object @BuiltValueField(wireName: 'update_details') bool get updateDetails; + @nullable @BuiltValueField(wireName: 'custom_value1') String get customValue1; + @nullable @BuiltValueField(wireName: 'custom_value2') String get customValue2; + String get config; + @override String get listDisplayName { return gateway.name; diff --git a/lib/data/models/company_gateway_model.g.dart b/lib/data/models/company_gateway_model.g.dart index 6f7a02661..01dc1ee9e 100644 --- a/lib/data/models/company_gateway_model.g.dart +++ b/lib/data/models/company_gateway_model.g.dart @@ -136,11 +136,8 @@ class _$CompanyGatewayEntitySerializer 'update_details', serializers.serialize(object.updateDetails, specifiedType: const FullType(bool)), - 'custom_value1', - serializers.serialize(object.customValue1, - specifiedType: const FullType(String)), - 'custom_value2', - serializers.serialize(object.customValue2, + 'config', + serializers.serialize(object.config, specifiedType: const FullType(String)), ]; if (object.gatewayId != null) { @@ -149,6 +146,18 @@ class _$CompanyGatewayEntitySerializer ..add(serializers.serialize(object.gatewayId, specifiedType: const FullType(String))); } + if (object.customValue1 != null) { + result + ..add('custom_value1') + ..add(serializers.serialize(object.customValue1, + specifiedType: const FullType(String))); + } + if (object.customValue2 != null) { + result + ..add('custom_value2') + ..add(serializers.serialize(object.customValue2, + specifiedType: const FullType(String))); + } if (object.isChanged != null) { result ..add('isChanged') @@ -234,6 +243,10 @@ class _$CompanyGatewayEntitySerializer result.customValue2 = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; + case 'config': + result.config = serializers.deserialize(value, + specifiedType: const FullType(String)) as String; + break; case 'isChanged': result.isChanged = serializers.deserialize(value, specifiedType: const FullType(bool)) as bool; @@ -477,6 +490,8 @@ class _$CompanyGatewayEntity extends CompanyGatewayEntity { @override final String customValue2; @override + final String config; + @override final bool isChanged; @override final int createdAt; @@ -503,6 +518,7 @@ class _$CompanyGatewayEntity extends CompanyGatewayEntity { this.updateDetails, this.customValue1, this.customValue2, + this.config, this.isChanged, this.createdAt, this.updatedAt, @@ -526,13 +542,8 @@ class _$CompanyGatewayEntity extends CompanyGatewayEntity { throw new BuiltValueNullFieldError( 'CompanyGatewayEntity', 'updateDetails'); } - if (customValue1 == null) { - throw new BuiltValueNullFieldError( - 'CompanyGatewayEntity', 'customValue1'); - } - if (customValue2 == null) { - throw new BuiltValueNullFieldError( - 'CompanyGatewayEntity', 'customValue2'); + if (config == null) { + throw new BuiltValueNullFieldError('CompanyGatewayEntity', 'config'); } } @@ -556,6 +567,7 @@ class _$CompanyGatewayEntity extends CompanyGatewayEntity { updateDetails == other.updateDetails && customValue1 == other.customValue1 && customValue2 == other.customValue2 && + config == other.config && isChanged == other.isChanged && createdAt == other.createdAt && updatedAt == other.updatedAt && @@ -580,15 +592,20 @@ class _$CompanyGatewayEntity extends CompanyGatewayEntity { $jc( $jc( $jc( - $jc(0, - gateway.hashCode), - gatewayId.hashCode), - showBillingAddress + $jc( + $jc( + 0, + gateway + .hashCode), + gatewayId.hashCode), + showBillingAddress + .hashCode), + showShippingAddress .hashCode), - showShippingAddress.hashCode), - updateDetails.hashCode), - customValue1.hashCode), - customValue2.hashCode), + updateDetails.hashCode), + customValue1.hashCode), + customValue2.hashCode), + config.hashCode), isChanged.hashCode), createdAt.hashCode), updatedAt.hashCode), @@ -608,6 +625,7 @@ class _$CompanyGatewayEntity extends CompanyGatewayEntity { ..add('updateDetails', updateDetails) ..add('customValue1', customValue1) ..add('customValue2', customValue2) + ..add('config', config) ..add('isChanged', isChanged) ..add('createdAt', createdAt) ..add('updatedAt', updatedAt) @@ -655,6 +673,10 @@ class CompanyGatewayEntityBuilder String get customValue2 => _$this._customValue2; set customValue2(String customValue2) => _$this._customValue2 = customValue2; + String _config; + String get config => _$this._config; + set config(String config) => _$this._config = config; + bool _isChanged; bool get isChanged => _$this._isChanged; set isChanged(bool isChanged) => _$this._isChanged = isChanged; @@ -694,6 +716,7 @@ class CompanyGatewayEntityBuilder _updateDetails = _$v.updateDetails; _customValue1 = _$v.customValue1; _customValue2 = _$v.customValue2; + _config = _$v.config; _isChanged = _$v.isChanged; _createdAt = _$v.createdAt; _updatedAt = _$v.updatedAt; @@ -732,6 +755,7 @@ class CompanyGatewayEntityBuilder updateDetails: updateDetails, customValue1: customValue1, customValue2: customValue2, + config: config, isChanged: isChanged, createdAt: createdAt, updatedAt: updatedAt, diff --git a/lib/redux/app/app_state.dart b/lib/redux/app/app_state.dart index db7c951d7..c1234e5ae 100644 --- a/lib/redux/app/app_state.dart +++ b/lib/redux/app/app_state.dart @@ -32,6 +32,7 @@ import 'package:invoiceninja_flutter/ui/app/screen_imports.dart'; import 'package:invoiceninja_flutter/ui/client/edit/client_edit_vm.dart'; import 'package:invoiceninja_flutter/ui/group/edit/group_edit_vm.dart'; import 'package:invoiceninja_flutter/ui/product/edit/product_edit_vm.dart'; + // STARTER: import - do not remove comment import 'package:invoiceninja_flutter/redux/tax_rate/tax_rate_state.dart'; @@ -199,13 +200,17 @@ abstract class AppState implements Built { // STARTER: state getters - do not remove comment TaxRateState get taxRateState => selectedCompanyState.taxRateState; + ListUIState get taxRateListState => uiState.taxRateUIState.listUIState; + TaxRateUIState get taxRateUIState => uiState.taxRateUIState; CompanyGatewayState get companyGatewayState => selectedCompanyState.companyGatewayState; + ListUIState get companyGatewayListState => uiState.companyGatewayUIState.listUIState; + CompanyGatewayUIState get companyGatewayUIState => uiState.companyGatewayUIState; @@ -324,9 +329,9 @@ abstract class AppState implements Built { @override String toString() { //return 'showCurrencyCode: ${uiState.settingsUIState.settings.showCurrencyCode}'; - //return 'gateways : ${staticState.gatewayMap}'; + return 'gateways : ${selectedCompany.companyGateways}'; //return 'URL: ${userCompany.token.token}'; - return 'Route: ${uiState.currentRoute}, Setting Type: ${uiState.settingsUIState.entityType}, Name: ${uiState.settingsUIState.settings.name}, Updated: ${uiState.settingsUIState.updatedAt}'; + //return 'Route: ${uiState.currentRoute}, Setting Type: ${uiState.settingsUIState.entityType}, Name: ${uiState.settingsUIState.settings.name}, Updated: ${uiState.settingsUIState.updatedAt}'; //return 'Route: ${uiState.currentRoute}, Previous: ${uiState.previousRoute}, Layout: ${uiState.layout}, Menu: ${uiState.isMenuVisible}, History: ${uiState.isHistoryVisible}'; } } diff --git a/lib/redux/company_gateway/company_gateway_reducer.dart b/lib/redux/company_gateway/company_gateway_reducer.dart index 3c5ceb7e0..50e88b618 100644 --- a/lib/redux/company_gateway/company_gateway_reducer.dart +++ b/lib/redux/company_gateway/company_gateway_reducer.dart @@ -1,4 +1,5 @@ import 'package:invoiceninja_flutter/data/models/company_gateway_model.dart'; +import 'package:invoiceninja_flutter/redux/group/group_state.dart'; import 'package:redux/redux.dart'; import 'package:invoiceninja_flutter/redux/app/app_actions.dart'; import 'package:invoiceninja_flutter/redux/company/company_actions.dart'; @@ -130,6 +131,8 @@ final companyGatewaysReducer = combineReducers([ _setLoadedCompanyGateways), TypedReducer( _setLoadedCompanyGateway), + TypedReducer( + _setLoadedCompany), TypedReducer( _archiveCompanyGatewayRequest), TypedReducer( @@ -244,6 +247,18 @@ CompanyGatewayState _setLoadedCompanyGateway( .rebuild((b) => b..map[action.companyGateway.id] = action.companyGateway); } +CompanyGatewayState _setLoadedCompany(CompanyGatewayState companyGatewayState, LoadCompanySuccess action) { + final state = companyGatewayState.rebuild((b) => b + ..lastUpdated = DateTime.now().millisecondsSinceEpoch + ..map.addAll(Map.fromIterable( + action.userCompany.company.companyGateways, + key: (dynamic item) => item.id, + value: (dynamic item) => item, + ))); + + return state.rebuild((b) => b..list.replace(state.map.keys)); +} + CompanyGatewayState _setLoadedCompanyGateways( CompanyGatewayState companyGatewayState, LoadCompanyGatewaysSuccess action) { diff --git a/lib/ui/company_gateway/company_gateway_list_vm.dart b/lib/ui/company_gateway/company_gateway_list_vm.dart index 7b11ff26b..7c3222309 100644 --- a/lib/ui/company_gateway/company_gateway_list_vm.dart +++ b/lib/ui/company_gateway/company_gateway_list_vm.dart @@ -34,6 +34,7 @@ class CompanyGatewayListBuilder extends StatelessWidget { class CompanyGatewayListVM { CompanyGatewayListVM({ + @required this.state, @required this.userCompany, @required this.companyGatewayList, @required this.companyGatewayMap, @@ -89,6 +90,7 @@ class CompanyGatewayListVM { ); } + final AppState state; final UserCompanyEntity userCompany; final List companyGatewayList; final BuiltMap companyGatewayMap; diff --git a/lib/ui/company_gateway/edit/company_gateway_edit.dart b/lib/ui/company_gateway/edit/company_gateway_edit.dart index 66c02e33b..38c3ee112 100644 --- a/lib/ui/company_gateway/edit/company_gateway_edit.dart +++ b/lib/ui/company_gateway/edit/company_gateway_edit.dart @@ -35,7 +35,7 @@ class _CompanyGatewayEditState extends State @override void initState() { super.initState(); - _controller = TabController(vsync: this, length: 3); + _controller = TabController(vsync: this, length: 4); } @override @@ -88,6 +88,9 @@ class _CompanyGatewayEditState extends State key: ValueKey(state.settingsUIState.updatedAt), controller: _controller, tabs: [ + Tab( + text: localization.credentials, + ), Tab( text: localization.settings, ), @@ -132,6 +135,48 @@ class _CompanyGatewayEditState extends State ), ], ), + ListView( + children: [ + FormCard( + children: [ + SwitchListTile( + activeColor: Theme.of(context).accentColor, + title: Text(localization.billingAddress), + subtitle: Text(localization.requireBillingAddressHelp), + value: companyGateway.showBillingAddress, + onChanged: (value) => viewModel.onChanged(companyGateway + .rebuild((b) => b..showBillingAddress = value)), + ), + SwitchListTile( + activeColor: Theme.of(context).accentColor, + title: Text(localization.shippingAddress), + subtitle: Text(localization.requireShippingAddressHelp), + value: companyGateway.showShippingAddress, + onChanged: (value) => viewModel.onChanged(companyGateway + .rebuild((b) => b..showShippingAddress = value)), + ), + SwitchListTile( + activeColor: Theme.of(context).accentColor, + title: Text(localization.updateAddress), + subtitle: Text(localization.updateAddressHelp), + value: companyGateway.updateDetails, + onChanged: (value) => viewModel.onChanged(companyGateway + .rebuild((b) => b..updateDetails = value)), + ), + ], + ), + FormCard( + children: [ + SwitchListTile( + activeColor: Theme.of(context).accentColor, + //title: Text(), + value: false, + //onChanged: (value) => viewModel.onChanged(companyGateway.rebuild((b) => b..)), + ) + ], + ) + ], + ), ListView( children: [], ), diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index 38cd753b7..56f212d47 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -14,6 +14,13 @@ abstract class LocaleCodeAware { mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { + 'credentials': 'Credentials', + 'require_billing_address_help': + 'Require client to provide their billing address', + 'require_shipping_address_help': + 'Require client to provide their shipping address', + 'update_address': 'Update address', + 'update_address_help': 'Update client\'s address with provided details', 'rate': 'Rate', 'tax_rate': 'Tax Rate', 'new_tax_rate': 'New Tax Rate', @@ -14942,6 +14949,21 @@ mixin LocalizationsProvider on LocaleCodeAware { String get rate => _localizedValues[localeCode]['rate']; + String get requireBillingAddressHelp => + _localizedValues[localeCode]['require_billing_address_help']; + + String get requireShippingAddressHelp => + _localizedValues[localeCode]['require_shipping_address_help']; + + String get updateAddress => _localizedValues[localeCode]['update_address']; + + String get updateAddressHelp => + _localizedValues[localeCode]['update_address_help']; + + String get credentials => + _localizedValues[localeCode]['credentials']; + + String lookup(String key) { final lookupKey = toSnakeCase(key); return _localizedValues[localeCode][lookupKey] ??