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;
|
||||
|
||||
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;
|
||||
|
||||
UserEntity get user => userCompanyState.user;
|
||||
|
|
|
|||
|
|
@ -245,8 +245,7 @@ Middleware<AppState> _createCompany(AuthRepository repository) {
|
|||
store.dispatch(RefreshData(
|
||||
completer: Completer<Null>()
|
||||
..future.then<Null>((_) {
|
||||
final companies = companiesSelector(state);
|
||||
store.dispatch(SelectCompany(companies.length));
|
||||
store.dispatch(SelectCompany(state.companies.length));
|
||||
store.dispatch(ViewDashboard(
|
||||
navigator: Navigator.of(action.context), force: true));
|
||||
store.dispatch(LoadClients());
|
||||
|
|
|
|||
|
|
@ -114,20 +114,6 @@ List<BaseEntity> filteredSelector(String filter, UserCompanyState state) {
|
|||
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) {
|
||||
final locale = state.staticState
|
||||
?.languageMap[state.company?.settings?.languageId]?.locale ??
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class AppDrawerVM {
|
|||
|
||||
return AppDrawerVM(
|
||||
isLoading: state.isLoading,
|
||||
companies: companiesSelector(state),
|
||||
companies: state.companies,
|
||||
user: state.user,
|
||||
selectedCompany: state.company,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ class MenuDrawer extends StatelessWidget {
|
|||
child: _companyLogo(viewModel.selectedCompany),
|
||||
),
|
||||
itemBuilder: (BuildContext context) => [
|
||||
...viewModel.companies
|
||||
...viewModel.state.companies
|
||||
.map((company) => PopupMenuItem<String>(
|
||||
child: _companyListItem(company),
|
||||
value: company.id,
|
||||
|
|
@ -124,15 +124,15 @@ class MenuDrawer extends StatelessWidget {
|
|||
},
|
||||
);
|
||||
|
||||
final _expandedCompanySelector = viewModel.companies.isEmpty
|
||||
final _expandedCompanySelector = state.companies.isEmpty
|
||||
? SizedBox()
|
||||
: AppDropdownButton<String>(
|
||||
value: viewModel.selectedCompanyIndex,
|
||||
items: [
|
||||
...viewModel.companies
|
||||
...state.companies
|
||||
.map((CompanyEntity company) => DropdownMenuItem<String>(
|
||||
value:
|
||||
(viewModel.companies.indexOf(company)).toString(),
|
||||
(state.companies.indexOf(company)).toString(),
|
||||
child: _companyListItem(company),
|
||||
))
|
||||
.toList(),
|
||||
|
|
@ -154,7 +154,7 @@ class MenuDrawer extends StatelessWidget {
|
|||
viewModel.onAddCompany(context);
|
||||
} else {
|
||||
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 {
|
||||
MenuDrawerVM({
|
||||
@required this.state,
|
||||
@required this.companies,
|
||||
@required this.selectedCompany,
|
||||
@required this.user,
|
||||
@required this.selectedCompanyIndex,
|
||||
|
|
@ -41,7 +40,6 @@ class MenuDrawerVM {
|
|||
});
|
||||
|
||||
final AppState state;
|
||||
final List<CompanyEntity> companies;
|
||||
final CompanyEntity selectedCompany;
|
||||
final UserEntity user;
|
||||
final String selectedCompanyIndex;
|
||||
|
|
@ -56,7 +54,6 @@ class MenuDrawerVM {
|
|||
return MenuDrawerVM(
|
||||
state: state,
|
||||
isLoading: state.isLoading,
|
||||
companies: companiesSelector(state),
|
||||
user: state.user,
|
||||
selectedCompany: state.company,
|
||||
selectedCompanyIndex: state.uiState.selectedCompanyIndex.toString(),
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class _AccountManagementState extends State<AccountManagement>
|
|||
final viewModel = widget.viewModel;
|
||||
final state = viewModel.state;
|
||||
final company = viewModel.company;
|
||||
final companies = companiesSelector(state);
|
||||
final companies = state.companies;
|
||||
|
||||
return EditScaffold(
|
||||
title: localization.accountManagement,
|
||||
|
|
@ -100,11 +100,11 @@ class _AccountManagementState extends State<AccountManagement>
|
|||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ElevatedButton(
|
||||
label: companies.length == 1
|
||||
? localization.cancelAccount
|
||||
: localization.deleteCompany,
|
||||
? localization.cancelAccount.toUpperCase()
|
||||
: localization.deleteCompany.toUpperCase(),
|
||||
color: Colors.red,
|
||||
onPressed: () {
|
||||
confirmCallback(
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class AccountManagementVM {
|
|||
final selectedCompanyIndex = state.uiState.selectedCompanyIndex;
|
||||
final completer = Completer<Null>()
|
||||
..future.then((value) {
|
||||
final companies = companiesSelector(state);
|
||||
final companies = state.companies;
|
||||
if (companies.length > 1) {
|
||||
int index;
|
||||
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:invoiceninja_flutter/constants.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/ui/app/buttons/elevated_button.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/form_card.dart';
|
||||
|
|
@ -105,6 +107,14 @@ class _InvoiceDesignState extends State<InvoiceDesign>
|
|||
ListView(children: <Widget>[
|
||||
FormCard(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ElevatedButton(
|
||||
label: localization.customDesigns.toUpperCase(),
|
||||
iconData: Icons.settings,
|
||||
//onPressed: () => handleDesignAction(context, [group], EntityAction.settings),
|
||||
),
|
||||
),
|
||||
DesignPicker(
|
||||
label: localization.invoiceDesign,
|
||||
initialValue: settings.defaultInvoiceDesignId,
|
||||
|
|
|
|||
|
|
@ -143,11 +143,6 @@ class SettingsList extends StatelessWidget {
|
|||
section: kSettingsCustomFields,
|
||||
viewModel: viewModel,
|
||||
),
|
||||
if (showAll)
|
||||
SettingsListTile(
|
||||
section: kSettingsCustomDesigns,
|
||||
viewModel: viewModel,
|
||||
),
|
||||
SettingsListTile(
|
||||
section: kSettingsInvoiceDesign,
|
||||
viewModel: viewModel,
|
||||
|
|
|
|||
Loading…
Reference in New Issue