Chore: Migrate InviteUsersEditView to TypeScript
* chore: migrate the view InviteUsersEditView to ts * refactor: change some requestes after code review * minor tweaks Co-authored-by: Reinaldo Neto <reinaldonetof@hotmail.com>
This commit is contained in:
parent
cca66a51d6
commit
6746d674cc
|
@ -1,8 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import { TextInputProps, View } from 'react-native';
|
||||||
import { View } from 'react-native';
|
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import RNPickerSelect from 'react-native-picker-select';
|
import RNPickerSelect from 'react-native-picker-select';
|
||||||
|
import { StackNavigationOptions, StackNavigationProp } from '@react-navigation/stack';
|
||||||
|
import { RouteProp } from '@react-navigation/core';
|
||||||
|
import { Dispatch } from 'redux';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
inviteLinksCreate as inviteLinksCreateAction,
|
inviteLinksCreate as inviteLinksCreateAction,
|
||||||
|
@ -65,25 +67,29 @@ const OPTIONS = {
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
class InviteUsersView extends React.Component {
|
interface IInviteUsersEditView {
|
||||||
static navigationOptions = () => ({
|
navigation: StackNavigationProp<any, 'InviteUsersEditView'>;
|
||||||
|
route: RouteProp<{ InviteUsersEditView: { rid: string } }, 'InviteUsersEditView'>;
|
||||||
|
theme: string;
|
||||||
|
createInviteLink(rid: string): void;
|
||||||
|
inviteLinksSetParams(params: { [key: string]: number }): void;
|
||||||
|
days: number;
|
||||||
|
maxUses: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
class InviteUsersView extends React.Component<IInviteUsersEditView, any> {
|
||||||
|
static navigationOptions = (): StackNavigationOptions => ({
|
||||||
title: I18n.t('Invite_users')
|
title: I18n.t('Invite_users')
|
||||||
});
|
});
|
||||||
|
|
||||||
static propTypes = {
|
private rid: string;
|
||||||
navigation: PropTypes.object,
|
|
||||||
route: PropTypes.object,
|
|
||||||
theme: PropTypes.string,
|
|
||||||
createInviteLink: PropTypes.func,
|
|
||||||
inviteLinksSetParams: PropTypes.func
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props: IInviteUsersEditView) {
|
||||||
super(props);
|
super(props);
|
||||||
this.rid = props.route.params?.rid;
|
this.rid = props.route.params?.rid;
|
||||||
}
|
}
|
||||||
|
|
||||||
onValueChangePicker = (key, value) => {
|
onValueChangePicker = (key: string, value: number) => {
|
||||||
logEvent(events.IU_EDIT_SET_LINK_PARAM);
|
logEvent(events.IU_EDIT_SET_LINK_PARAM);
|
||||||
const { inviteLinksSetParams } = this.props;
|
const { inviteLinksSetParams } = this.props;
|
||||||
const params = {
|
const params = {
|
||||||
|
@ -99,9 +105,10 @@ class InviteUsersView extends React.Component {
|
||||||
navigation.pop();
|
navigation.pop();
|
||||||
};
|
};
|
||||||
|
|
||||||
renderPicker = (key, first) => {
|
renderPicker = (key: 'days' | 'maxUses', first: string) => {
|
||||||
const { props } = this;
|
const { props } = this;
|
||||||
const { theme } = props;
|
const { theme } = props;
|
||||||
|
const textInputStyle: TextInputProps = { style: { ...styles.pickerText, color: themes[theme].actionTintColor } };
|
||||||
const firstEl = [
|
const firstEl = [
|
||||||
{
|
{
|
||||||
label: I18n.t(first),
|
label: I18n.t(first),
|
||||||
|
@ -112,7 +119,7 @@ class InviteUsersView extends React.Component {
|
||||||
<RNPickerSelect
|
<RNPickerSelect
|
||||||
style={{ viewContainer: styles.viewContainer }}
|
style={{ viewContainer: styles.viewContainer }}
|
||||||
value={props[key]}
|
value={props[key]}
|
||||||
textInputProps={{ style: { ...styles.pickerText, color: themes[theme].actionTintColor } }}
|
textInputProps={textInputStyle}
|
||||||
useNativeAndroidPickerStyle={false}
|
useNativeAndroidPickerStyle={false}
|
||||||
placeholder={{}}
|
placeholder={{}}
|
||||||
onValueChange={value => this.onValueChangePicker(key, value)}
|
onValueChange={value => this.onValueChangePicker(key, value)}
|
||||||
|
@ -143,14 +150,14 @@ class InviteUsersView extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = state => ({
|
const mapStateToProps = (state: any) => ({
|
||||||
days: state.inviteLinks.days,
|
days: state.inviteLinks.days,
|
||||||
maxUses: state.inviteLinks.maxUses
|
maxUses: state.inviteLinks.maxUses
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => ({
|
const mapDispatchToProps = (dispatch: Dispatch) => ({
|
||||||
inviteLinksSetParams: params => dispatch(inviteLinksSetParamsAction(params)),
|
inviteLinksSetParams: (params: object) => dispatch(inviteLinksSetParamsAction(params)),
|
||||||
createInviteLink: rid => dispatch(inviteLinksCreateAction(rid))
|
createInviteLink: (rid: string) => dispatch(inviteLinksCreateAction(rid))
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(InviteUsersView));
|
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(InviteUsersView));
|
Loading…
Reference in New Issue