Skip to content

Commit

Permalink
login: Link to doc for what "server URL" is and how to find it
Browse files Browse the repository at this point in the history
  • Loading branch information
VatsalBhesaniya committed Mar 27, 2024
1 parent 68116a2 commit ff277e7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions assets/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@
"@loginServerUrlInputLabel": {
"description": "Input label in login page for Zulip server URL entry."
},
"serverURLDocLinkLabel": "(What's this?)",
"@serverURLDocLinkLabel": {
"description": "Link to doc to help users understand what a server URL is and how to find theirs."
},
"loginHidePassword": "Hide password",
"@loginHidePassword": {
"description": "Icon label for button to hide password in input form."
Expand Down
34 changes: 33 additions & 1 deletion lib/widgets/login.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart';

import '../api/exception.dart';
import '../api/route/account.dart';
import '../api/route/realm.dart';
import '../api/route/users.dart';
import '../model/binding.dart';
import '../model/store.dart';
import 'app.dart';
import 'dialog.dart';
Expand Down Expand Up @@ -223,7 +225,13 @@ class _AddAccountPageState extends State<AddAccountPage> {
decoration: InputDecoration(
labelText: zulipLocalizations.loginServerUrlInputLabel,
errorText: errorText,
helperText: kLayoutPinningHelperText,
helper: InkWell(
onTap: () {
_launchUrl(context);
},
child: Text(
zulipLocalizations.serverURLDocLinkLabel,
style: const TextStyle(color: Colors.blue))),
hintText: 'your-org.zulipchat.com')),
const SizedBox(height: 8),
ElevatedButton(
Expand All @@ -235,6 +243,30 @@ class _AddAccountPageState extends State<AddAccountPage> {
}
}

void _launchUrl(BuildContext context) async {
String urlString = 'https://zulip.com/help/logging-in#find-the-zulip-log-in-url';
Future<void> showError(BuildContext context, String? message) {
return showErrorDialog(context: context,
title: 'Unable to open link',
message: [
'Link could not be opened: $urlString',
if (message != null) message,
].join("\n\n"));
}

bool launched = false;
String? errorMessage;
try {
launched = await ZulipBinding.instance.launchUrl(Uri.parse(urlString));
} on PlatformException catch (e) {
errorMessage = e.message;
}
if (!launched) {
if (!context.mounted) return;
await showError(context, errorMessage);
}
}

class PasswordLoginPage extends StatefulWidget {
const PasswordLoginPage({super.key, required this.serverSettings});

Expand Down

0 comments on commit ff277e7

Please sign in to comment.