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