Skip to content

Commit a130303

Browse files
ErikCHErik Hanchett
andauthored
fix: Add missing translation for force new password page (#1859)
* Added new missing translation * Added changeset * Removed un-used variable, and spacing * Fixed changeset Co-authored-by: Erik Hanchett <[email protected]>
1 parent 2f6adb4 commit a130303

File tree

9 files changed

+66
-15
lines changed

9 files changed

+66
-15
lines changed

.changeset/tasty-tables-walk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/ui-react': patch
3+
---
4+
5+
Added a translatable text for errors on the Force new password page

examples/angular/src/pages/ui/components/authenticator/sign-in-with-phone/sign-in-with-phone.component.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
22

3-
import { Amplify } from 'aws-amplify';
3+
import { Amplify, I18n } from 'aws-amplify';
4+
import { translations } from '@aws-amplify/ui-angular';
45
import awsExports from './aws-exports';
56

67
@Component({
78
selector: 'sign-in-with-phone',
89
templateUrl: 'sign-in-with-phone.component.html',
910
})
10-
export class SignInWithPhoneComponent {
11+
export class SignInWithPhoneComponent implements OnInit {
1112
constructor() {
1213
Amplify.configure(awsExports);
1314
}
1415

16+
ngOnInit(): void {
17+
I18n.putVocabularies(translations);
18+
I18n.setLanguage('en');
19+
I18n.putVocabulariesForLanguage('en', {
20+
'Password does not conform to policy: Password not long enough':
21+
'Your password is too short! Try a longer password!',
22+
});
23+
}
24+
1525
public formFields = {
1626
signIn: {
1727
username: {

examples/next/pages/ui/components/authenticator/sign-in-with-phone/index.page.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import { Amplify } from 'aws-amplify';
1+
import { Amplify, I18n } from 'aws-amplify';
22

3-
import { withAuthenticator } from '@aws-amplify/ui-react';
3+
import { withAuthenticator, translations } from '@aws-amplify/ui-react';
44
import '@aws-amplify/ui-react/styles.css';
55

66
import awsExports from './aws-exports';
77
Amplify.configure(awsExports);
88

9+
I18n.putVocabularies(translations);
10+
I18n.setLanguage('en');
11+
I18n.putVocabulariesForLanguage('en', {
12+
'Password does not conform to policy: Password not long enough':
13+
'Your password is too short! Try a longer password!',
14+
});
15+
916
const formFields = {
1017
signIn: {
1118
username: {

examples/vue/src/pages/ui/components/authenticator/sign-in-with-phone/index.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<script setup lang="ts">
2-
import Amplify from 'aws-amplify';
3-
import { Authenticator } from '@aws-amplify/ui-vue';
2+
import { Amplify, I18n } from 'aws-amplify';
3+
import { Authenticator, translations } from '@aws-amplify/ui-vue';
44
import '@aws-amplify/ui-vue/styles.css';
55
import aws_exports from './aws-exports';
66
77
Amplify.configure(aws_exports);
88
9+
I18n.putVocabularies(translations);
10+
I18n.setLanguage('en');
11+
I18n.putVocabulariesForLanguage('en', {
12+
'Password does not conform to policy: Password not long enough':
13+
'Your password is too short! Try a longer password!',
14+
});
15+
916
const formFields = {
1017
signIn: {
1118
username: {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"__type": "InvalidPasswordException",
3+
"message": "Password does not conform to policy: Password not long enough"
4+
}

packages/e2e/cypress/integration/common/shared.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ When('I type an invalid password', () => {
114114
cy.findInputField('Password').type('invalidpass');
115115
});
116116

117+
When('I type a short password', () => {
118+
cy.findInputField('Password').type('inv');
119+
});
120+
117121
When('I type an invalid wrong complexity password', () => {
118122
cy.findInputField('Password').type('inv');
119123
});

packages/e2e/cypress/integration/common/sign-up.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ When('I confirm my password', () => {
1313
.wait(100);
1414
});
1515

16+
When('I confirm my short password', () => {
17+
cy.findInputField('Confirm Password').type('inv').blur().wait(100);
18+
});
19+
1620
Then('I see {string} as an input field', (name: string) => {
1721
cy.findByRole('textbox', { name }).should('exist');
1822
});

packages/e2e/features/ui/components/authenticator/sign-in-force-new-password.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ Feature: Sign In with Force New Password flow
77
Given I'm running the example "ui/components/authenticator/sign-in-with-phone"
88
Given I intercept '{ "headers": { "X-Amz-Target": "AWSCognitoIdentityProviderService.RespondToAuthChallenge" } }' with fixture "force-change-password"
99

10+
11+
@angular @react @vue
12+
Scenario: User is in a FORCE_CHANGE_PASSWORD state and gets an error that's translated
13+
When I select my country code with status "FORCE_CHANGE_PASSWORD"
14+
And I type my "phone number" with status "FORCE_CHANGE_PASSWORD"
15+
And I type my password
16+
And I click the "Sign in" button
17+
Then I should see the Force Change Password screen
18+
And I type a short password
19+
And I confirm my short password
20+
Given I intercept '{ "headers": { "X-Amz-Target": "AWSCognitoIdentityProviderService.RespondToAuthChallenge" } }' with error fixture "force-change-password-phone-failure"
21+
Then I click the "Change Password" button
22+
Then I see "Your password is too short! Try a longer password!"
23+
1024
@angular @react @vue
1125
Scenario: Back to Sign In works in the FORCE_CHANGE_PASSWORD state
1226
When I select my country code with status "FORCE_CHANGE_PASSWORD"

packages/react/src/components/Authenticator/ForceNewPassword/ForceNewPassword.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { translate } from '@aws-amplify/ui';
33
import { Button } from '../../../primitives/Button';
44
import { Flex } from '../../../primitives/Flex';
55
import { Heading } from '../../../primitives/Heading';
6-
import { Text } from '../../../primitives/Text';
6+
import { RemoteErrorMessage } from '../shared/RemoteErrorMessage';
77
import { useAuthenticator } from '../hooks/useAuthenticator';
88
import { useCustomComponents } from '../hooks/useCustomComponents';
99
import { useFormHandlers } from '../hooks/useFormHandlers';
@@ -14,8 +14,7 @@ export const ForceNewPassword = ({
1414
className,
1515
variation,
1616
}: RouteProps): JSX.Element => {
17-
const { error, isPending, toSignIn } = useAuthenticator((context) => [
18-
context.error,
17+
const { isPending, toSignIn } = useAuthenticator((context) => [
1918
context.isPending,
2019
context.toSignIn,
2120
]);
@@ -41,11 +40,8 @@ export const ForceNewPassword = ({
4140
<Heading level={3}>{translate('Change Password')}</Heading>
4241

4342
<FormFields />
44-
{error && (
45-
<Text className="forceNewPasswordErrorText" variation="error">
46-
{error}
47-
</Text>
48-
)}
43+
44+
<RemoteErrorMessage />
4945
<Button
5046
isDisabled={isPending}
5147
type="submit"

0 commit comments

Comments
 (0)