From 646e894c3614ca4bea2410b49cceb071c5098647 Mon Sep 17 00:00:00 2001 From: Joe Buono Date: Wed, 26 Oct 2022 16:32:43 -0500 Subject: [PATCH] feat(rna): ForceNewPassword subcomponent (#2823) * basic template and stories * write tests * align styles with SignIn component * replace container with fragment * destructure translations outside component Co-authored-by: Joe Buono --- .../stories/ForceNewPassword.stories.tsx | 31 ++- .../ForceNewPassword/ForceNewPassword.tsx | 44 +++- .../__tests__/ForceNewPassword.spec.tsx | 60 ++++- .../ForceNewPassword.spec.tsx.snap | 239 +++++++++++++++++- .../Defaults/ForceNewPassword/styles.ts | 22 ++ 5 files changed, 369 insertions(+), 27 deletions(-) create mode 100644 packages/react-native/src/Authenticator/Defaults/ForceNewPassword/styles.ts diff --git a/examples/react-native/storybook/stories/ForceNewPassword.stories.tsx b/examples/react-native/storybook/stories/ForceNewPassword.stories.tsx index 8c8b76e13d5..69938551d75 100644 --- a/examples/react-native/storybook/stories/ForceNewPassword.stories.tsx +++ b/examples/react-native/storybook/stories/ForceNewPassword.stories.tsx @@ -1,11 +1,28 @@ import React from 'react'; import { storiesOf } from '@storybook/react-native'; -import { ForceNewPassword } from '@aws-amplify/ui-react-native/dist/Authenticator/Defaults'; +import { Authenticator } from '@aws-amplify/ui-react-native'; +import noop from 'lodash/noop'; -const props = {} as any; +const baseProps = { + error: null as unknown as string, + fields: [], + Footer: Authenticator.ForceNewPassword.Footer, + FormFields: Authenticator.ForceNewPassword.FormFields, + Header: Authenticator.ForceNewPassword.Header, + handleBlur: noop, + handleSubmit: (values: any) => { + console.log('Values', values); + }, + handleChange: noop, + isPending: false, + toSignIn: noop, +}; -storiesOf('ForceNewPassword', module) - .add('default', () => ) - .add('header', () => ) - .add('footer', () => ) - .add('formFields', () => ); +storiesOf('Authenticator.ForceNewPassword', module) + .add('default', () => ) + .add('with error', () => ( + + )) + .add('isPending', () => ( + + )); diff --git a/packages/react-native/src/Authenticator/Defaults/ForceNewPassword/ForceNewPassword.tsx b/packages/react-native/src/Authenticator/Defaults/ForceNewPassword/ForceNewPassword.tsx index 783482c091c..33b6d3a46bc 100644 --- a/packages/react-native/src/Authenticator/Defaults/ForceNewPassword/ForceNewPassword.tsx +++ b/packages/react-native/src/Authenticator/Defaults/ForceNewPassword/ForceNewPassword.tsx @@ -1,13 +1,45 @@ import React from 'react'; -import { Text } from 'react-native'; -import { DefaultFooter } from '../../common/DefaultFooter'; -import { DefaultHeader } from '../../common/DefaultHeader'; -import { DefaultFormFields } from '../../common/DefaultFormFields'; +import { authenticatorTextUtil } from '@aws-amplify/ui'; + +import { Button, ErrorMessage } from '../../../primitives'; +import { DefaultFooter, DefaultFormFields, DefaultHeader } from '../../common'; import { DefaultForceNewPasswordComponent } from '../types'; +import { styles } from './styles'; + +const { getChangePasswordText, getChangingText, getBackToSignInText } = + authenticatorTextUtil; -const ForceNewPassword: DefaultForceNewPasswordComponent = () => { - return ForceNewPassword; +const ForceNewPassword: DefaultForceNewPasswordComponent = ({ + error, + fields, + Footer, + FormFields, + Header, + isPending, + toSignIn, +}) => { + return ( + <> +
{getChangePasswordText()}
+ + {error ? {error} : null} + + +