Fixes for refresh data
This commit is contained in:
parent
8eb13c0601
commit
b8998cd7cc
|
|
@ -560,11 +560,15 @@ abstract class InvoiceEntity extends Object
|
||||||
|
|
||||||
if (userCompany.canEditEntity(this)) {
|
if (userCompany.canEditEntity(this)) {
|
||||||
if (!isQuote && !isCredit && isSent) {
|
if (!isQuote && !isCredit && isSent) {
|
||||||
if (statusId != kInvoiceStatusReversed) {
|
if (![
|
||||||
|
kInvoiceStatusReversed,
|
||||||
|
kInvoiceStatusCancelled,
|
||||||
|
].contains(statusId)) {
|
||||||
actions.add(EntityAction.cancel);
|
actions.add(EntityAction.cancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userCompany.company.isModuleEnabled(EntityType.credit)) {
|
if (userCompany.company.isModuleEnabled(EntityType.credit) &&
|
||||||
|
statusId != kInvoiceStatusReversed) {
|
||||||
actions.add(EntityAction.reverse);
|
actions.add(EntityAction.reverse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -551,6 +551,7 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
//return 'Token: ${userCompanyStates.map((state) => state.token.token).where((name) => name.isNotEmpty).first}';
|
//return 'Token: ${userCompanyStates.map((state) => state.token.token).where((name) => name.isNotEmpty).first}';
|
||||||
|
return 'URL: ${authState.url}';
|
||||||
return 'Layout: ${prefState.appLayout}, Route: ${uiState.currentRoute} Prev: ${uiState.previousRoute}';
|
return 'Layout: ${prefState.appLayout}, Route: ${uiState.currentRoute} Prev: ${uiState.previousRoute}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,13 +15,6 @@ class LoadStateSuccess {
|
||||||
final AppState state;
|
final AppState state;
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserLoginLoaded {
|
|
||||||
UserLoginLoaded(this.email, this.url);
|
|
||||||
|
|
||||||
final String email;
|
|
||||||
final String url;
|
|
||||||
}
|
|
||||||
|
|
||||||
class OAuthLoginRequest implements StartLoading {
|
class OAuthLoginRequest implements StartLoading {
|
||||||
OAuthLoginRequest({
|
OAuthLoginRequest({
|
||||||
@required this.completer,
|
@required this.completer,
|
||||||
|
|
|
||||||
|
|
@ -44,33 +44,18 @@ List<Middleware<AppState>> createStoreAuthMiddleware([
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
void _saveAuthLocal(
|
void _saveAuthLocal({String email = '', String url = ''}) async {
|
||||||
{String email = '', String url = '', String secret = ''}) async {
|
|
||||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
prefs.setString(kSharedPrefEmail, email ?? '');
|
prefs.setString(kSharedPrefEmail, email);
|
||||||
prefs.setString(kSharedPrefUrl, formatApiUrl(url));
|
prefs.setString(kSharedPrefUrl, formatApiUrl(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _loadAuthLocal(Store<AppState> store) async {
|
|
||||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
||||||
final String email = kReleaseMode
|
|
||||||
? (prefs.getString(kSharedPrefEmail) ?? '')
|
|
||||||
: Config.TEST_EMAIL;
|
|
||||||
final String url = formatApiUrl(prefs.getString(kSharedPrefUrl) ?? '');
|
|
||||||
|
|
||||||
if (email.isNotEmpty) {
|
|
||||||
store.dispatch(UserLoginLoaded(email, url));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Middleware<AppState> _createUserLogout() {
|
Middleware<AppState> _createUserLogout() {
|
||||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
final action = dynamicAction as UserLogout;
|
final action = dynamicAction as UserLogout;
|
||||||
|
|
||||||
next(action);
|
next(action);
|
||||||
|
|
||||||
_loadAuthLocal(store);
|
|
||||||
|
|
||||||
Navigator.of(action.context).pushNamedAndRemoveUntil(
|
Navigator.of(action.context).pushNamedAndRemoveUntil(
|
||||||
LoginScreen.route, (Route<dynamic> route) => false);
|
LoginScreen.route, (Route<dynamic> route) => false);
|
||||||
|
|
||||||
|
|
@ -93,7 +78,6 @@ Middleware<AppState> _createLoginRequest(AuthRepository repository) {
|
||||||
.then((data) {
|
.then((data) {
|
||||||
_saveAuthLocal(
|
_saveAuthLocal(
|
||||||
email: action.email,
|
email: action.email,
|
||||||
secret: action.secret,
|
|
||||||
url: action.url,
|
url: action.url,
|
||||||
);
|
);
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
|
|
@ -131,7 +115,7 @@ Middleware<AppState> _createSignUpRequest(AuthRepository repository) {
|
||||||
password: action.password,
|
password: action.password,
|
||||||
)
|
)
|
||||||
.then((data) {
|
.then((data) {
|
||||||
_saveAuthLocal(email: action.email, secret: '', url: '');
|
_saveAuthLocal(email: action.email, url: kAppProductionUrl);
|
||||||
|
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
LoadAccountSuccess(completer: action.completer, loginResponse: data));
|
LoadAccountSuccess(completer: action.completer, loginResponse: data));
|
||||||
|
|
@ -162,7 +146,6 @@ Middleware<AppState> _createOAuthLoginRequest(AuthRepository repository) {
|
||||||
.then((data) {
|
.then((data) {
|
||||||
_saveAuthLocal(
|
_saveAuthLocal(
|
||||||
email: action.email,
|
email: action.email,
|
||||||
secret: action.secret,
|
|
||||||
url: action.url,
|
url: action.url,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -191,7 +174,7 @@ Middleware<AppState> _createOAuthSignUpRequest(AuthRepository repository) {
|
||||||
serverAuthCode: action.serverAuthCode,
|
serverAuthCode: action.serverAuthCode,
|
||||||
)
|
)
|
||||||
.then((data) {
|
.then((data) {
|
||||||
_saveAuthLocal(email: '', secret: '', url: '');
|
_saveAuthLocal(url: kAppProductionUrl);
|
||||||
|
|
||||||
store.dispatch(
|
store.dispatch(
|
||||||
LoadAccountSuccess(completer: action.completer, loginResponse: data));
|
LoadAccountSuccess(completer: action.completer, loginResponse: data));
|
||||||
|
|
@ -212,14 +195,10 @@ Middleware<AppState> _createRefreshRequest(AuthRepository repository) {
|
||||||
NextDispatcher next) async {
|
NextDispatcher next) async {
|
||||||
final action = dynamicAction as RefreshData;
|
final action = dynamicAction as RefreshData;
|
||||||
|
|
||||||
_loadAuthLocal(store);
|
|
||||||
|
|
||||||
String url;
|
|
||||||
String token;
|
|
||||||
|
|
||||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
url = formatApiUrl(prefs.getString(kSharedPrefUrl) ?? Config.TEST_URL);
|
final url =
|
||||||
token = prefs.getString(kSharedPrefToken);
|
formatApiUrl(prefs.getString(kSharedPrefUrl) ?? Config.TEST_URL);
|
||||||
|
final token = prefs.getString(kSharedPrefToken);
|
||||||
|
|
||||||
repository.refresh(url: url, token: token).then((data) {
|
repository.refresh(url: url, token: token).then((data) {
|
||||||
store.dispatch(LoadAccountSuccess(
|
store.dispatch(LoadAccountSuccess(
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import 'package:invoiceninja_flutter/redux/auth/auth_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/auth/auth_state.dart';
|
import 'package:invoiceninja_flutter/redux/auth/auth_state.dart';
|
||||||
|
|
||||||
Reducer<AuthState> authReducer = combineReducers([
|
Reducer<AuthState> authReducer = combineReducers([
|
||||||
TypedReducer<AuthState, UserLoginLoaded>(userLoginLoadedReducer),
|
|
||||||
TypedReducer<AuthState, UserLoginRequest>(userLoginRequestReducer),
|
TypedReducer<AuthState, UserLoginRequest>(userLoginRequestReducer),
|
||||||
TypedReducer<AuthState, OAuthLoginRequest>(oauthLoginRequestReducer),
|
TypedReducer<AuthState, OAuthLoginRequest>(oauthLoginRequestReducer),
|
||||||
TypedReducer<AuthState, OAuthSignUpRequest>(oauthSignUpRequestReducer),
|
TypedReducer<AuthState, OAuthSignUpRequest>(oauthSignUpRequestReducer),
|
||||||
|
|
@ -21,13 +20,6 @@ AuthState userSignUpRequestReducer(
|
||||||
..secret = '');
|
..secret = '');
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthState userLoginLoadedReducer(AuthState authState, UserLoginLoaded action) {
|
|
||||||
return authState.rebuild((b) => b
|
|
||||||
..isInitialized = true
|
|
||||||
..url = formatApiUrl(action.url)
|
|
||||||
..email = action.email ?? '');
|
|
||||||
}
|
|
||||||
|
|
||||||
AuthState userLoginRequestReducer(
|
AuthState userLoginRequestReducer(
|
||||||
AuthState authState, UserLoginRequest action) {
|
AuthState authState, UserLoginRequest action) {
|
||||||
return authState.rebuild((b) => b
|
return authState.rebuild((b) => b
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue