Skip to content

Commit

Permalink
Include password-requirements in new registration
Browse files Browse the repository at this point in the history
  • Loading branch information
rottabonus committed Nov 4, 2023
1 parent 3986fb9 commit 3492fb5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Screens/Onboarding/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const SignUp = ({ navigation }: Props) => {
onPressNext={onSignUp}
remoteAction={credentialsCheck}
onChange={resetCredentialsCheck}
isSignup
/>
</OnboardingBackground>
);
Expand Down
39 changes: 36 additions & 3 deletions src/Screens/components/LoginCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import * as RD from '@devexperts/remote-data-ts';
import * as authApi from '../../api/auth';

import * as localization from '../../localization';
import { ValidPassword } from '../../lib/validators';
import { isLeft } from 'fp-ts/lib/Either';

import Card from '../components/Card';
import fonts from '../components/fonts';
import Message from '../components/Message';
import colors from '../components/colors';

import Card from '../components/Card';
import Message from '../components/Message';
import NamedInputField from '../components/NamedInputField';
import Button from '../components/Button';
import ErrorMessage from '../components/ErrorMessage';
Expand All @@ -22,6 +25,7 @@ interface Props extends RN.ViewProps {
remoteAction: RD.RemoteData<unknown, unknown>;
getErrorMessageId: (u: unknown) => localization.MessageId;
onChange?: (credentials: authApi.Credentials) => void | undefined;
isSignup?: boolean;
}

const LoginCard = ({
Expand All @@ -32,6 +36,7 @@ const LoginCard = ({
remoteAction,
getErrorMessageId,
onChange,
isSignup = false,
style,
...viewProps
}: Props) => {
Expand All @@ -40,6 +45,16 @@ const LoginCard = ({
password: '',
});

const [isInvalidPassword, setIsInvalidPassword] =
React.useState<boolean>(false);

const handlePasswordValidate = () => {
if (isSignup) {
const passwordParsingResult = ValidPassword.decode(credentials.password);
setIsInvalidPassword(isLeft(passwordParsingResult));
}
};

const onChangeCredentials = (newCredentials: authApi.Credentials) => {
if (onChange) {
onChange(credentials);
Expand Down Expand Up @@ -75,14 +90,26 @@ const LoginCard = ({
onChangeText={onPasswordChange}
autoComplete="off"
testID="onboarding.signUp.password"
onBlur={handlePasswordValidate}
onSubmitEditing={handlePasswordValidate}
/>
{isSignup && (
<Message
style={[
styles.commonMessage,
isInvalidPassword && styles.passwordErrorMessage,
]}
id={'main.settings.account.password.requirements'}
/>
)}
</RN.View>
<ErrorMessage
style={styles.errorText}
getMessageId={getErrorMessageId}
data={remoteAction}
testID={'components.loginCard.errorMessage'}
/>

<RN.View style={styles.buttonContainer}>
<Button
messageId="onboarding.signUp.back"
Expand All @@ -98,7 +125,7 @@ const LoginCard = ({
onPress={() => onPressNext(credentials)}
badge={require('../images/arrow-right.svg')}
loading={RD.isPending(remoteAction)}
disabled={isEmptyFields}
disabled={isEmptyFields || isInvalidPassword}
testID="onboarding.signUp.button"
/>
</RN.View>
Expand All @@ -123,6 +150,12 @@ const styles = RN.StyleSheet.create({
input: {
marginBottom: 10,
},
commonMessage: {
...fonts.regular,
},
passwordErrorMessage: {
color: colors.danger,
},
errorText: {
marginBottom: 16,
},
Expand Down

0 comments on commit 3492fb5

Please sign in to comment.