import React, { forwardRef, useImperativeHandle, useState } from 'react'; import { InteractionManager, StyleSheet, Text, View } from 'react-native'; import Modal from 'react-native-modal'; import { connect } from 'react-redux'; import I18n from '../../i18n'; import Button from '../../containers/Button'; import TextInput from '../../containers/TextInput'; import RocketChat from '../../lib/rocketchat'; import sharedStyles from '../Styles'; import { themes } from '../../constants/colors'; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center' }, content: { padding: 16, width: '100%', borderRadius: 4 }, title: { fontSize: 16, paddingBottom: 8, ...sharedStyles.textBold, ...sharedStyles.textAlignCenter }, button: { minWidth: 96, marginBottom: 0 }, buttonContainer: { flexDirection: 'row', justifyContent: 'space-between' }, tablet: { height: undefined } }); interface IRoomJoinCodeProps { rid: string; t: string; onJoin: Function; isMasterDetail: boolean; theme: string; } const JoinCode = React.memo( forwardRef(({ rid, t, onJoin, isMasterDetail, theme }: IRoomJoinCodeProps, ref) => { const [visible, setVisible] = useState(false); const [error, setError] = useState(false); const [code, setCode] = useState(''); const show = () => setVisible(true); const hide = () => setVisible(false); const joinRoom = async () => { try { await RocketChat.joinRoom(rid, code, t); onJoin(); hide(); } catch (e) { setError(true); } }; useImperativeHandle(ref, () => ({ show })); return ( {I18n.t('Insert_Join_Code')} InteractionManager.runAfterInteractions(() => e?.getNativeRef()?.focus())} returnKeyType='send' autoCapitalize='none' onChangeText={setCode} onSubmitEditing={joinRoom} placeholder={I18n.t('Join_Code')} secureTextEntry error={error && { error: 'error-code-invalid', reason: I18n.t('Code_or_password_invalid') }} testID='join-code-input' />