vn-verdnaturachat/app/views/RoomView/JoinCode.js

141 lines
3.2 KiB
JavaScript
Raw Normal View History

[FIX] App not prompting join code for password protected channels (#2514) * Adding joinCode parameter Co-authored-by: Vitor Leal <vitor_leal2201@hotmail.com> Co-authored-by: Fernando Aguilar <fernando.aguilar@hotmail.com.br> * Insert join code input Signed-off-by: Vitor.Leal <vitor_leal2201@hotmail.com> * Add joinCode field on db Signed-off-by: Vitor.Leal <vitor_leal2201@hotmail.com> * Add label i18 pt-br and en-us Signed-off-by: Vitor.Leal <vitor_leal2201@hotmail.com> * Add insert join code text Signed-off-by: Vitor.Leal <vitor_leal2201@hotmail.com> * Fix atribute name Signed-off-by: Vitor.Leal <vitor_leal2201@hotmail.com> * Add join text Signed-off-by: Vitor.Leal <vitor_leal2201@hotmail.com> Co-authored-by: Daniel Maike <danmke@hotmail.com> Co-authored-by: Fernando Aguilar <fernando.aguilar@hotmail.com.br> * Fix attributes joinCode, joinCodeRequired and pass attribute param in navigation Signed-off-by: Daniel Maike <danmke@hotmail.com> Co-authored-by: Vitor Leal <vitor_leal2201@hotmail.com> * Fixing attribute joinCodeRequired pass to goRoom Signed-off-by: Daniel Maike <danmke@hotmail.com> * Changed textinput style Signed-off-by: Daniel Maike <danmke@hotmail.com> Co-authored-by: Vitor Leal <vitor_leal2201@hotmail.com> * Delete not necessary attribute Signed-off-by: Daniel Maike <danmke@hotmail.com> * Fixing input style Co-authored-by: Vitor Leal <vitor_leal2201@hotmail.com> * Undo unncessary changes * use a join code modal * tests: e2e tests to join protected channel * fix: undo unnecessary change * tests: cancel join code * Remove some tests * Minor fixes Co-authored-by: Vitor Leal <vitor_leal2201@hotmail.com> Co-authored-by: Fernando Aguilar <fernando.aguilar@hotmail.com.br> Co-authored-by: Djorkaeff Alexandre <djorkaeff.unb@gmail.com> Co-authored-by: youssef-md <emaildeyoussefmuhamad@gmail.com> Co-authored-by: Diego Mello <diegolmello@gmail.com>
2020-12-01 17:30:39 +00:00
import React, {
useState,
forwardRef,
useImperativeHandle
} from 'react';
import PropTypes from 'prop-types';
import {
View,
Text,
StyleSheet,
InteractionManager
} 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
}
});
const JoinCode = React.memo(forwardRef(({
rid,
t,
onJoin,
isMasterDetail,
theme
}, 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 (
<Modal
transparent
avoidKeyboard
useNativeDriver
isVisible={visible}
hideModalContentWhileAnimating
>
<View style={styles.container} testID='join-code'>
<View style={[styles.content, isMasterDetail && [sharedStyles.modalFormSheet, styles.tablet], { backgroundColor: themes[theme].backgroundColor }]}>
<Text style={[styles.title, { color: themes[theme].titleText }]}>{I18n.t('Insert_Join_Code')}</Text>
<TextInput
value={code}
theme={theme}
inputRef={e => 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'
/>
<View style={styles.buttonContainer}>
<Button
title={I18n.t('Cancel')}
type='secondary'
style={styles.button}
backgroundColor={themes[theme].chatComponentBackground}
theme={theme}
testID='join-code-cancel'
onPress={hide}
/>
<Button
title={I18n.t('Join')}
type='primary'
style={styles.button}
theme={theme}
testID='join-code-submit'
onPress={joinRoom}
/>
</View>
</View>
</View>
</Modal>
);
}));
JoinCode.propTypes = {
rid: PropTypes.string,
t: PropTypes.string,
onJoin: PropTypes.func,
isMasterDetail: PropTypes.bool,
theme: PropTypes.string
};
const mapStateToProps = state => ({
isMasterDetail: state.app.isMasterDetail
});
export default connect(mapStateToProps, null, null, { forwardRef: true })(JoinCode);