diff --git a/lib/constants.dart b/lib/constants.dart index c5ed97740..33a041f6f 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -20,6 +20,10 @@ const String kSharedPrefAppVersion = 'app_version'; const String kSharedPrefRequireAuthentication = 'require_authentication'; const String kSharedPrefAddDocumentsToInvoice = 'add_documents_to_invoice'; +const String kPlanFree = ''; +const String kPlanPro = 'pro'; +const String kPlanEnterprise = 'enterprise'; + String getCompanyTokenKey([int companyIndex = 0]) => '${kSharedPrefToken}_$companyIndex'; diff --git a/lib/data/models/company_model.dart b/lib/data/models/company_model.dart index ecd142100..62fa3d8c6 100644 --- a/lib/data/models/company_model.dart +++ b/lib/data/models/company_model.dart @@ -320,6 +320,14 @@ abstract class CompanyEntity return plan.isNotEmpty; } + bool get isEnterprisePlan { + if (appUrl != kAppUrl) { + return true; + } + + return plan == kPlanEnterprise; + } + bool isModuleEnabled(EntityType entityType) { if (entityType == EntityType.recurringInvoice && enabledModules & kModuleRecurringInvoice == 0) { diff --git a/lib/redux/document/document_middleware.dart b/lib/redux/document/document_middleware.dart index 2c5b05661..892473847 100644 --- a/lib/redux/document/document_middleware.dart +++ b/lib/redux/document/document_middleware.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; +import 'package:invoiceninja_flutter/redux/dashboard/dashboard_actions.dart'; import 'package:redux/redux.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart'; @@ -216,11 +217,9 @@ Middleware _loadDocuments(DocumentRepository repository) { if (action.completer != null) { action.completer.complete(null); } - /* if (state.productState.isStale) { - store.dispatch(LoadProducts()); + store.dispatch(LoadDashboard()); } - */ }).catchError((Object error) { print(error); store.dispatch(LoadDocumentsFailure(error)); diff --git a/lib/redux/expense/expense_middleware.dart b/lib/redux/expense/expense_middleware.dart index a29139179..b228604fc 100644 --- a/lib/redux/expense/expense_middleware.dart +++ b/lib/redux/expense/expense_middleware.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:invoiceninja_flutter/redux/dashboard/dashboard_actions.dart'; +import 'package:invoiceninja_flutter/redux/document/document_actions.dart'; import 'package:redux/redux.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart'; @@ -218,7 +219,11 @@ Middleware _loadExpenses(ExpenseRepository repository) { action.completer.complete(null); } if (state.dashboardState.isStale) { - store.dispatch(LoadDashboard()); + if (state.selectedCompany.isEnterprisePlan) { + store.dispatch(LoadDocuments()); + } else { + store.dispatch(LoadDashboard()); + } } }).catchError((Object error) { print(error);