[IMPROVE] - migrating the TwoFactor container

This commit is contained in:
AlexAlexandre 2021-07-23 16:33:40 -03:00
parent d5c2decfb9
commit e8b58323c7
3 changed files with 17 additions and 15 deletions

View File

@ -6,7 +6,7 @@ import { themes } from '../../constants/colors';
import sharedStyles from '../../views/Styles'; import sharedStyles from '../../views/Styles';
import ActivityIndicator from '../ActivityIndicator'; import ActivityIndicator from '../ActivityIndicator';
interface IButton { interface IButtonProps {
title: string; title: string;
type: string type: string
onPress(): void; onPress(): void;
@ -17,6 +17,7 @@ interface IButton {
color: string color: string
fontSize: any fontSize: any
style: any style: any
testID: string;
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
@ -37,7 +38,7 @@ const styles = StyleSheet.create({
} }
}); });
export default class Button extends React.PureComponent<IButton, any> { export default class Button extends React.PureComponent<Partial<IButtonProps>, any> {
render() { render() {
const { const {
@ -45,7 +46,7 @@ export default class Button extends React.PureComponent<IButton, any> {
} = this.props; } = this.props;
const isPrimary = type === 'primary'; const isPrimary = type === 'primary';
let textColor = isPrimary ? themes[theme].buttonText : themes[theme].bodyText; let textColor = isPrimary ? themes[theme!].buttonText : themes[theme!].bodyText;
if (color) { if (color) {
textColor = color; textColor = color;
} }
@ -58,7 +59,7 @@ export default class Button extends React.PureComponent<IButton, any> {
styles.container, styles.container,
backgroundColor backgroundColor
? { backgroundColor } ? { backgroundColor }
: { backgroundColor: isPrimary ? themes[theme].actionTintColor : themes[theme].backgroundColor }, : { backgroundColor: isPrimary ? themes[theme!].actionTintColor : themes[theme!].backgroundColor },
disabled && styles.disabled, disabled && styles.disabled,
style style
]} ]}

View File

@ -1,7 +1,6 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { View, Text, InteractionManager } from 'react-native'; import { View, Text, InteractionManager } from 'react-native';
import isEmpty from 'lodash/isEmpty'; import isEmpty from 'lodash/isEmpty';
import PropTypes from 'prop-types';
import { sha256 } from 'js-sha256'; import { sha256 } from 'js-sha256';
import Modal from 'react-native-modal'; import Modal from 'react-native-modal';
import useDeepCompareEffect from 'use-deep-compare-effect'; import useDeepCompareEffect from 'use-deep-compare-effect';
@ -19,7 +18,12 @@ import styles from './styles';
export const TWO_FACTOR = 'TWO_FACTOR'; export const TWO_FACTOR = 'TWO_FACTOR';
const methods = { interface ITwoFactor {
theme: string;
isMasterDetail: boolean;
}
const methods: any = {
totp: { totp: {
text: 'Open_your_authentication_app_and_enter_the_code', text: 'Open_your_authentication_app_and_enter_the_code',
keyboardType: 'numeric' keyboardType: 'numeric'
@ -36,9 +40,9 @@ const methods = {
} }
}; };
const TwoFactor = React.memo(({ theme, isMasterDetail }) => { const TwoFactor = React.memo(({ theme, isMasterDetail }: ITwoFactor) => {
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [data, setData] = useState({}); const [data, setData] = useState<any>({});
const [code, setCode] = useState(''); const [code, setCode] = useState('');
const method = methods[data.method]; const method = methods[data.method];
@ -55,7 +59,7 @@ const TwoFactor = React.memo(({ theme, isMasterDetail }) => {
} }
}, [data]); }, [data]);
const showTwoFactor = args => setData(args); const showTwoFactor = (args: any) => setData(args);
useEffect(() => { useEffect(() => {
const listener = EventEmitter.addEventListener(TWO_FACTOR, showTwoFactor); const listener = EventEmitter.addEventListener(TWO_FACTOR, showTwoFactor);
@ -86,6 +90,7 @@ const TwoFactor = React.memo(({ theme, isMasterDetail }) => {
const color = themes[theme].titleText; const color = themes[theme].titleText;
return ( return (
<Modal <Modal
//@ts-ignore
transparent transparent
avoidKeyboard avoidKeyboard
useNativeDriver useNativeDriver
@ -99,7 +104,7 @@ const TwoFactor = React.memo(({ theme, isMasterDetail }) => {
<TextInput <TextInput
value={code} value={code}
theme={theme} theme={theme}
inputRef={e => InteractionManager.runAfterInteractions(() => e?.getNativeRef()?.focus())} inputRef={(e: any) => InteractionManager.runAfterInteractions(() => e?.getNativeRef()?.focus())}
returnKeyType='send' returnKeyType='send'
autoCapitalize='none' autoCapitalize='none'
onChangeText={setCode} onChangeText={setCode}
@ -133,12 +138,8 @@ const TwoFactor = React.memo(({ theme, isMasterDetail }) => {
</Modal> </Modal>
); );
}); });
TwoFactor.propTypes = {
theme: PropTypes.string,
isMasterDetail: PropTypes.bool
};
const mapStateToProps = state => ({ const mapStateToProps = (state: any) => ({
isMasterDetail: state.app.isMasterDetail isMasterDetail: state.app.isMasterDetail
}); });