Show React icon to hosted web users

This commit is contained in:
Hillel Coren 2023-11-19 09:44:55 +02:00
parent 5b2e3af1ba
commit 2fb7945f23
5 changed files with 39 additions and 31 deletions

View File

@ -10,10 +10,12 @@ const String kMinServerVersion = '5.0.4';
const String kAppName = 'Invoice Ninja'; const String kAppName = 'Invoice Ninja';
const String kSiteUrl = 'https://invoiceninja.com'; const String kSiteUrl = 'https://invoiceninja.com';
const String kAppProductionUrl = 'https://invoicing.co'; const String kAppProductionUrl = 'https://invoicing.co';
const String kAppReactUrl = 'https://app.invoicing.co';
const String kAppStagingUrl = 'https://staging.invoicing.co'; const String kAppStagingUrl = 'https://staging.invoicing.co';
const String kAppStagingNetUrl = 'https://invoiceninja.net'; const String kAppStagingNetUrl = 'https://invoiceninja.net';
const String kAppLargeTestUrl = 'https://testv5.invoicing.co'; 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 = const String kWhiteLabelUrl =
'https://app.invoiceninja.com/buy_now/?account_key=AsFmBAeLXF0IKf7tmi0eiyZfmWW9hxMT&product_id=3'; 'https://app.invoiceninja.com/buy_now/?account_key=AsFmBAeLXF0IKf7tmi0eiyZfmWW9hxMT&product_id=3';
const String kPrivacyPolicyURL = 'https://www.invoiceninja.com/privacy-policy'; const String kPrivacyPolicyURL = 'https://www.invoiceninja.com/privacy-policy';

View File

@ -271,7 +271,7 @@ Middleware<AppState> _createLoadState(
String? token; String? token;
if (Config.DEMO_MODE || if (Config.DEMO_MODE ||
cleanApiUrl(store.state.authState.url) == kAppDemoUrl) { cleanApiUrl(store.state.authState.url) == kFlutterDemoUrl) {
token = 'TOKEN'; token = 'TOKEN';
} else { } else {
final SharedPreferences prefs = await SharedPreferences.getInstance(); final SharedPreferences prefs = await SharedPreferences.getInstance();

View File

@ -833,7 +833,7 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
bool get isSelfHosted => !isHosted; 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; bool get isStaging => cleanApiUrl(authState.url) == kAppStagingUrl;

View File

@ -47,7 +47,7 @@ abstract class AuthState implements Built<AuthState, AuthStateBuilder> {
if ([ if ([
kAppProductionUrl, kAppProductionUrl,
kAppDemoUrl, kFlutterDemoUrl,
kAppStagingUrl, kAppStagingUrl,
kAppStagingNetUrl, kAppStagingNetUrl,
].contains(cleanUrl)) { ].contains(cleanUrl)) {

View File

@ -259,40 +259,46 @@ class _DashboardScreenState extends State<DashboardScreen>
), ),
if (!kReleaseMode || if (!kReleaseMode ||
(kIsWeb && (kIsWeb &&
state.isSelfHosted && (state.isHosted ||
state.userCompany.isAdmin && (state.isSelfHosted && state.userCompany.isAdmin))))
!state.isDemo))
Padding( Padding(
padding: const EdgeInsets.only(right: 10), padding: const EdgeInsets.only(right: 10),
child: IconButton( child: IconButton(
tooltip: localization!.enableReactApp, tooltip: localization!.enableReactApp,
onPressed: () async { onPressed: () async {
confirmCallback( if (state.isDemo) {
context: context, launchUrl(Uri.parse(kReactDemoUrl));
message: localization.enableReactApp, } else if (state.isHosted) {
callback: (_) { launchUrl(Uri.parse(kAppReactUrl));
final credentials = state.credentials; } else {
final account = state.account confirmCallback(
.rebuild((b) => b..setReactAsDefaultAP = true); context: context,
final url = '${credentials.url}/accounts/${account.id}'; message: localization.enableReactApp,
final data = serializers.serializeWith( callback: (_) {
AccountEntity.serializer, account); 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()); store.dispatch(StartSaving());
WebClient() WebClient()
.put( .put(
url, url,
credentials.token, credentials.token,
data: json.encode(data), data: json.encode(data),
) )
.then((dynamic _) { .then((dynamic _) {
store.dispatch(StopSaving()); store.dispatch(StopSaving());
WebUtils.reloadBrowser(); WebUtils.reloadBrowser();
}).catchError((Object error) { }).catchError((Object error) {
store.dispatch(StopSaving()); store.dispatch(StopSaving());
showErrorDialog(message: error as String?); showErrorDialog(message: error as String?);
});
}); });
}); }
}, },
icon: Icon(MdiIcons.react), icon: Icon(MdiIcons.react),
), ),