diff --git a/src/components/checkbox/view/checkboxView.js b/src/components/checkbox/view/checkboxView.js index 824f5591a..52239a213 100644 --- a/src/components/checkbox/view/checkboxView.js +++ b/src/components/checkbox/view/checkboxView.js @@ -1,45 +1,34 @@ -import React, { Component } from 'react'; +import React, { useState } from 'react'; import { View, TouchableOpacity } from 'react-native'; import styles from './checkboxStyles'; -class CheckBoxView extends Component { - constructor(props) { - super(props); - this.state = { isCheck: false }; - } +const CheckBoxView = ({ clicked, value, isChecked, style, locked }) => { + const [isCheck, setIsCheck] = useState(false); - _checkClicked = async () => { - const { clicked, value } = this.props; + const _checkClicked = () => { + setIsCheck(!isCheck); - await this.setState(prevState => ({ - isCheck: !prevState.isCheck, - })); - - const { isCheck } = this.state; - - if (clicked) clicked(value, isCheck); + if (clicked) { + clicked(value, !isCheck); + } }; - render() { - const { style, isChecked, locked } = this.props; - const { isCheck } = this.state; - - if (locked) { - return ( - - - - ); - } + if (locked) { return ( - - - - - + + + ); } -} + + return ( + + + + + + ); +}; export default CheckBoxView; diff --git a/src/components/errorBoundary/index.js b/src/components/errorBoundary/index.js deleted file mode 100644 index 8ada838b3..000000000 --- a/src/components/errorBoundary/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import ErrorBoundary from './view/errorBoundaryView'; - -export { ErrorBoundary }; diff --git a/src/components/errorBoundary/view/errorBoundaryView.js b/src/components/errorBoundary/view/errorBoundaryView.js deleted file mode 100644 index 87f835edd..000000000 --- a/src/components/errorBoundary/view/errorBoundaryView.js +++ /dev/null @@ -1,32 +0,0 @@ -import React, { Component, Fragment } from 'react'; -import Text from 'react-native'; - -export default class ErrorBoundary extends Component { - constructor(props) { - super(props); - this.state = { hasError: false }; - } - - componentDidCatch(error, info) { - if (__DEV__) { - return; - } - this.setState({ hasError: true, info, error }); - } - - render() { - const { hasError, info, error } = this.state; - const { children } = this.props; - - if (hasError) { - return ( - - Something went wrong. - {error} - {info} - - ); - } - return children; - } -} diff --git a/src/index.js b/src/index.js index f4b57b5a6..b4a8bdc2e 100755 --- a/src/index.js +++ b/src/index.js @@ -3,6 +3,7 @@ import { Provider, connect } from 'react-redux'; import { PersistGate } from 'redux-persist/integration/react'; import { IntlProvider } from 'react-intl'; import { useScreens } from 'react-native-screens'; +import { setTopLevelNavigator } from './navigation/service'; import { flattenMessages } from './utils/flattenMessages'; import messages from './config/locales'; @@ -29,7 +30,11 @@ const App = connect(mapStateToProps)(_renderApp); export default () => { return ( - + { + setTopLevelNavigator(navigatorRef); + }} + /> ); }; diff --git a/src/navigation/service.js b/src/navigation/service.js new file mode 100644 index 000000000..8cec6cc7c --- /dev/null +++ b/src/navigation/service.js @@ -0,0 +1,16 @@ +import { NavigationActions } from 'react-navigation'; + +let _navigator; + +export const setTopLevelNavigator = navigatorRef => { + _navigator = navigatorRef; +}; + +export const navigate = (routeName, params) => { + _navigator.dispatch( + NavigationActions.navigate({ + routeName, + params, + }), + ); +}; diff --git a/src/screens/pinCode/screen/pinCodeScreen.js b/src/screens/pinCode/screen/pinCodeScreen.js index d721ca375..2271b600c 100644 --- a/src/screens/pinCode/screen/pinCodeScreen.js +++ b/src/screens/pinCode/screen/pinCodeScreen.js @@ -1,4 +1,6 @@ -import React, { PureComponent } from 'react'; +import React, { useState } from 'react'; +import { useIntl } from 'react-intl'; + import { Text, TouchableOpacity, View } from 'react-native'; import { NumericKeyboard, PinAnimatedInput } from '../../../components'; @@ -6,84 +8,72 @@ import { UserAvatar } from '../../../components'; import styles from './pinCodeStyles'; -class PinCodeScreen extends PureComponent { - constructor(props) { - super(props); - this.state = { - pin: '', - loading: false, - }; - } +const PinCodeScreen = ({ + informationText, + showForgotButton, + username, + handleForgotButton, + setPinCode, +}) => { + const [pin, setPin] = useState(''); + const [loading, setLoading] = useState(false); + const intl = useIntl(); - // Component Life Cycles - - // Component Functions - - _handleKeyboardOnPress = async value => { - const { setPinCode } = this.props; - const { pin, loading } = this.state; + const _handleKeyboardOnPress = async value => { if (loading) { return; } if (value === 'clear') { - this.setState({ pin: '' }); + setPin(''); return; } const newPin = `${pin}${value}`; if (pin.length < 3) { - this.setState({ pin: newPin }); + setPin(newPin); } else if (pin.length === 3) { - await this.setState({ pin: newPin, loading: true }); + await setPin(newPin); + await setLoading(true); - setPinCode(`${pin}${value}`) - .then(() => { - // TODO: fix unmounted component error - this.setState({ pin: '', loading: false }); - }) - .catch(() => { - this.setState({ pin: '', loading: false }); - }); + await setPinCode(`${pin}${value}`); + + setPin(''); + setLoading(false); } else if (pin.length > 3) { - this.setState({ pin: `${value}` }); + setPin(`${value}`); } }; - render() { - const { informationText, showForgotButton, username, intl, handleForgotButton } = this.props; - const { pin, loading } = this.state; - - return ( - - - - - - {`@${username}`} - - - {informationText} - - - - - - - - {showForgotButton ? ( - handleForgotButton()} style={styles.forgotButtonView}> - - {intl.formatMessage({ - id: 'pincode.forgot_text', - })} - - - ) : ( - - )} + return ( + + + - ); - } -} + + {`@${username}`} + + + {informationText} + + + + + + + + {showForgotButton ? ( + handleForgotButton()} style={styles.forgotButtonView}> + + {intl.formatMessage({ + id: 'pincode.forgot_text', + })} + + + ) : ( + + )} + + ); +}; export default PinCodeScreen; diff --git a/src/screens/points/container/pointsContainer.js b/src/screens/points/container/pointsContainer.js index be15ae363..17f6909dd 100644 --- a/src/screens/points/container/pointsContainer.js +++ b/src/screens/points/container/pointsContainer.js @@ -1,4 +1,4 @@ -import React, { PureComponent } from 'react'; +import React from 'react'; import { connect } from 'react-redux'; // Component @@ -7,33 +7,14 @@ import PointsScreen from '../screen/pointsScreen'; // Constants import ROUTES from '../../../constants/routeNames'; -/* - * Props Name Description Value - *@props --> props name here description here Value Type Here - * - */ - -class PointsContainer extends PureComponent { - constructor(props) { - super(props); - this.state = {}; - } - - // Component Life Cycle Functions - - // Component Functions - _handleOnPressLogin = () => { - const { navigation } = this.props; - +const PointsContainer = ({ isLoggedIn, navigation }) => { + const _handleOnPressLogin = () => { navigation.navigate(ROUTES.SCREENS.LOGIN); }; - render() { - const { isLoggedIn } = this.props; + return ; +}; - return ; - } -} const matStateToProps = state => ({ isLoggedIn: state.application.isLoggedIn, }); diff --git a/src/screens/points/screen/pointsScreen.js b/src/screens/points/screen/pointsScreen.js index bff67694d..1118d0d3f 100644 --- a/src/screens/points/screen/pointsScreen.js +++ b/src/screens/points/screen/pointsScreen.js @@ -1,6 +1,6 @@ -import React, { PureComponent, Fragment } from 'react'; -import { injectIntl } from 'react-intl'; -import { View, SafeAreaView } from 'react-native'; +import React, { Fragment } from 'react'; +import { useIntl } from 'react-intl'; +import { SafeAreaView } from 'react-native'; // Containers import { PointsContainer } from '../../../containers'; @@ -11,68 +11,52 @@ import { Header, Points, NoPost } from '../../../components'; // Styles import styles from './pointsStyles'; -class PointsScreen extends PureComponent { - /* Props - * ------------------------------------------------ - * @prop { type } name - Description.... - */ +const PointsScreen = ({ isLoggedIn, handleLoginPress }) => { + const intl = useIntl(); - constructor(props) { - super(props); - this.state = {}; - } + return ( + +
+ + {isLoggedIn ? ( + + {({ + handleOnDropdownSelected, + claimPoints, + fetchUserActivity, + isClaiming, + isDarkTheme, + isLoading, + refreshing, + userActivities, + userPoints, + }) => ( + + )} + + ) : ( + + )} + + + ); +}; - // Component Life Cycles - - // Component Functions - - render() { - const { intl, isLoggedIn, handleLoginPress } = this.props; - - return ( - -
- - {isLoggedIn ? ( - - {({ - handleOnDropdownSelected, - claimPoints, - fetchUserActivity, - isClaiming, - isDarkTheme, - isLoading, - refreshing, - userActivities, - userPoints, - }) => ( - - )} - - ) : ( - - )} - - - ); - } -} - -export default injectIntl(PointsScreen); +export default PointsScreen;