Chore: Migrate LoginView to TypeScript (#3423)

* Initial commit

* Update interface

* Minor tweaks

* Update FormContainer.tsx

* Minor tweaks

* update snapshots

* Update TextInput interface

* Update snapshots

* Merge branch 'develop' into chore.migrate-loginview-ts

* Minor tweak
This commit is contained in:
Gerzon Z 2021-10-20 13:45:47 -04:00 committed by GitHub
parent 467a1a5217
commit 9922fdd7e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 49 deletions

View File

@ -76288,8 +76288,6 @@ exports[`Storyshots Text Input Short and Long Text 1`] = `
} }
> >
<Text <Text
accessibilityLabel={null}
contentDescription={null}
style={ style={
Array [ Array [
Object { Object {
@ -76321,7 +76319,6 @@ exports[`Storyshots Text Input Short and Long Text 1`] = `
allowFontScaling={true} allowFontScaling={true}
autoCapitalize="none" autoCapitalize="none"
autoCorrect={false} autoCorrect={false}
contentDescription="placeholder"
keyboardAppearance="light" keyboardAppearance="light"
placeholder="placeholder" placeholder="placeholder"
placeholderTextColor="#9ca2a8" placeholderTextColor="#9ca2a8"
@ -76374,8 +76371,6 @@ exports[`Storyshots Text Input Short and Long Text 1`] = `
} }
> >
<Text <Text
accessibilityLabel={null}
contentDescription={null}
style={ style={
Array [ Array [
Object { Object {
@ -76407,7 +76402,6 @@ exports[`Storyshots Text Input Short and Long Text 1`] = `
allowFontScaling={true} allowFontScaling={true}
autoCapitalize="none" autoCapitalize="none"
autoCorrect={false} autoCorrect={false}
contentDescription="placeholder"
keyboardAppearance="light" keyboardAppearance="light"
placeholder="placeholder" placeholder="placeholder"
placeholderTextColor="#9ca2a8" placeholderTextColor="#9ca2a8"

View File

@ -146,17 +146,10 @@ export default class RCTextInput extends React.PureComponent<IRCTextInputProps,
return ( return (
<View style={[styles.inputContainer, containerStyle]}> <View style={[styles.inputContainer, containerStyle]}>
{label ? ( {label ? (
<Text <Text style={[styles.label, { color: themes[theme].titleText }, error?.error && { color: dangerColor }]}>{label}</Text>
contentDescription={null}
// @ts-ignore
accessibilityLabel={null}
style={[styles.label, { color: themes[theme].titleText }, error?.error && { color: dangerColor }]}>
{label}
</Text>
) : null} ) : null}
<View style={styles.wrap}> <View style={styles.wrap}>
<TextInput <TextInput
/* @ts-ignore*/
style={[ style={[
styles.input, styles.input,
iconLeft && styles.inputIconLeft, iconLeft && styles.inputIconLeft,
@ -173,7 +166,6 @@ export default class RCTextInput extends React.PureComponent<IRCTextInputProps,
inputStyle inputStyle
]} ]}
ref={inputRef} ref={inputRef}
/* @ts-ignore*/
autoCorrect={false} autoCorrect={false}
autoCapitalize='none' autoCapitalize='none'
underlineColorAndroid='transparent' underlineColorAndroid='transparent'
@ -181,8 +173,6 @@ export default class RCTextInput extends React.PureComponent<IRCTextInputProps,
testID={testID} testID={testID}
accessibilityLabel={placeholder} accessibilityLabel={placeholder}
placeholder={placeholder} placeholder={placeholder}
/* @ts-ignore*/
contentDescription={placeholder}
theme={theme} theme={theme}
{...inputProps} {...inputProps}
/> />

View File

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { I18nManager, StyleSheet, TextInput, TextInputProps } from 'react-native'; import { I18nManager, StyleProp, StyleSheet, TextInput, TextInputProps, TextStyle } from 'react-native';
import { themes } from '../constants/colors'; import { themes } from '../constants/colors';
@ -10,7 +10,7 @@ const styles = StyleSheet.create({
}); });
interface IThemedTextInput extends TextInputProps { interface IThemedTextInput extends TextInputProps {
style: object; style: StyleProp<TextStyle>;
theme: string; theme: string;
} }

View File

@ -1,8 +1,9 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import { Alert, Keyboard, StyleSheet, Text, View } from 'react-native'; import { Alert, Keyboard, StyleSheet, Text, View } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { dequal } from 'dequal'; import { dequal } from 'dequal';
import { StackNavigationProp } from '@react-navigation/stack';
import { RouteProp } from '@react-navigation/core';
import Button from '../containers/Button'; import Button from '../containers/Button';
import I18n from '../i18n'; import I18n from '../i18n';
@ -46,31 +47,35 @@ const styles = StyleSheet.create({
} }
}); });
class LoginView extends React.Component { interface IProps {
static navigationOptions = ({ route, navigation }) => ({ navigation: StackNavigationProp<any>;
title: route.params?.title ?? 'Rocket.Chat', route: RouteProp<any, 'RegisterView'>;
Site_Name: string;
Accounts_RegistrationForm: string;
Accounts_RegistrationForm_LinkReplacementText: string;
Accounts_EmailOrUsernamePlaceholder: string;
Accounts_PasswordPlaceholder: string;
Accounts_PasswordReset: boolean;
Accounts_ShowFormLogin: boolean;
isFetching: boolean;
error: {
error: string;
};
failure: boolean;
theme: string;
loginRequest: Function;
inviteLinkToken: string;
}
class LoginView extends React.Component<IProps, any> {
private passwordInput: any;
static navigationOptions = ({ route, navigation }: Partial<IProps>) => ({
title: route?.params?.title ?? 'Rocket.Chat',
headerRight: () => <HeaderButton.Legal testID='login-view-more' navigation={navigation} /> headerRight: () => <HeaderButton.Legal testID='login-view-more' navigation={navigation} />
}); });
static propTypes = { constructor(props: IProps) {
navigation: PropTypes.object,
route: PropTypes.object,
Site_Name: PropTypes.string,
Accounts_RegistrationForm: PropTypes.string,
Accounts_RegistrationForm_LinkReplacementText: PropTypes.string,
Accounts_EmailOrUsernamePlaceholder: PropTypes.string,
Accounts_PasswordPlaceholder: PropTypes.string,
Accounts_PasswordReset: PropTypes.bool,
Accounts_ShowFormLogin: PropTypes.bool,
isFetching: PropTypes.bool,
error: PropTypes.object,
failure: PropTypes.bool,
theme: PropTypes.string,
loginRequest: PropTypes.func,
inviteLinkToken: PropTypes.string
};
constructor(props) {
super(props); super(props);
this.state = { this.state = {
user: props.route.params?.username ?? '', user: props.route.params?.username ?? '',
@ -78,10 +83,10 @@ class LoginView extends React.Component {
}; };
} }
UNSAFE_componentWillReceiveProps(nextProps) { UNSAFE_componentWillReceiveProps(nextProps: IProps) {
const { error } = this.props; const { error } = this.props;
if (nextProps.failure && !dequal(error, nextProps.error)) { if (nextProps.failure && !dequal(error, nextProps.error)) {
if (nextProps.error.error === 'error-invalid-email') { if (nextProps.error?.error === 'error-invalid-email') {
this.resendEmailConfirmation(); this.resendEmailConfirmation();
} else { } else {
Alert.alert(I18n.t('Oops'), I18n.t('Login_error')); Alert.alert(I18n.t('Oops'), I18n.t('Login_error'));
@ -156,7 +161,7 @@ class LoginView extends React.Component {
placeholder={Accounts_EmailOrUsernamePlaceholder || I18n.t('Username_or_email')} placeholder={Accounts_EmailOrUsernamePlaceholder || I18n.t('Username_or_email')}
keyboardType='email-address' keyboardType='email-address'
returnKeyType='next' returnKeyType='next'
onChangeText={value => this.setState({ user: value })} onChangeText={(value: string) => this.setState({ user: value })}
onSubmitEditing={() => { onSubmitEditing={() => {
this.passwordInput.focus(); this.passwordInput.focus();
}} }}
@ -176,7 +181,7 @@ class LoginView extends React.Component {
returnKeyType='send' returnKeyType='send'
secureTextEntry secureTextEntry
onSubmitEditing={this.submit} onSubmitEditing={this.submit}
onChangeText={value => this.setState({ password: value })} onChangeText={(value: string) => this.setState({ password: value })}
testID='login-view-password' testID='login-view-password'
textContentType='password' textContentType='password'
autoCompleteType='password' autoCompleteType='password'
@ -237,7 +242,7 @@ class LoginView extends React.Component {
} }
} }
const mapStateToProps = state => ({ const mapStateToProps = (state: any) => ({
server: state.server.server, server: state.server.server,
Site_Name: state.settings.Site_Name, Site_Name: state.settings.Site_Name,
Accounts_ShowFormLogin: state.settings.Accounts_ShowFormLogin, Accounts_ShowFormLogin: state.settings.Accounts_ShowFormLogin,
@ -252,8 +257,8 @@ const mapStateToProps = state => ({
inviteLinkToken: state.inviteLinks.token inviteLinkToken: state.inviteLinks.token
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = (dispatch: any) => ({
loginRequest: params => dispatch(loginRequestAction(params)) loginRequest: (params: any) => dispatch(loginRequestAction(params))
}); });
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(LoginView)); export default connect(mapStateToProps, mapDispatchToProps)(withTheme(LoginView));