Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added AuthComponent #9

Merged
merged 2 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/components/AuthComponent/Auth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, { useState } from 'react'
import SignIn from '../../containers/SignInContainer'
import SignUp from '../../containers/SignUpContainer'
import ForgotPassword from '../../containers/ForgotPasswordContainer'

export interface IAuthProps {
className?: string
}

const AuthComponent = ({
className = 'a6y-react-auth',
}: IAuthProps): JSX.Element => {
const [currentForm] = useState('sign-in')
const getAuthForm = (): JSX.Element => {
switch (currentForm) {
case 'sign-up':
return <SignUp />
case 'forgot-password':
return <ForgotPassword />
default:
return <SignIn />
}
}
return <div className={className}>{getAuthForm()}</div>
}

export default AuthComponent
2 changes: 2 additions & 0 deletions src/components/AuthComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Auth from './Auth'
export default Auth
4 changes: 2 additions & 2 deletions src/components/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const SignIn = ({
<ErrorBoundary showError={apiError ? true : false}>
{apiError}
</ErrorBoundary>
<EmailPasswordForm onClick={onClick} />
<FormLinks path='sign-up' />
<EmailPasswordForm submitLabel='sign in' onClick={onClick} />
<FormLinks path='sign-in' />
</div>
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/SignUp/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ export interface ISignUpProps {

const SignUp = ({
className = 'a6y-react-auth__sign-up',
onClick,
apiError,
}: ISignUpProps): JSX.Element => {
return (
<div className={className}>
<ErrorBoundary showError={apiError ? true : false}>
{apiError}
</ErrorBoundary>
<EmailPasswordForm />
<EmailPasswordForm submitLabel='sign up' onClick={onClick} />
<FormLinks path='sign-up' />
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion src/containers/SignInContainer/SignInContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const SignInContainer = ({ className }: ISignInContainerProps): JSX.Element => {
}
}
return (
<div className={className ? className : 'a6y-react-auth__sign-in'}>
<div className={className ? className : 'a6y-react-auth__sign-in-cnt'}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing to change here, just sharing my thoughts that maybe we should figure out some better naming convention for CSS classes. I believe that -cnt means the "container" here, but is it named that way because it is in SignInContainer file or because this div acts as a container/wrapper.

Maybe in the future, we will try to standardize it a bit.

<SignIn onClick={signIn} apiError={apiError} />
</div>
)
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 @@ -31,7 +31,7 @@ const SignUpContainer = ({ className }: ISignUpContainerProps): JSX.Element => {
}
}
return (
<div className={className ? className : 'a6y-react-auth__sign-up'}>
<div className={className ? className : 'a6y-react-auth__sign-up-cnt'}>
<SignUp onClick={signUp} apiError={apiError} />
</div>
)
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './components/EmailPasswordForm'
import Auth from './components/AuthComponent'
export default Auth
10 changes: 10 additions & 0 deletions src/tests/components/AuthComponent.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 AuthComponent from '../../components/AuthComponent'

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

export const AuthComponent: React.VFC<unknown> = args => <Auth {...args} />

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