// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React, {type RefObject, useCallback, useRef} from 'react'; import {defineMessages, useIntl} from 'react-intl'; import {Keyboard, View} from 'react-native'; import Button from '@components/button'; import FloatingTextInput, {type FloatingTextInputRef} from '@components/floating_text_input_label'; import FormattedText from '@components/formatted_text'; import {useAvoidKeyboard} from '@hooks/device'; import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; import {typography} from '@utils/typography'; import type {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view'; type Props = { autoFocus?: boolean; buttonDisabled: boolean; connecting: boolean; displayName?: string; displayNameError?: string; disableServerUrl: boolean; handleConnect: () => void; handleDisplayNameTextChanged: (text: string) => void; handleUrlTextChanged: (text: string) => void; keyboardAwareRef: RefObject; theme: Theme; url?: string; urlError?: string; }; const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({ formContainer: { alignItems: 'center', maxWidth: 600, width: '100%', paddingHorizontal: 20, }, enterServer: { marginBottom: 24, }, fullWidth: { width: '100%', }, chooseText: { alignSelf: 'flex-start', color: changeOpacity(theme.centerChannelColor, 0.64), marginTop: 8, ...typography('Body', 75, 'Regular'), }, connectButtonContainer: { width: '100%', marginTop: 32, marginLeft: 20, marginRight: 20, }, })); const messages = defineMessages({ connect: { id: 'mobile.components.select_server_view.connect', defaultMessage: 'Connect', }, connecting: { id: 'mobile.components.select_server_view.connecting', defaultMessage: 'Connecting', }, }); const ServerForm = ({ autoFocus = false, buttonDisabled, connecting, displayName = '', displayNameError, disableServerUrl, handleConnect, handleDisplayNameTextChanged, handleUrlTextChanged, keyboardAwareRef, theme, url = '', urlError, }: Props) => { const {formatMessage} = useIntl(); const displayNameRef = useRef(null); const urlRef = useRef(null); const styles = getStyleSheet(theme); useAvoidKeyboard(keyboardAwareRef); const onConnect = useCallback(() => { Keyboard.dismiss(); handleConnect(); }, [handleConnect]); const onUrlSubmit = useCallback(() => { displayNameRef.current?.focus(); }, []); const connectButtonTestId = buttonDisabled ? 'server_form.connect.button.disabled' : 'server_form.connect.button'; return ( {!displayNameError && }