Add company
This commit is contained in:
parent
0f20973efc
commit
f8814ac5f9
|
|
@ -90,6 +90,10 @@ class AuthRepository {
|
|||
return sendRequest(url: url, data: credentials);
|
||||
}
|
||||
|
||||
Future<dynamic> addCompany({String token}) async {
|
||||
return webClient.post('/companies', token);
|
||||
}
|
||||
|
||||
Future<LoginResponse> sendRequest(
|
||||
{String url, dynamic data, String token, String secret}) async {
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:invoiceninja_flutter/.env.dart';
|
||||
import 'package:invoiceninja_flutter/constants.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/company/company_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
|
||||
import 'package:invoiceninja_flutter/ui/auth/login_vm.dart';
|
||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
||||
|
|
@ -21,6 +22,7 @@ List<Middleware<AppState>> createStoreAuthMiddleware([
|
|||
final oauthRequest = _createOAuthRequest(repository);
|
||||
final refreshRequest = _createRefreshRequest(repository);
|
||||
final recoverRequest = _createRecoverRequest(repository);
|
||||
final addCompany = _createCompany(repository);
|
||||
|
||||
return [
|
||||
TypedMiddleware<AppState, UserLogout>(userLogout),
|
||||
|
|
@ -29,6 +31,7 @@ List<Middleware<AppState>> createStoreAuthMiddleware([
|
|||
TypedMiddleware<AppState, OAuthLoginRequest>(oauthRequest),
|
||||
TypedMiddleware<AppState, RefreshData>(refreshRequest),
|
||||
TypedMiddleware<AppState, RecoverPasswordRequest>(recoverRequest),
|
||||
TypedMiddleware<AppState, AddCompany>(addCompany),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -226,3 +229,14 @@ Middleware<AppState> _createRecoverRequest(AuthRepository repository) {
|
|||
next(action);
|
||||
};
|
||||
}
|
||||
|
||||
Middleware<AppState> _createCompany(AuthRepository repository) {
|
||||
return (Store<AppState> store, dynamic action, NextDispatcher next) async {
|
||||
|
||||
final state = store.state;
|
||||
|
||||
repository.addCompany(token: state.credentials.token);
|
||||
|
||||
next(action);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,3 +42,5 @@ class SaveCompanyFailure implements StopSaving {
|
|||
|
||||
final Object error;
|
||||
}
|
||||
|
||||
class AddCompany {}
|
||||
|
|
@ -102,36 +102,43 @@ class MenuDrawer extends StatelessWidget {
|
|||
},
|
||||
);
|
||||
|
||||
final _expandedCompanySelector = DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
isExpanded: true,
|
||||
icon: Icon(Icons.arrow_drop_down),
|
||||
value: viewModel.selectedCompanyIndex,
|
||||
items: viewModel.companies
|
||||
.map((CompanyEntity company) => DropdownMenuItem<String>(
|
||||
value: (viewModel.companies.indexOf(company)).toString(),
|
||||
child: _companyListItem(company),
|
||||
))
|
||||
.toList()..add(DropdownMenuItem<String>(
|
||||
value: null,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
SizedBox(width: 2),
|
||||
Icon(Icons.add_circle, size: 32),
|
||||
SizedBox(width: 28),
|
||||
Text(localization.addCompany),
|
||||
],
|
||||
),
|
||||
)),
|
||||
onChanged: (value) {
|
||||
if (value == null) {
|
||||
print('## ADD COMPANY.. ##');
|
||||
} else {
|
||||
viewModel.onCompanyChanged(
|
||||
context, value, viewModel.companies[int.parse(value)]);
|
||||
}
|
||||
},
|
||||
));
|
||||
final _expandedCompanySelector = viewModel.companies.isEmpty
|
||||
? SizedBox()
|
||||
: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
isExpanded: true,
|
||||
icon: Icon(Icons.arrow_drop_down),
|
||||
value: viewModel.selectedCompanyIndex,
|
||||
items: [
|
||||
...viewModel.companies
|
||||
.map((CompanyEntity company) => DropdownMenuItem<String>(
|
||||
value:
|
||||
(viewModel.companies.indexOf(company)).toString(),
|
||||
child: _companyListItem(company),
|
||||
))
|
||||
.toList(),
|
||||
DropdownMenuItem<String>(
|
||||
value: null,
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
SizedBox(width: 2),
|
||||
Icon(Icons.add_circle, size: 32),
|
||||
SizedBox(width: 28),
|
||||
Text(localization.addCompany),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (value) {
|
||||
if (value == null) {
|
||||
print('## ADD COMPANY.. ##');
|
||||
viewModel.onAddCompany();
|
||||
} else {
|
||||
viewModel.onCompanyChanged(
|
||||
context, value, viewModel.companies[int.parse(value)]);
|
||||
}
|
||||
},
|
||||
));
|
||||
|
||||
return SizedBox(
|
||||
width: state.prefState.isMenuCollapsed ? 65 : kDrawerWidth,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:invoiceninja_flutter/redux/client/client_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/company/company_actions.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/app_builder.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/menu_drawer.dart';
|
||||
|
|
@ -31,6 +32,7 @@ class MenuDrawerVM {
|
|||
@required this.selectedCompanyIndex,
|
||||
@required this.onCompanyChanged,
|
||||
@required this.isLoading,
|
||||
@required this.onAddCompany,
|
||||
});
|
||||
|
||||
final List<CompanyEntity> companies;
|
||||
|
|
@ -38,6 +40,8 @@ class MenuDrawerVM {
|
|||
final UserEntity user;
|
||||
final String selectedCompanyIndex;
|
||||
final Function(BuildContext context, String, CompanyEntity) onCompanyChanged;
|
||||
final Function onAddCompany;
|
||||
|
||||
final bool isLoading;
|
||||
|
||||
static MenuDrawerVM fromStore(Store<AppState> store) {
|
||||
|
|
@ -57,6 +61,9 @@ class MenuDrawerVM {
|
|||
store.dispatch(LoadClients());
|
||||
AppBuilder.of(context).rebuild();
|
||||
},
|
||||
onAddCompany: () {
|
||||
store.dispatch(AddCompany());
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue