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

Fix/demo routes #17

Merged
merged 3 commits into from
Mar 12, 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
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Authentication forms for React.

[Demo](https://altalogy.github.io/a6y-react-auth/#/)

## **Getting Started**

**1) Install:**
Expand Down Expand Up @@ -71,7 +73,7 @@ param | type | description
--- | --- | ---
className[optional] | string | the CSS classes
onSuccess[optional]] | (response: unknown) => void | onSuccess callback function
onLinkHandler[optional] | it's a link callback function to redirect the app. If not declared it's using by pathname `/sign-in`
onLinkHandler[optional] | it's a link callback function to redirect the app. If not declared it's using by pathname `sign-in`


**example**
Expand All @@ -89,7 +91,7 @@ param | type | description
--- | --- | ---
className[optional] | string | the CSS classes
onSuccess[optional]] | (response: unknown) => void | onSuccess callback function
onLinkHandler[optional] | it's a link callback function to redirect the app. If not declared it's using by pathname `/sign-up`
onLinkHandler[optional] | it's a link callback function to redirect the app. If not declared it's using by pathname `sign-up`


**example**
Expand All @@ -108,7 +110,7 @@ param | type | description
--- | --- | ---
className[optional] | string | the CSS classes
onSuccess[optional]] | (response: unknown) => void | onSuccess callback function
onLinkHandler[optional] | (to: string) => void | it's a link callback function to redirect the app. If not declared it's using by pathname `/forgot-password`
onLinkHandler[optional] | (to: string) => void | it's a link callback function to redirect the app. If not declared it's using by pathname `forgot-password`


**example**
Expand All @@ -125,7 +127,7 @@ onLinkHandler[optional] | (to: string) => void | it's a link callback function t

### Getting started

1. Clone repository with `git clone`
1. Clone repository with `git clone` and go to `cd a6y-react-auth`

2. Install:
```
Expand All @@ -139,6 +141,10 @@ $ npm link
```
Full docs here: [npm-link](https://docs.npmjs.com/cli/v7/commands/npm-link)

4. Then go to `/demo` and run `npm install && npm start`

Open [http://localhost:3000](http://localhost:3000) to view it in the browser.


### Storybook
**build**
Expand Down
3 changes: 1 addition & 2 deletions a6y-react-auth/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions a6y-react-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "a6y-react-auth",
"version": "0.0.1",
"version": "0.0.6",
"homepage": "https://altalogy.github.io/a6y-react-auth/",
"description": "Authentication forms for React.",
"main": "./lib/index.js",
"module": "./lib/index.es.js",
Expand Down Expand Up @@ -69,7 +70,6 @@
"bugs": {
"url": "https://github.com/Altalogy/a6y-react-auth/issues"
},
"homepage": "https://github.com/Altalogy/a6y-react-auth#readme",
"peerDependencies": {
"react": ">=16",
"react-dom": "16.13.1"
Expand All @@ -78,7 +78,6 @@
"react": ">=16",
"react-dom": "16.13.1",
"babel-loader": "^8.2.2",
"classnames": "^2.2.6",
"copyfiles": "^2.4.1",
"eslint": "^7.20.0",
"eslint-config-prettier": "^8.1.0",
Expand Down Expand Up @@ -117,6 +116,7 @@
"@typescript-eslint/parser": "^4.15.2"
},
"dependencies": {
"classnames": "^2.2.6",
"aws-amplify": "^3.3.22"
}
}
7 changes: 2 additions & 5 deletions a6y-react-auth/src/components/AuthComponent/AuthComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ const AuthComponent = ({
className = 'a6y-react-auth',
onSuccess,
}: IAuthProps): JSX.Element => {
const [currentForm, setCurrentForm] = useState('/sign-in')
const formhandler = (to: string) => {
setCurrentForm(to)
}
const [currentForm, setCurrentForm] = useState('sign-in')
const getAuthForm = (): JSX.Element => {
switch (currentForm) {
case 'sign-up':
return (
<SignUp
onSuccess={onSuccess ? onSuccess : undefined}
onLinkHandler={(to: string) => formhandler(to)}
onLinkHandler={(to: string) => setCurrentForm(to)}
/>
)
case 'forgot-password':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ function EmailPasswordForm({
email: '',
password: '',
})
const [errorData, setErrorData] = useState({
email: false,
password: false,
})

const classNames = require('classnames')

const FormClassEmail = classNames({
[`${className}--error`]: errorData.email ? true : false,
})
const FormClassPassword = classNames({
[`${className}--error`]: errorData.password ? true : false,
})

const onInputChange = (e: { target: { value: string } }, target: string) => {
setErrorData({ ...errorData, [target]: e.target.value.length !== 0 })
setSignUpData({ ...signUpData, [target]: e.target.value })
}

const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.stopPropagation()
Expand All @@ -64,33 +82,33 @@ function EmailPasswordForm({
rules: ['CANNOT_BE_BLANK'],
},
]
if (onClick && validate(data))
if (onClick && validate(data)) {
onClick(signUpData.email, signUpData.password)
} else {
if (!errorData.email && !errorData.password)
setErrorData({ email: true, password: true })
}
}

return (
<form className={`${className}`} onSubmit={e => onSubmit(e)}>
<div className={`${className}-group`}>
<div className={`${className}-group ${FormClassEmail}`}>
<Input
id='email'
placeholder='Email'
typeInput='email'
label=''
onChange={(e: { target: { value: string } }) =>
setSignUpData({ ...signUpData, email: e.target.value })
}
onChange={e => onInputChange(e, 'email')}
value={signUpData.email}
/>
</div>
<div className={`${className}-group`}>
<div className={`${className}-group ${FormClassPassword}`}>
<Input
id='password'
typeInput='password'
placeholder='Password'
label=''
onChange={(e: { target: { value: string } }) =>
setSignUpData({ ...signUpData, password: e.target.value })
}
onChange={e => onInputChange(e, 'password')}
value={signUpData.password}
/>
</div>
Expand Down
41 changes: 32 additions & 9 deletions a6y-react-auth/src/components/ForgotPassword/ForgotPassword.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react'
import FormLinks from '../FormLinks'
import { ErrorBoundary, Input, Button } from '../UI'
import validate from '../../utilities/validation'
import '../../index.css'

/**
Expand Down Expand Up @@ -42,27 +43,49 @@ const ForgotPassword = ({
const [forgotPasswordData, setForgotPasswordData] = useState({
email: '',
})
const onSubmit = () => {
if (onClick) onClick(forgotPasswordData.email)
const [errorData, setErrorData] = useState({
email: false,
})
const classNames = require('classnames')

const FormClass = classNames({
[`${className}--error`]: errorData.email ? true : false,
})
const onInputChange = (e: { target: { value: string } }, target: string) => {
setErrorData({ ...errorData, [target]: e.target.value.length !== 0 })
setForgotPasswordData({
...forgotPasswordData,
[target]: e.target.value,
})
}
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
e.stopPropagation()
const data = [
{
value: forgotPasswordData.email,
rules: ['CANNOT_BE_BLANK'],
},
]
if (onClick && validate(data)) {
onClick(forgotPasswordData.email)
} else {
if (!errorData.email) setErrorData({ email: true })
}
}
return (
<div className={className}>
<ErrorBoundary showError={apiError ? true : false}>
{apiError}
</ErrorBoundary>
<form className={`${className}__form`} onSubmit={onSubmit}>
<div className={`${className}-group`}>
<div className={`${className}-group ${FormClass}`}>
<Input
id='email'
placeholder='Email'
typeInput='email'
label=''
onChange={(e: { target: { value: string } }) =>
setForgotPasswordData({
...forgotPasswordData,
email: e.target.value,
})
}
onChange={e => onInputChange(e, 'email')}
value={forgotPasswordData.email}
/>
</div>
Expand Down
10 changes: 5 additions & 5 deletions a6y-react-auth/src/components/FormLinks/FormLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const FormLinks = ({
<Link
onClick={onLinkHandler}
className={className + '__link'}
to='/forgot-password'
to='forgot-password'
>
Forgot Password
</Link>
Expand All @@ -49,7 +49,7 @@ const FormLinks = ({
<Link
onClick={onLinkHandler}
className={className + '__link'}
to='/sign-up'
to='sign-up'
>
Sign Up
</Link>
Expand All @@ -62,7 +62,7 @@ const FormLinks = ({
<Link
onClick={onLinkHandler}
className={className + '__link'}
to='/sign-in'
to='sign-in'
>
Sign In
</Link>
Expand All @@ -74,14 +74,14 @@ const FormLinks = ({
<Link
onClick={onLinkHandler}
className={className + '__link'}
to='/sign-in'
to='sign-in'
>
Sign In
</Link>
<Link
onClick={onLinkHandler}
className={className + '__link'}
to='/sign-up'
to='sign-up'
>
Sign Up
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

.a6y-react-auth__error-boundary--primary {
padding: 10px 15px;
margin-bottom: 10px;
}

.a6y-react-auth__error-boundary--primary.a6y-react-auth__error-boundary--warning,
Expand Down
4 changes: 4 additions & 0 deletions a6y-react-auth/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
max-width: 320px;
margin: auto;
box-shadow: 0 1px 10px 1px rgb(0 0 0 / 8%), 0 1px 2px -1px rgb(0 0 0 / 6%);
}

.a6y-react-auth__form--error label.a6y-react-auth__label input.a6y-react-auth__label__input {
border: 1px solid #DC2626;
}
Loading