From 2fb7945f23246b392cd6c2a369694e2831b38a7c Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 19 Nov 2023 09:44:55 +0200 Subject: [PATCH] Show React icon to hosted web users --- lib/constants.dart | 4 +- lib/redux/app/app_middleware.dart | 2 +- lib/redux/app/app_state.dart | 2 +- lib/redux/auth/auth_state.dart | 2 +- lib/ui/dashboard/dashboard_screen.dart | 60 ++++++++++++++------------ 5 files changed, 39 insertions(+), 31 deletions(-) diff --git a/lib/constants.dart b/lib/constants.dart index cb9f24e6a..63598100c 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -10,10 +10,12 @@ const String kMinServerVersion = '5.0.4'; const String kAppName = 'Invoice Ninja'; const String kSiteUrl = 'https://invoiceninja.com'; const String kAppProductionUrl = 'https://invoicing.co'; +const String kAppReactUrl = 'https://app.invoicing.co'; const String kAppStagingUrl = 'https://staging.invoicing.co'; const String kAppStagingNetUrl = 'https://invoiceninja.net'; const String kAppLargeTestUrl = 'https://testv5.invoicing.co'; -const String kAppDemoUrl = 'https://demo.invoiceninja.com'; +const String kFlutterDemoUrl = 'https://demo.invoiceninja.com'; +const String kReactDemoUrl = 'https://react.invoicing.co/demo'; const String kWhiteLabelUrl = 'https://app.invoiceninja.com/buy_now/?account_key=AsFmBAeLXF0IKf7tmi0eiyZfmWW9hxMT&product_id=3'; const String kPrivacyPolicyURL = 'https://www.invoiceninja.com/privacy-policy'; diff --git a/lib/redux/app/app_middleware.dart b/lib/redux/app/app_middleware.dart index 7c50ab757..80c4d045b 100644 --- a/lib/redux/app/app_middleware.dart +++ b/lib/redux/app/app_middleware.dart @@ -271,7 +271,7 @@ Middleware _createLoadState( String? token; if (Config.DEMO_MODE || - cleanApiUrl(store.state.authState.url) == kAppDemoUrl) { + cleanApiUrl(store.state.authState.url) == kFlutterDemoUrl) { token = 'TOKEN'; } else { final SharedPreferences prefs = await SharedPreferences.getInstance(); diff --git a/lib/redux/app/app_state.dart b/lib/redux/app/app_state.dart index 19803a0b8..8a5fc5ad6 100644 --- a/lib/redux/app/app_state.dart +++ b/lib/redux/app/app_state.dart @@ -833,7 +833,7 @@ abstract class AppState implements Built { bool get isSelfHosted => !isHosted; - bool get isDemo => cleanApiUrl(authState.url) == kAppDemoUrl; + bool get isDemo => cleanApiUrl(authState.url) == kFlutterDemoUrl; bool get isStaging => cleanApiUrl(authState.url) == kAppStagingUrl; diff --git a/lib/redux/auth/auth_state.dart b/lib/redux/auth/auth_state.dart index 51dc3e63a..177432c39 100644 --- a/lib/redux/auth/auth_state.dart +++ b/lib/redux/auth/auth_state.dart @@ -47,7 +47,7 @@ abstract class AuthState implements Built { if ([ kAppProductionUrl, - kAppDemoUrl, + kFlutterDemoUrl, kAppStagingUrl, kAppStagingNetUrl, ].contains(cleanUrl)) { diff --git a/lib/ui/dashboard/dashboard_screen.dart b/lib/ui/dashboard/dashboard_screen.dart index 5d42d0b39..7a2129442 100644 --- a/lib/ui/dashboard/dashboard_screen.dart +++ b/lib/ui/dashboard/dashboard_screen.dart @@ -259,40 +259,46 @@ class _DashboardScreenState extends State ), if (!kReleaseMode || (kIsWeb && - state.isSelfHosted && - state.userCompany.isAdmin && - !state.isDemo)) + (state.isHosted || + (state.isSelfHosted && state.userCompany.isAdmin)))) Padding( padding: const EdgeInsets.only(right: 10), child: IconButton( tooltip: localization!.enableReactApp, onPressed: () async { - confirmCallback( - context: context, - message: localization.enableReactApp, - callback: (_) { - final credentials = state.credentials; - final account = state.account - .rebuild((b) => b..setReactAsDefaultAP = true); - final url = '${credentials.url}/accounts/${account.id}'; - final data = serializers.serializeWith( - AccountEntity.serializer, account); + if (state.isDemo) { + launchUrl(Uri.parse(kReactDemoUrl)); + } else if (state.isHosted) { + launchUrl(Uri.parse(kAppReactUrl)); + } else { + confirmCallback( + context: context, + message: localization.enableReactApp, + callback: (_) { + final credentials = state.credentials; + final account = state.account + .rebuild((b) => b..setReactAsDefaultAP = true); + final url = + '${credentials.url}/accounts/${account.id}'; + final data = serializers.serializeWith( + AccountEntity.serializer, account); - store.dispatch(StartSaving()); - WebClient() - .put( - url, - credentials.token, - data: json.encode(data), - ) - .then((dynamic _) { - store.dispatch(StopSaving()); - WebUtils.reloadBrowser(); - }).catchError((Object error) { - store.dispatch(StopSaving()); - showErrorDialog(message: error as String?); + store.dispatch(StartSaving()); + WebClient() + .put( + url, + credentials.token, + data: json.encode(data), + ) + .then((dynamic _) { + store.dispatch(StopSaving()); + WebUtils.reloadBrowser(); + }).catchError((Object error) { + store.dispatch(StopSaving()); + showErrorDialog(message: error as String?); + }); }); - }); + } }, icon: Icon(MdiIcons.react), ),