Code refactor
This commit is contained in:
parent
349875096e
commit
01c3093747
|
|
@ -115,6 +115,20 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
||||||
|
|
||||||
CompanyEntity get company => userCompanyState.company;
|
CompanyEntity get company => userCompanyState.company;
|
||||||
|
|
||||||
|
List<CompanyEntity> get companies {
|
||||||
|
final List<CompanyEntity> list = [];
|
||||||
|
|
||||||
|
for (var companyState in userCompanyStates) {
|
||||||
|
if (companyState.company != null) {
|
||||||
|
list.add(companyState.company);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list
|
||||||
|
.where((CompanyEntity company) => (company.id ?? '').isNotEmpty)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
DashboardUIState get dashboardUIState => uiState.dashboardUIState;
|
DashboardUIState get dashboardUIState => uiState.dashboardUIState;
|
||||||
|
|
||||||
UserEntity get user => userCompanyState.user;
|
UserEntity get user => userCompanyState.user;
|
||||||
|
|
|
||||||
|
|
@ -245,8 +245,7 @@ Middleware<AppState> _createCompany(AuthRepository repository) {
|
||||||
store.dispatch(RefreshData(
|
store.dispatch(RefreshData(
|
||||||
completer: Completer<Null>()
|
completer: Completer<Null>()
|
||||||
..future.then<Null>((_) {
|
..future.then<Null>((_) {
|
||||||
final companies = companiesSelector(state);
|
store.dispatch(SelectCompany(state.companies.length));
|
||||||
store.dispatch(SelectCompany(companies.length));
|
|
||||||
store.dispatch(ViewDashboard(
|
store.dispatch(ViewDashboard(
|
||||||
navigator: Navigator.of(action.context), force: true));
|
navigator: Navigator.of(action.context), force: true));
|
||||||
store.dispatch(LoadClients());
|
store.dispatch(LoadClients());
|
||||||
|
|
|
||||||
|
|
@ -114,20 +114,6 @@ List<BaseEntity> filteredSelector(String filter, UserCompanyState state) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CompanyEntity> companiesSelector(AppState state) {
|
|
||||||
final List<CompanyEntity> list = [];
|
|
||||||
|
|
||||||
for (var companyState in state.userCompanyStates) {
|
|
||||||
if (companyState.company != null) {
|
|
||||||
list.add(companyState.company);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list
|
|
||||||
.where((CompanyEntity company) => (company.id ?? '').isNotEmpty)
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
String localeSelector(AppState state) {
|
String localeSelector(AppState state) {
|
||||||
final locale = state.staticState
|
final locale = state.staticState
|
||||||
?.languageMap[state.company?.settings?.languageId]?.locale ??
|
?.languageMap[state.company?.settings?.languageId]?.locale ??
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class AppDrawerVM {
|
||||||
|
|
||||||
return AppDrawerVM(
|
return AppDrawerVM(
|
||||||
isLoading: state.isLoading,
|
isLoading: state.isLoading,
|
||||||
companies: companiesSelector(state),
|
companies: state.companies,
|
||||||
user: state.user,
|
user: state.user,
|
||||||
selectedCompany: state.company,
|
selectedCompany: state.company,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ class MenuDrawer extends StatelessWidget {
|
||||||
child: _companyLogo(viewModel.selectedCompany),
|
child: _companyLogo(viewModel.selectedCompany),
|
||||||
),
|
),
|
||||||
itemBuilder: (BuildContext context) => [
|
itemBuilder: (BuildContext context) => [
|
||||||
...viewModel.companies
|
...viewModel.state.companies
|
||||||
.map((company) => PopupMenuItem<String>(
|
.map((company) => PopupMenuItem<String>(
|
||||||
child: _companyListItem(company),
|
child: _companyListItem(company),
|
||||||
value: company.id,
|
value: company.id,
|
||||||
|
|
@ -124,15 +124,15 @@ class MenuDrawer extends StatelessWidget {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
final _expandedCompanySelector = viewModel.companies.isEmpty
|
final _expandedCompanySelector = state.companies.isEmpty
|
||||||
? SizedBox()
|
? SizedBox()
|
||||||
: AppDropdownButton<String>(
|
: AppDropdownButton<String>(
|
||||||
value: viewModel.selectedCompanyIndex,
|
value: viewModel.selectedCompanyIndex,
|
||||||
items: [
|
items: [
|
||||||
...viewModel.companies
|
...state.companies
|
||||||
.map((CompanyEntity company) => DropdownMenuItem<String>(
|
.map((CompanyEntity company) => DropdownMenuItem<String>(
|
||||||
value:
|
value:
|
||||||
(viewModel.companies.indexOf(company)).toString(),
|
(state.companies.indexOf(company)).toString(),
|
||||||
child: _companyListItem(company),
|
child: _companyListItem(company),
|
||||||
))
|
))
|
||||||
.toList(),
|
.toList(),
|
||||||
|
|
@ -154,7 +154,7 @@ class MenuDrawer extends StatelessWidget {
|
||||||
viewModel.onAddCompany(context);
|
viewModel.onAddCompany(context);
|
||||||
} else {
|
} else {
|
||||||
viewModel.onCompanyChanged(
|
viewModel.onCompanyChanged(
|
||||||
context, value, viewModel.companies[int.parse(value)]);
|
context, value, state.companies[int.parse(value)]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ class MenuDrawerBuilder extends StatelessWidget {
|
||||||
class MenuDrawerVM {
|
class MenuDrawerVM {
|
||||||
MenuDrawerVM({
|
MenuDrawerVM({
|
||||||
@required this.state,
|
@required this.state,
|
||||||
@required this.companies,
|
|
||||||
@required this.selectedCompany,
|
@required this.selectedCompany,
|
||||||
@required this.user,
|
@required this.user,
|
||||||
@required this.selectedCompanyIndex,
|
@required this.selectedCompanyIndex,
|
||||||
|
|
@ -41,7 +40,6 @@ class MenuDrawerVM {
|
||||||
});
|
});
|
||||||
|
|
||||||
final AppState state;
|
final AppState state;
|
||||||
final List<CompanyEntity> companies;
|
|
||||||
final CompanyEntity selectedCompany;
|
final CompanyEntity selectedCompany;
|
||||||
final UserEntity user;
|
final UserEntity user;
|
||||||
final String selectedCompanyIndex;
|
final String selectedCompanyIndex;
|
||||||
|
|
@ -56,7 +54,6 @@ class MenuDrawerVM {
|
||||||
return MenuDrawerVM(
|
return MenuDrawerVM(
|
||||||
state: state,
|
state: state,
|
||||||
isLoading: state.isLoading,
|
isLoading: state.isLoading,
|
||||||
companies: companiesSelector(state),
|
|
||||||
user: state.user,
|
user: state.user,
|
||||||
selectedCompany: state.company,
|
selectedCompany: state.company,
|
||||||
selectedCompanyIndex: state.uiState.selectedCompanyIndex.toString(),
|
selectedCompanyIndex: state.uiState.selectedCompanyIndex.toString(),
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class _AccountManagementState extends State<AccountManagement>
|
||||||
final viewModel = widget.viewModel;
|
final viewModel = widget.viewModel;
|
||||||
final state = viewModel.state;
|
final state = viewModel.state;
|
||||||
final company = viewModel.company;
|
final company = viewModel.company;
|
||||||
final companies = companiesSelector(state);
|
final companies = state.companies;
|
||||||
|
|
||||||
return EditScaffold(
|
return EditScaffold(
|
||||||
title: localization.accountManagement,
|
title: localization.accountManagement,
|
||||||
|
|
@ -100,11 +100,11 @@ class _AccountManagementState extends State<AccountManagement>
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(14),
|
padding: const EdgeInsets.all(16),
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
label: companies.length == 1
|
label: companies.length == 1
|
||||||
? localization.cancelAccount
|
? localization.cancelAccount.toUpperCase()
|
||||||
: localization.deleteCompany,
|
: localization.deleteCompany.toUpperCase(),
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
confirmCallback(
|
confirmCallback(
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class AccountManagementVM {
|
||||||
final selectedCompanyIndex = state.uiState.selectedCompanyIndex;
|
final selectedCompanyIndex = state.uiState.selectedCompanyIndex;
|
||||||
final completer = Completer<Null>()
|
final completer = Completer<Null>()
|
||||||
..future.then((value) {
|
..future.then((value) {
|
||||||
final companies = companiesSelector(state);
|
final companies = state.companies;
|
||||||
if (companies.length > 1) {
|
if (companies.length > 1) {
|
||||||
int index;
|
int index;
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:invoiceninja_flutter/constants.dart';
|
import 'package:invoiceninja_flutter/constants.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/entities.dart';
|
import 'package:invoiceninja_flutter/data/models/entities.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/design/design_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/static/static_selectors.dart';
|
import 'package:invoiceninja_flutter/redux/static/static_selectors.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/app/buttons/elevated_button.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/dialogs/multiselect_dialog.dart';
|
import 'package:invoiceninja_flutter/ui/app/dialogs/multiselect_dialog.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/entity_dropdown.dart';
|
import 'package:invoiceninja_flutter/ui/app/entity_dropdown.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/form_card.dart';
|
import 'package:invoiceninja_flutter/ui/app/form_card.dart';
|
||||||
|
|
@ -105,6 +107,14 @@ class _InvoiceDesignState extends State<InvoiceDesign>
|
||||||
ListView(children: <Widget>[
|
ListView(children: <Widget>[
|
||||||
FormCard(
|
FormCard(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: ElevatedButton(
|
||||||
|
label: localization.customDesigns.toUpperCase(),
|
||||||
|
iconData: Icons.settings,
|
||||||
|
//onPressed: () => handleDesignAction(context, [group], EntityAction.settings),
|
||||||
|
),
|
||||||
|
),
|
||||||
DesignPicker(
|
DesignPicker(
|
||||||
label: localization.invoiceDesign,
|
label: localization.invoiceDesign,
|
||||||
initialValue: settings.defaultInvoiceDesignId,
|
initialValue: settings.defaultInvoiceDesignId,
|
||||||
|
|
|
||||||
|
|
@ -143,11 +143,6 @@ class SettingsList extends StatelessWidget {
|
||||||
section: kSettingsCustomFields,
|
section: kSettingsCustomFields,
|
||||||
viewModel: viewModel,
|
viewModel: viewModel,
|
||||||
),
|
),
|
||||||
if (showAll)
|
|
||||||
SettingsListTile(
|
|
||||||
section: kSettingsCustomDesigns,
|
|
||||||
viewModel: viewModel,
|
|
||||||
),
|
|
||||||
SettingsListTile(
|
SettingsListTile(
|
||||||
section: kSettingsInvoiceDesign,
|
section: kSettingsInvoiceDesign,
|
||||||
viewModel: viewModel,
|
viewModel: viewModel,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue