-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Altalogy/add/ForgotPassword
added ForgotPassword component
- Loading branch information
Showing
13 changed files
with
156 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import ForgotPassword from './ForgotPassword' | ||
export default ForgotPassword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/containers/ForgotPasswordContainer/ForgotPasswordContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import ForgotPasswordContainer from './ForgotPasswordContainer' | ||
export default ForgotPasswordContainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |