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 (!isQuote && !isCredit && isSent) {
|
||||
if (statusId != kInvoiceStatusReversed) {
|
||||
if (![
|
||||
kInvoiceStatusReversed,
|
||||
kInvoiceStatusCancelled,
|
||||
].contains(statusId)) {
|
||||
actions.add(EntityAction.cancel);
|
||||
}
|
||||
|
||||
if (userCompany.company.isModuleEnabled(EntityType.credit)) {
|
||||
if (userCompany.company.isModuleEnabled(EntityType.credit) &&
|
||||
statusId != kInvoiceStatusReversed) {
|
||||
actions.add(EntityAction.reverse);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -551,6 +551,7 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
|||
@override
|
||||
String toString() {
|
||||
//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}';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,13 +15,6 @@ class LoadStateSuccess {
|
|||
final AppState state;
|
||||
}
|
||||
|
||||
class UserLoginLoaded {
|
||||
UserLoginLoaded(this.email, this.url);
|
||||
|
||||
final String email;
|
||||
final String url;
|
||||
}
|
||||
|
||||
class OAuthLoginRequest implements StartLoading {
|
||||
OAuthLoginRequest({
|
||||
@required this.completer,
|
||||
|
|
|
|||
|
|
@ -44,33 +44,18 @@ List<Middleware<AppState>> createStoreAuthMiddleware([
|
|||
];
|
||||
}
|
||||
|
||||
void _saveAuthLocal(
|
||||
{String email = '', String url = '', String secret = ''}) async {
|
||||
void _saveAuthLocal({String email = '', String url = ''}) async {
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString(kSharedPrefEmail, email ?? '');
|
||||
prefs.setString(kSharedPrefEmail, email);
|
||||
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() {
|
||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||
final action = dynamicAction as UserLogout;
|
||||
|
||||
next(action);
|
||||
|
||||
_loadAuthLocal(store);
|
||||
|
||||
Navigator.of(action.context).pushNamedAndRemoveUntil(
|
||||
LoginScreen.route, (Route<dynamic> route) => false);
|
||||
|
||||
|
|
@ -93,7 +78,6 @@ Middleware<AppState> _createLoginRequest(AuthRepository repository) {
|
|||
.then((data) {
|
||||
_saveAuthLocal(
|
||||
email: action.email,
|
||||
secret: action.secret,
|
||||
url: action.url,
|
||||
);
|
||||
store.dispatch(
|
||||
|
|
@ -131,7 +115,7 @@ Middleware<AppState> _createSignUpRequest(AuthRepository repository) {
|
|||
password: action.password,
|
||||
)
|
||||
.then((data) {
|
||||
_saveAuthLocal(email: action.email, secret: '', url: '');
|
||||
_saveAuthLocal(email: action.email, url: kAppProductionUrl);
|
||||
|
||||
store.dispatch(
|
||||
LoadAccountSuccess(completer: action.completer, loginResponse: data));
|
||||
|
|
@ -162,7 +146,6 @@ Middleware<AppState> _createOAuthLoginRequest(AuthRepository repository) {
|
|||
.then((data) {
|
||||
_saveAuthLocal(
|
||||
email: action.email,
|
||||
secret: action.secret,
|
||||
url: action.url,
|
||||
);
|
||||
|
||||
|
|
@ -191,7 +174,7 @@ Middleware<AppState> _createOAuthSignUpRequest(AuthRepository repository) {
|
|||
serverAuthCode: action.serverAuthCode,
|
||||
)
|
||||
.then((data) {
|
||||
_saveAuthLocal(email: '', secret: '', url: '');
|
||||
_saveAuthLocal(url: kAppProductionUrl);
|
||||
|
||||
store.dispatch(
|
||||
LoadAccountSuccess(completer: action.completer, loginResponse: data));
|
||||
|
|
@ -212,14 +195,10 @@ Middleware<AppState> _createRefreshRequest(AuthRepository repository) {
|
|||
NextDispatcher next) async {
|
||||
final action = dynamicAction as RefreshData;
|
||||
|
||||
_loadAuthLocal(store);
|
||||
|
||||
String url;
|
||||
String token;
|
||||
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
url = formatApiUrl(prefs.getString(kSharedPrefUrl) ?? Config.TEST_URL);
|
||||
token = prefs.getString(kSharedPrefToken);
|
||||
final url =
|
||||
formatApiUrl(prefs.getString(kSharedPrefUrl) ?? Config.TEST_URL);
|
||||
final token = prefs.getString(kSharedPrefToken);
|
||||
|
||||
repository.refresh(url: url, token: token).then((data) {
|
||||
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';
|
||||
|
||||
Reducer<AuthState> authReducer = combineReducers([
|
||||
TypedReducer<AuthState, UserLoginLoaded>(userLoginLoadedReducer),
|
||||
TypedReducer<AuthState, UserLoginRequest>(userLoginRequestReducer),
|
||||
TypedReducer<AuthState, OAuthLoginRequest>(oauthLoginRequestReducer),
|
||||
TypedReducer<AuthState, OAuthSignUpRequest>(oauthSignUpRequestReducer),
|
||||
|
|
@ -21,13 +20,6 @@ AuthState userSignUpRequestReducer(
|
|||
..secret = '');
|
||||
}
|
||||
|
||||
AuthState userLoginLoadedReducer(AuthState authState, UserLoginLoaded action) {
|
||||
return authState.rebuild((b) => b
|
||||
..isInitialized = true
|
||||
..url = formatApiUrl(action.url)
|
||||
..email = action.email ?? '');
|
||||
}
|
||||
|
||||
AuthState userLoginRequestReducer(
|
||||
AuthState authState, UserLoginRequest action) {
|
||||
return authState.rebuild((b) => b
|
||||
|
|
|
|||
Loading…
Reference in New Issue