Company selector
This commit is contained in:
parent
5b50a81d94
commit
b19ab9e45b
|
|
@ -7,6 +7,7 @@ class CustomDrawer extends StatelessWidget {
|
||||||
final bool hasMultipleCompanies;
|
final bool hasMultipleCompanies;
|
||||||
final List<CompanyEntity> companies;
|
final List<CompanyEntity> companies;
|
||||||
final String selectedCompanyId;
|
final String selectedCompanyId;
|
||||||
|
final Function(String) onCompanyChanged;
|
||||||
|
|
||||||
CustomDrawer({
|
CustomDrawer({
|
||||||
Key key,
|
Key key,
|
||||||
|
|
@ -14,6 +15,7 @@ class CustomDrawer extends StatelessWidget {
|
||||||
@required this.hasMultipleCompanies,
|
@required this.hasMultipleCompanies,
|
||||||
@required this.companies,
|
@required this.companies,
|
||||||
@required this.selectedCompanyId,
|
@required this.selectedCompanyId,
|
||||||
|
@required this.onCompanyChanged,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -26,6 +28,7 @@ class CustomDrawer extends StatelessWidget {
|
||||||
final _multipleCompanies = Align(
|
final _multipleCompanies = Align(
|
||||||
alignment: FractionalOffset.bottomLeft,
|
alignment: FractionalOffset.bottomLeft,
|
||||||
child: new DropdownButton<String>(
|
child: new DropdownButton<String>(
|
||||||
|
isDense: true,
|
||||||
value: this.selectedCompanyId,
|
value: this.selectedCompanyId,
|
||||||
items: this.companies.map((CompanyEntity company) =>
|
items: this.companies.map((CompanyEntity company) =>
|
||||||
DropdownMenuItem<String>(
|
DropdownMenuItem<String>(
|
||||||
|
|
@ -35,17 +38,9 @@ class CustomDrawer extends StatelessWidget {
|
||||||
).toList(),
|
).toList(),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
print('on change: ' + value);
|
print('on change: ' + value);
|
||||||
|
this.onCompanyChanged(value);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
/*
|
|
||||||
child: DropdownButton(
|
|
||||||
items: this.companies.map((CompanyEntity company) {
|
|
||||||
return DropdownMenuItem(
|
|
||||||
child: Text(company.name),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
*/
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return Drawer(
|
return Drawer(
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import 'package:redux/redux.dart';
|
||||||
import 'package:invoiceninja/ui/app/custom_drawer.dart';
|
import 'package:invoiceninja/ui/app/custom_drawer.dart';
|
||||||
import 'package:invoiceninja/redux/app/app_state.dart';
|
import 'package:invoiceninja/redux/app/app_state.dart';
|
||||||
import 'package:invoiceninja/redux/company/company_selectors.dart';
|
import 'package:invoiceninja/redux/company/company_selectors.dart';
|
||||||
|
import 'package:invoiceninja/redux/company/company_actions.dart';
|
||||||
import 'package:invoiceninja/data/models/models.dart';
|
import 'package:invoiceninja/data/models/models.dart';
|
||||||
|
|
||||||
class CustomDrawerVM extends StatelessWidget {
|
class CustomDrawerVM extends StatelessWidget {
|
||||||
|
|
@ -20,6 +21,7 @@ class CustomDrawerVM extends StatelessWidget {
|
||||||
hasMultipleCompanies: vm.hasMultipleCompanies,
|
hasMultipleCompanies: vm.hasMultipleCompanies,
|
||||||
companies: vm.companies,
|
companies: vm.companies,
|
||||||
selectedCompanyId: vm.selectedCompanyId,
|
selectedCompanyId: vm.selectedCompanyId,
|
||||||
|
onCompanyChanged: vm.onCompanyChanged,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -31,12 +33,14 @@ class _ViewModel {
|
||||||
final bool hasMultipleCompanies;
|
final bool hasMultipleCompanies;
|
||||||
final List<CompanyEntity> companies;
|
final List<CompanyEntity> companies;
|
||||||
final String selectedCompanyId;
|
final String selectedCompanyId;
|
||||||
|
final Function(String) onCompanyChanged;
|
||||||
|
|
||||||
_ViewModel({
|
_ViewModel({
|
||||||
@required this.companyName,
|
@required this.companyName,
|
||||||
@required this.hasMultipleCompanies,
|
@required this.hasMultipleCompanies,
|
||||||
@required this.companies,
|
@required this.companies,
|
||||||
@required this.selectedCompanyId,
|
@required this.selectedCompanyId,
|
||||||
|
@required this.onCompanyChanged,
|
||||||
});
|
});
|
||||||
|
|
||||||
static _ViewModel fromStore(Store<AppState> store) {
|
static _ViewModel fromStore(Store<AppState> store) {
|
||||||
|
|
@ -45,6 +49,9 @@ class _ViewModel {
|
||||||
hasMultipleCompanies: store.state.companyState2.company.token != null,
|
hasMultipleCompanies: store.state.companyState2.company.token != null,
|
||||||
companies: companiesSelector(store.state),
|
companies: companiesSelector(store.state),
|
||||||
selectedCompanyId: store.state.selectedCompanyId.toString(),
|
selectedCompanyId: store.state.selectedCompanyId.toString(),
|
||||||
|
onCompanyChanged: (String companyId) {
|
||||||
|
store.dispatch(SelectCompany(int.parse(companyId)));
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue