Skip to content

Commit

Permalink
Merge pull request #8 from Altalogy/add/ForgotPassword
Browse files Browse the repository at this point in the history
added ForgotPassword component
  • Loading branch information
ArkuVonSymfon authored Mar 4, 2021
2 parents 65f08ca + 63e7bb4 commit eb55f6d
Show file tree
Hide file tree
Showing 13 changed files with 156 additions and 11 deletions.
74 changes: 74 additions & 0 deletions src/components/ForgotPassword/ForgotPassword.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React, { useState } from 'react'
import FormLinks from '../FormLinks'
import { ErrorBoundary, Input, Button } from '../UI'
import '../../index.css'

/**
* @typedef IForgotPasswordProps
* @props {string} [className] - the CSS classes
* @props {() => void} [onClick] - onClick handler launching after submit form
* @props {string} [apiError] - api error messages
*/

export interface IForgotPasswordProps {
className?: string
onClick?: () => void
apiError?: string
}

/**
* Renders the sign-in component
*
* @param {string} [className] - the CSS classes
* @param {() => void} [onClick] - onClick handler launching after submit form
* @param {string} [apiError] - api error messages
*
* @example
* <ForgotPassword
* className='a6y-react-auth__forgot-password'
* onClick={onClick}
* />
*/

const ForgotPassword = ({
className = 'a6y-react-auth__forgot-password',
onClick,
apiError,
}: IForgotPasswordProps): JSX.Element => {
const [forgotPasswordData, setForgotPasswordData] = useState({
email: '',
})
const onSubmit = () => {
if (onClick) onClick()
}
return (
<div className={className}>
<ErrorBoundary showError={apiError ? true : false}>
{apiError}
</ErrorBoundary>
<form className={`${className}__form`} onSubmit={onSubmit}>
<div className={`${className}-group`}>
<Input
id='email'
placeholder='Email'
typeInput='email'
label=''
onChange={(e: { target: { value: string } }) =>
setForgotPasswordData({
...forgotPasswordData,
email: e.target.value,
})
}
value={forgotPasswordData.email}
/>
</div>
<Button role='submit' style='primary'>
Reset password
</Button>
</form>
<FormLinks />
</div>
)
}

export default ForgotPassword
2 changes: 2 additions & 0 deletions src/components/ForgotPassword/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import ForgotPassword from './ForgotPassword'
export default ForgotPassword
2 changes: 1 addition & 1 deletion src/components/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import EmailPasswordForm from '../EmailPasswordForm'
import FormLinks from '../FormLinks'
import { ErrorBoundary } from '../UI'
import './SignIn.css'
import '../../index.css'

/**
* @typedef ISignInProps
Expand Down
6 changes: 0 additions & 6 deletions src/components/SignUp/SignUp.css

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/SignUp/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import EmailPasswordForm from '../EmailPasswordForm'
import FormLinks from '../FormLinks'
import { ErrorBoundary } from '../UI'
import './SignUp.css'
import '../../index.css'

/**
* @typedef ISignUpProps
Expand Down
41 changes: 41 additions & 0 deletions src/containers/ForgotPasswordContainer/ForgotPasswordContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useState } from 'react'
import ForgotPassword from '../../components/ForgotPassword'

/**
* @typedef IForgotPasswordContainerProps
* @props {string} [className] - the CSS classes
*/
export interface IForgotPasswordContainerProps {
className?: string
}

/**
* Renders the sign-in component with API call
*
* @param {string} [className] - the CSS classes
*
* @example
* <ForgotPasswordContainer
* className='a6y-react-auth__forgot-password'
* />
*/

const ForgotPasswordContainer = ({
className,
}: IForgotPasswordContainerProps): JSX.Element => {
const [apiError, setApiError] = useState(undefined)
async function signIn() {
try {
// sign in service
} catch (error) {
return setApiError(error)
}
}
return (
<div className={className ? className : 'a6y-react-auth__forgot-password'}>
<ForgotPassword onClick={signIn} apiError={apiError} />
</div>
)
}

export default ForgotPasswordContainer
2 changes: 2 additions & 0 deletions src/containers/ForgotPasswordContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import ForgotPasswordContainer from './ForgotPasswordContainer'
export default ForgotPasswordContainer
2 changes: 1 addition & 1 deletion src/containers/SignInContainer/SignInContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ISignInContainerProps {
*
* @example
* <SignInContainer
* className='a6y-react-auth-sign-in-cmp'
* className='a6y-react-auth__sign-in'
* />
*/

Expand Down
2 changes: 1 addition & 1 deletion src/containers/SignUpContainer/SignUpContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface ISignUpContainerProps {
*
* @example
* <SignUpContainer
* className='a6y-react-auth-sign-in-cmp'
* className='a6y-react-auth__sign-in'
* />
*/

Expand Down
2 changes: 1 addition & 1 deletion src/components/SignIn/SignIn.css → src/index.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.a6y-react-auth__sign-in {
.a6y-react-auth__sign-in,.a6y-react-auth__forgot-password,.a6y-react-auth__sign-up {
padding: 2rem 1rem;
max-width: 320px;
margin: auto;
Expand Down
10 changes: 10 additions & 0 deletions src/tests/components/ForgotPassword.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import { render } from '@testing-library/react'
import ForgotPassword from '../../components/ForgotPassword'

describe(`Component:ForgotPassword test`, () => {
it('renders without crashing', () => {
const rendered = render(<ForgotPassword />)
expect(rendered).toBeDefined
})
})
10 changes: 10 additions & 0 deletions src/tests/containers/ForgotPasswordContainer.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import { render } from '@testing-library/react'
import ForgotPasswordContainer from '../../containers/ForgotPasswordContainer'

describe(`Container:ForgotPasswordContainer test`, () => {
it('renders without crashing', () => {
const rendered = render(<ForgotPasswordContainer />)
expect(rendered).toBeDefined
})
})
12 changes: 12 additions & 0 deletions stories/components/ForgotPassword.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react'
import { Meta } from '@storybook/react'
import ForgotPassword from '../../src/components/ForgotPassword'

export const ForgotPasswordComponent: React.VFC<unknown> = args => (
<ForgotPassword {...args} />
)

export default {
title: 'Components/ForgotPassword',
component: ForgotPassword,
} as Meta

0 comments on commit eb55f6d

Please sign in to comment.