Skip to content

Commit

Permalink
Fix Settings Screen PasswordForm
Browse files Browse the repository at this point in the history
  • Loading branch information
rottabonus committed Dec 10, 2023
1 parent c8f9b77 commit 5da0ca7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
24 changes: 5 additions & 19 deletions src/Screens/Main/Settings/Password/PasswordForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import {
PasswordState,
} from './getState';

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

import Button from '../../../components/Button';
import NamedInputField from '../../../components/NamedInputField';
import IconButton from '../../../components/IconButton';
import Message from '../../../components/Message';
import InfoBox from 'src/Screens/components/InfoBox';

type Props = {
currentPassword: string;
Expand Down Expand Up @@ -68,7 +65,9 @@ export default (props: Props) => {
isPasswordInput={true}
value={props.newPassword}
onChangeText={value => handleChange(props.setNewPassword, value)}
onBlur={handlePasswordValidate}
testID="main.settings.account.password.new"
isError={passwordState.first}
/>
<NamedInputField
style={styles.field}
Expand All @@ -78,18 +77,12 @@ export default (props: Props) => {
onChangeText={value =>
handleChange(props.setRepeatedNewPassword, value)
}
onBlur={handlePasswordValidate}
onSubmitEditing={handlePasswordValidate}
testID="main.settings.account.password.repeat"
isError={passwordState.second}
/>
<InfoBox messageId={passwordState.messageId} />
</RN.View>
<Message
style={[
styles.commonMessage,
!passwordState.isOkay && styles.errorMessage,
]}
id={passwordState.messageId}
/>
<RN.View style={styles.buttonContainer}>
<IconButton
badge={require('../../../images/chevron-left.svg')}
Expand Down Expand Up @@ -127,13 +120,6 @@ const styles = RN.StyleSheet.create({
marginVertical: 24,
gap: 24,
},
commonMessage: {
...fonts.regular,
marginBottom: -24,
},
errorMessage: {
color: colors.danger,
},
badge: {
width: 32,
height: 32,
Expand Down
17 changes: 13 additions & 4 deletions src/Screens/Main/Settings/Password/getState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { MessageId } from '../../../../localization';
import { ValidPassword } from '../../../../lib/validators';
import { isRight } from 'fp-ts/lib/Either';

export type PasswordState = { isOkay: boolean; messageId: MessageId };
export type PasswordState = {
isOkay: boolean;
messageId: MessageId;
first?: boolean;
second?: boolean;
};

export const passwordRequirementsMessage = {
messageId: 'main.settings.account.password.requirements',
Expand All @@ -23,18 +28,22 @@ export const getPasswordState = (
)
return {
isOkay: true,
first: false,
second: false,
...passwordRequirementsMessage,
};

if (newPassword !== repeatedNewPassword) {
if (!isValidPassword) {
return {
isOkay: false,
messageId: 'main.settings.account.password.invalid.same',
first: true,
...passwordRequirementsMessage,
};
}

return {
isOkay: false,
...passwordRequirementsMessage,
second: true,
messageId: 'main.settings.account.password.invalid.same',
};
};
1 change: 1 addition & 0 deletions src/Screens/components/InfoBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const styles = RN.StyleSheet.create({
infoBox: {
padding: 16,
backgroundColor: colors.whiteBlue,
flex: 1,
},
infoText: {
...fonts.subtitle,
Expand Down

0 comments on commit 5da0ca7

Please sign in to comment.