Chore: Migrate SetUsernameView to Typescript (#3526)

This commit is contained in:
Reinaldo Neto 2021-12-02 10:29:01 -03:00 committed by GitHub
parent e93a73d52d
commit afaa185fe7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 19 deletions

View File

@ -4,7 +4,7 @@ import { KeyboardAwareScrollView, KeyboardAwareScrollViewProps } from '@codler/r
import scrollPersistTaps from '../utils/scrollPersistTaps'; import scrollPersistTaps from '../utils/scrollPersistTaps';
interface IKeyboardViewProps extends KeyboardAwareScrollViewProps { interface IKeyboardViewProps extends KeyboardAwareScrollViewProps {
keyboardVerticalOffset: number; keyboardVerticalOffset?: number;
scrollEnabled?: boolean; scrollEnabled?: boolean;
children: React.ReactNode; children: React.ReactNode;
} }

View File

@ -1,8 +1,10 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import { StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
import { Dispatch } from 'redux';
import { ScrollView, StyleSheet, Text } from 'react-native'; import { ScrollView, StyleSheet, Text } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import Orientation from 'react-native-orientation-locker'; import Orientation from 'react-native-orientation-locker';
import { RouteProp } from '@react-navigation/native';
import { loginRequest as loginRequestAction } from '../actions/login'; import { loginRequest as loginRequestAction } from '../actions/login';
import TextInput from '../containers/TextInput'; import TextInput from '../containers/TextInput';
@ -27,21 +29,27 @@ const styles = StyleSheet.create({
} }
}); });
class SetUsernameView extends React.Component { interface ISetUsernameViewState {
static navigationOptions = ({ route }) => ({ username: string;
saving: boolean;
}
interface ISetUsernameViewProps {
navigation: StackNavigationProp<any, 'SetUsernameView'>;
route: RouteProp<{ SetUsernameView: { title: string } }, 'SetUsernameView'>;
server: string;
userId: string;
loginRequest: ({ resume }: { resume: string }) => void;
token: string;
theme: string;
}
class SetUsernameView extends React.Component<ISetUsernameViewProps, ISetUsernameViewState> {
static navigationOptions = ({ route }: Pick<ISetUsernameViewProps, 'route'>): StackNavigationOptions => ({
title: route.params?.title title: route.params?.title
}); });
static propTypes = { constructor(props: ISetUsernameViewProps) {
navigation: PropTypes.object,
server: PropTypes.string,
userId: PropTypes.string,
loginRequest: PropTypes.func,
token: PropTypes.string,
theme: PropTypes.string
};
constructor(props) {
super(props); super(props);
this.state = { this.state = {
username: '', username: '',
@ -61,7 +69,7 @@ class SetUsernameView extends React.Component {
} }
} }
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps: ISetUsernameViewProps, nextState: ISetUsernameViewState) {
const { username, saving } = this.state; const { username, saving } = this.state;
const { theme } = this.props; const { theme } = this.props;
if (nextProps.theme !== theme) { if (nextProps.theme !== theme) {
@ -88,7 +96,7 @@ class SetUsernameView extends React.Component {
try { try {
await RocketChat.saveUserProfile({ username }); await RocketChat.saveUserProfile({ username });
await loginRequest({ resume: token }); await loginRequest({ resume: token });
} catch (e) { } catch (e: any) {
showErrorAlert(e.message, I18n.t('Oops')); showErrorAlert(e.message, I18n.t('Oops'));
} }
this.setState({ saving: false }); this.setState({ saving: false });
@ -136,13 +144,13 @@ class SetUsernameView extends React.Component {
} }
} }
const mapStateToProps = state => ({ const mapStateToProps = (state: any) => ({
server: state.server.server, server: state.server.server,
token: getUserSelector(state).token token: getUserSelector(state).token
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = (dispatch: Dispatch) => ({
loginRequest: params => dispatch(loginRequestAction(params)) loginRequest: (params: { resume: string }) => dispatch(loginRequestAction(params))
}); });
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(SetUsernameView)); export default connect(mapStateToProps, mapDispatchToProps)(withTheme(SetUsernameView));