Skip to content

Commit 6264ddf

Browse files
chrisbobbegnprice
authored andcommitted
RealmInputScreen: Use error alert for server errors
Instead of showing them in exactly the same way we show client-side validation errors. For those (the client-side validation errors), give a more explicit name to the React state we use.
1 parent 5af4f8d commit 6264ddf

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/start/RealmInputScreen.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { tryParseUrl } from '../utils/url';
1515
import * as api from '../api';
1616
import { ThemeContext } from '../styles/theme';
1717
import { createStyleSheet, HALF_COLOR } from '../styles';
18+
import { showErrorAlert } from '../utils/info';
19+
import { TranslationContext } from '../boot/TranslationProvider';
1820

1921
type Props = $ReadOnly<{|
2022
navigation: AppNavigationProp<'realm-input'>,
@@ -32,12 +34,13 @@ const urlFromInputValue = (realmInputValue: string): URL | void => {
3234
export default function RealmInputScreen(props: Props): Node {
3335
const { navigation, route } = props;
3436

37+
const _ = React.useContext(TranslationContext);
3538
const themeContext = React.useContext(ThemeContext);
3639

3740
const [progress, setProgress] = React.useState(false);
3841
const [realmInputValue, setRealmInputValue] = React.useState('');
3942
const parsedRealm = urlFromInputValue(realmInputValue);
40-
const [error, setError] = React.useState(null);
43+
const [validationErrorMsg, setError] = React.useState(null);
4144

4245
const textInputRef = React.useRef<React$ElementRef<typeof TextInput> | null>(null);
4346

@@ -77,15 +80,15 @@ export default function RealmInputScreen(props: Props): Node {
7780
Keyboard.dismiss();
7881
} catch (errorIllTyped) {
7982
const err: mixed = errorIllTyped; // https://github.com/facebook/flow/issues/2470
80-
setError('Cannot connect to server.');
83+
showErrorAlert(_('Cannot connect to server.'));
8184
/* eslint-disable no-console */
8285
console.warn('RealmInputScreen: failed to connect to server:', err);
8386
// $FlowFixMe[incompatible-cast]: assuming caught exception was Error
8487
console.warn((err: Error).stack);
8588
} finally {
8689
setProgress(false);
8790
}
88-
}, [navigation, parsedRealm]);
91+
}, [navigation, parsedRealm, _]);
8992

9093
const styles = React.useMemo(
9194
() =>
@@ -138,8 +141,8 @@ export default function RealmInputScreen(props: Props): Node {
138141
ref={textInputRef}
139142
/>
140143
</View>
141-
{error !== null ? (
142-
<ErrorMsg error={error} />
144+
{validationErrorMsg !== null ? (
145+
<ErrorMsg error={validationErrorMsg} />
143146
) : (
144147
<ZulipTextIntl text="e.g. zulip.example.com" style={styles.hintText} />
145148
)}

0 commit comments

Comments
 (0)