diff --git a/app/stacks/OutsideStack.tsx b/app/stacks/OutsideStack.tsx
index 1ae5e42f..8ffc8ae8 100644
--- a/app/stacks/OutsideStack.tsx
+++ b/app/stacks/OutsideStack.tsx
@@ -25,7 +25,7 @@ const _OutsideStack = () => {
-
+
diff --git a/app/views/ForgotPasswordView.tsx b/app/views/ForgotPasswordView.tsx
index 4602526a..ab7b94f7 100644
--- a/app/views/ForgotPasswordView.tsx
+++ b/app/views/ForgotPasswordView.tsx
@@ -1,75 +1,58 @@
-import React from 'react';
+import React, { useLayoutEffect, useState } from 'react';
import { Text } from 'react-native';
+import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
+import { StackNavigationProp } from '@react-navigation/stack';
+import { useForm } from 'react-hook-form';
+import * as yup from 'yup';
+import { yupResolver } from '@hookform/resolvers/yup';
import Button from '../containers/Button';
import FormContainer, { FormContainerInner } from '../containers/FormContainer';
-import { FormTextInput } from '../containers/TextInput';
+import { ControlledFormTextInput } from '../containers/TextInput';
import I18n from '../i18n';
-import { themes } from '../lib/constants';
import { Services } from '../lib/services';
import { OutsideParamList } from '../stacks/types';
-import { withTheme } from '../theme';
-import { showErrorAlert, isValidEmail } from '../lib/methods/helpers';
+import { useTheme } from '../theme';
+import { showErrorAlert } from '../lib/methods/helpers';
import { events, logEvent } from '../lib/methods/helpers/log';
-import { IBaseScreen } from '../definitions';
import sharedStyles from './Styles';
-interface IForgotPasswordViewState {
+const schema = yup.object().shape({
+ email: yup.string().email().required()
+});
+
+interface ISubmit {
email: string;
- invalidEmail: boolean;
- isFetching: boolean;
}
-type IForgotPasswordViewProps = IBaseScreen;
+const ForgotPasswordView = (): React.ReactElement => {
+ const {
+ control,
+ handleSubmit,
+ formState: { isValid }
+ } = useForm({ mode: 'onChange', resolver: yupResolver(schema) });
-class ForgotPasswordView extends React.Component {
- static navigationOptions = ({ route }: IForgotPasswordViewProps) => ({
- title: route.params?.title ?? 'Rocket.Chat'
- });
+ const [isFetching, setIsFetching] = useState(false);
- state = {
- email: '',
- invalidEmail: true,
- isFetching: false
- };
+ const navigation = useNavigation>();
+ const { params } = useRoute>();
+ const { colors } = useTheme();
- shouldComponentUpdate(nextProps: IForgotPasswordViewProps, nextState: IForgotPasswordViewState) {
- const { email, invalidEmail, isFetching } = this.state;
- const { theme } = this.props;
- if (nextProps.theme !== theme) {
- return true;
- }
- if (nextState.email !== email) {
- return true;
- }
- if (nextState.invalidEmail !== invalidEmail) {
- return true;
- }
- if (nextState.isFetching !== isFetching) {
- return true;
- }
- return false;
- }
+ useLayoutEffect(() => {
+ navigation.setOptions({
+ title: params?.title ?? 'Rocket.Chat'
+ });
+ }, [navigation, params?.title]);
- validate = (email: string) => {
- if (!isValidEmail(email)) {
- this.setState({ invalidEmail: true });
- return;
- }
- this.setState({ email, invalidEmail: false });
- };
-
- resetPassword = async () => {
- logEvent(events.FP_FORGOT_PASSWORD);
- const { email, invalidEmail } = this.state;
- if (invalidEmail || !email) {
+ const resetPassword = async ({ email }: ISubmit) => {
+ if (!isValid) {
return;
}
try {
- this.setState({ isFetching: true });
+ logEvent(events.FP_FORGOT_PASSWORD);
+ setIsFetching(true);
const result = await Services.forgotPassword(email);
if (result.success) {
- const { navigation } = this.props;
navigation.pop();
showErrorAlert(I18n.t('Forgot_password_If_this_email_is_registered'), I18n.t('Alert'));
}
@@ -78,41 +61,38 @@ class ForgotPasswordView extends React.Component
+
+
+ {I18n.t('Forgot_password')}
+
+
+
+
+
+ );
+};
- return (
-
-
-
- {I18n.t('Forgot_password')}
-
- this.validate(email)}
- onSubmitEditing={this.resetPassword}
- testID='forgot-password-view-email'
- containerStyle={sharedStyles.inputLastChild}
- />
-
-
-
- );
- }
-}
-
-export default withTheme(ForgotPasswordView);
+export default ForgotPasswordView;