Skip to content

Commit

Permalink
merge fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ArkuVonSymfon committed Mar 8, 2021
2 parents 7f40e10 + ac83cce commit 0a27c93
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 26 deletions.
23 changes: 19 additions & 4 deletions src/components/AuthComponent/AuthComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,30 @@ const AuthComponent = ({
className = 'a6y-react-auth',
onSuccess,
}: IAuthProps): JSX.Element => {
const [currentForm] = useState('sign-in')
const [currentForm, setCurrentForm] = useState('/sign-in')
const getAuthForm = (): JSX.Element => {
switch (currentForm) {
case 'sign-up':
return <SignUp onSuccess={onSuccess ? onSuccess : undefined} />
return (
<SignUp
onSuccess={onSuccess ? onSuccess : undefined}
onLinkHandler={(to: string) => setCurrentForm(to)}
/>
)
case 'forgot-password':
return <ForgotPassword onSuccess={onSuccess ? onSuccess : undefined} />
return (
<ForgotPassword
onSuccess={onSuccess ? onSuccess : undefined}
onLinkHandler={(to: string) => setCurrentForm(to)}
/>
)
default:
return <SignIn onSuccess={onSuccess ? onSuccess : undefined} />
return (
<SignIn
onSuccess={onSuccess ? onSuccess : undefined}
onLinkHandler={(to: string) => setCurrentForm(to)}
/>
)
}
}
return <div className={className}>{getAuthForm()}</div>
Expand Down
6 changes: 5 additions & 1 deletion src/components/ForgotPassword/ForgotPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import '../../index.css'
* @props {string} [className] - the CSS classes
* @props {(email: string) => void} [onClick] - onClick handler launching after submit form
* @props {string} [apiError] - api error messages
* @props {(to: string) => void} [onLinkHandler] - links onClick handler
*/

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

/**
Expand All @@ -22,6 +24,7 @@ export interface IForgotPasswordProps {
* @param {string} [className] - the CSS classes
* @param {(email: string) => void} [onClick] - onClick handler launching after submit form
* @param {string} [apiError] - api error messages
* @param {(to: string) => void} [onLinkHandler] - links onClick handler
*
* @example
* <ForgotPassword
Expand All @@ -34,6 +37,7 @@ const ForgotPassword = ({
className = 'a6y-react-auth__forgot-password',
onClick,
apiError,
onLinkHandler,
}: IForgotPasswordProps): JSX.Element => {
const [forgotPasswordData, setForgotPasswordData] = useState({
email: '',
Expand Down Expand Up @@ -66,7 +70,7 @@ const ForgotPassword = ({
Reset password
</Button>
</form>
<FormLinks />
<FormLinks onLinkHandler={onLinkHandler} />
</div>
)
}
Expand Down
45 changes: 39 additions & 6 deletions src/components/FormLinks/FormLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,38 @@ import './FormLinks.css'
* @typedef IFormLinksProps
* @props {string} [className] - the CSS classes
* @props {string} [path] - the name of route path
* @props {(to: string) => void} [onLinkHandler] - links onClick handler
*/

export interface IFormLinksProps {
className?: string
path?: string
onLinkHandler?: (to: string) => void
}

/**
* Renders form component with links
*
* @param {string} [className] - the CSS classes
* @param {string} [path] - the name of route path
* @param {(to: string) => void} [onLinkHandler] - links onClick handler
*
* @example
* <FormLinks path='sign-in' className='a6y-react-auth-form' />
* <FormLinks onLinkHandler={() => void} path='sign-in' className='a6y-react-auth-form' />
*/

const FormLinks = ({
className = 'a6y-react-auth__form',
path,
onLinkHandler,
}: IFormLinksProps): JSX.Element => {
function renderLinks(): JSX.Element {
const ForgotPassword = (): JSX.Element => (
<Link className={className + '__link'} to='/forgot-password'>
const ForgotPassword = (
<Link
onClick={onLinkHandler}
className={className + '__link'}
to='/forgot-password'
>
Forgot Password
</Link>
)
Expand All @@ -38,7 +46,11 @@ const FormLinks = ({
return (
<>
{ForgotPassword}
<Link className={className + '__link'} to='/sign-up'>
<Link
onClick={onLinkHandler}
className={className + '__link'}
to='/sign-up'
>
Sign Up
</Link>
</>
Expand All @@ -47,13 +59,34 @@ const FormLinks = ({
return (
<>
{ForgotPassword}
<Link className={className + '__link'} to='/sign-in'>
<Link
onClick={onLinkHandler}
className={className + '__link'}
to='/sign-in'
>
Sign In
</Link>
</>
)
default:
return <>{ForgotPassword}</>
return (
<>
<Link
onClick={onLinkHandler}
className={className + '__link'}
to='/sign-in'
>
Sign In
</Link>
<Link
onClick={onLinkHandler}
className={className + '__link'}
to='/sign-up'
>
Sign Up
</Link>
</>
)
}
}
return <div className={className + '__links'}>{renderLinks()}</div>
Expand Down
7 changes: 6 additions & 1 deletion src/components/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import '../../index.css'
* @props {string} [className] - the CSS classes
* @props {(email: string, password: string) => void} [onClick] - onClick handler launching after submit form
* @props {string} [apiError] - api error messages
* @props {(to: string) => void} [onLinkHandler] - links onClick handler
*/

export interface ISignInProps {
className?: string
onClick?: (email: string, password: string) => void
apiError?: string
onLinkHandler?: (to: string) => void
}

/**
Expand All @@ -23,26 +25,29 @@ export interface ISignInProps {
* @param {string} [className] - the CSS classes
* @param {(email: string, password: string) => void} [onClick] - onClick handler launching after submit form
* @param {string} [apiError] - api error messages
* @param {(to: string) => void} [onLinkHandler] - links onClick handler
*
* @example
* <SignIn
* className='a6y-react-auth__sign-in'
* onClick={onClick}
* onLinkHandler={onLinkHandler}
* />
*/

const SignIn = ({
className = 'a6y-react-auth__sign-in',
onClick,
apiError,
onLinkHandler = undefined,
}: ISignInProps): JSX.Element => {
return (
<div className={className}>
<ErrorBoundary showError={apiError ? true : false}>
{apiError}
</ErrorBoundary>
<EmailPasswordForm submitLabel='sign in' onClick={onClick} />
<FormLinks path='sign-in' />
<FormLinks onLinkHandler={onLinkHandler} path='sign-in' />
</div>
)
}
Expand Down
7 changes: 6 additions & 1 deletion src/components/SignUp/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import '../../index.css'
* @props {string} [className] - the CSS classes
* @props {(email: string, password: string) => void} [onClick] - onClick handler launching after submit form
* @props {string} [apiError] - api error messages
* @props {(to: string) => void} [onLinkHandler] - links onClick handler
*/

export interface ISignUpProps {
className?: string
onClick?: (email: string, password: string) => void
apiError?: string
onLinkHandler?: (to: string) => void
}

/**
Expand All @@ -23,26 +25,29 @@ export interface ISignUpProps {
* @param {string} [className] - the CSS classes
* @param {(email: string, password: string) => void} [onClick] - onClick handler launching after submit form
* @param {string} [apiError] - api error messages
* @param {(to: string) => void} [onLinkHandler] - links onClick handler
*
* @example
* <SignUp
* className='a6y-react-auth__sign-up'
* onClick={onClick}
* onLinkHandler={onLinkHandler}
* />
*/

const SignUp = ({
className = 'a6y-react-auth__sign-up',
onClick,
apiError,
onLinkHandler = undefined,
}: ISignUpProps): JSX.Element => {
return (
<div className={className}>
<ErrorBoundary showError={apiError ? true : false}>
{apiError}
</ErrorBoundary>
<EmailPasswordForm submitLabel='sign up' onClick={onClick} />
<FormLinks path='sign-up' />
<FormLinks onLinkHandler={onLinkHandler} path='sign-up' />
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/UI/Button/Button.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ button.a6y-react-auth__button {
margin: 1rem auto;
}

button:hover {
button.a6y-react-auth__button:hover {
opacity: .7;
}

Expand Down
14 changes: 11 additions & 3 deletions src/components/UI/Link/Link.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
a.a6y-react-auth__form__link--primary {
.a6y-react-auth__form__link--primary {
color: #2f5ef7;
background: transparent;
border: none;
}
a.a6y-react-auth__form__link--secondary {
.a6y-react-auth__form__link--secondary {
color: #172232;
background: transparent;
border: none;
}
a.a6y-react-auth__form__link {
.a6y-react-auth__form__link {
letter-spacing: normal;
font-size: .9rem;
margin: 5px 0;
cursor: pointer;
text-decoration: underline;
width: fit-content;
font-family: inherit;
}
13 changes: 8 additions & 5 deletions src/components/UI/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import './Link.css'
export interface ILinkProps {
children: React.ReactNode
className?: string
onClick?: () => void
onClick?: (to: string) => void
to: string
underline?: 'none' | 'hover' | 'always'
style?: 'primary' | 'secondary' | 'custom'
Expand Down Expand Up @@ -52,16 +52,19 @@ const Link = ({
[`${className}--${style}`]: style ? true : false,
})

function handleLinkClick(e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) {
function handleLinkClick(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) {
e.preventDefault()
e.stopPropagation()
if (onClick) onClick()
if (onClick) onClick(to)
}
if (onClick) {
return (
<a href='#' onClick={e => handleLinkClick(e)} className={LinkClass}>
<button
onClick={e => handleLinkClick(e)}
className={className + ' ' + LinkClass}
>
{children}
</a>
</button>
)
}
return (
Expand Down
15 changes: 13 additions & 2 deletions src/containers/ForgotPasswordContainer/ForgotPasswordContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ import AuthService from '../../services/AuthService'
* @typedef IForgotPasswordContainerProps
* @props {string} [className] - the CSS classes
* @props {(response: unknown) => void} [onSuccess] - onSuccess call function
* @props {(to: string) => void} [onLinkHandler] - links onClick handler
*/

export interface IForgotPasswordContainerProps {
className?: string
onSuccess?: (response: unknown) => void
onLinkHandler?: (to: string) => void
}

/**
* Renders the sign-in component with API call
*
* @param {string} [className] - the CSS classes
* @param {(response: unknown) => void} [onSuccess] - onSuccess call function
* @param {(to: string) => void} [onLinkHandler] - links onClick handler
*
* @example
* <ForgotPasswordContainer
Expand All @@ -28,6 +32,7 @@ export interface IForgotPasswordContainerProps {
const ForgotPasswordContainer = ({
className,
onSuccess,
onLinkHandler = undefined,
}: IForgotPasswordContainerProps): JSX.Element => {
const [apiError, setApiError] = useState(undefined)
async function forgotPassword(email: string) {
Expand All @@ -44,8 +49,14 @@ const ForgotPasswordContainer = ({
}
}
return (
<div className={className ? className : 'a6y-react-auth__forgot-password'}>
<ForgotPassword onClick={forgotPassword} apiError={apiError} />
<div
className={className ? className : 'a6y-react-auth__forgot-password-cnt'}
>
<ForgotPassword
onLinkHandler={onLinkHandler}
onClick={forgotPassword}
apiError={apiError}
/>
</div>
)
}
Expand Down
Loading

0 comments on commit 0a27c93

Please sign in to comment.