-
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.
feat(route): simple route with react-async eg
- Loading branch information
1 parent
2681750
commit c14c625
Showing
21 changed files
with
293 additions
and
287 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# dev files | ||
public/dev-lib | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
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,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": "src" | ||
}, | ||
"include": ["src"] | ||
} |
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
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
|
||
// Authorization HOC | ||
const Authorization = (WrappedComponent) => | ||
class WithAuthorization extends React.Component { | ||
render() { | ||
return <WrappedComponent {...this.props} /> | ||
} | ||
} | ||
|
||
|
||
export default Authorization; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import './index.css'; | ||
import App from './App'; | ||
import * as serviceWorker from './serviceWorker'; | ||
import Route from 'routes/ServiceRoute'; | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<App /> | ||
<Route /> | ||
</React.StrictMode>, | ||
document.getElementById('root') | ||
); | ||
|
||
// If you want your app to work offline and load faster, you can change | ||
// unregister() to register() below. Note this comes with some pitfalls. | ||
// Learn more about service workers: https://bit.ly/CRA-PWA | ||
serviceWorker.unregister(); | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
|
||
const Error404 = () => { | ||
return ( | ||
<div> | ||
404 Error | ||
</div> | ||
); | ||
} | ||
|
||
|
||
export default Error404; |
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 @@ | ||
export { default } from './Error404'; |
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,13 @@ | ||
import React from 'react'; | ||
import { Redirect } from "react-router-dom"; | ||
|
||
class Index extends React.Component { | ||
render() { | ||
return ( | ||
<Redirect to="/login" /> | ||
) | ||
} | ||
} | ||
|
||
|
||
export default Index; |
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,40 @@ | ||
import React, { useState } from 'react'; | ||
import { useAsync } from 'react-async'; | ||
|
||
|
||
import Authorization from 'hocs/Authorization'; | ||
|
||
const Login = () => { | ||
/* Rest API Authenticator function */ | ||
const auth = ([email, password], { signal }) => { | ||
// setEmail(""); | ||
|
||
} | ||
|
||
/* Async api call */ | ||
const { isPending, error, run } = useAsync({ deferFn: auth }) | ||
|
||
/* State hooks */ | ||
const [email, setEmail] = useState(""); | ||
|
||
/* State hooks */ | ||
const [password, setPassword] = useState(""); | ||
|
||
const handleLogin = event => { | ||
event.preventDefault(); | ||
run(email, password); | ||
} | ||
|
||
return ( | ||
<form onSubmit={handleLogin}> | ||
<input type='text' value={email} onChange={event => setEmail(event.target.value)} /> | ||
<br /> | ||
<input type='password' value={password} onChange={event => setPassword(event.target.value)} /> | ||
<br /> | ||
<button type='submit' disabled={isPending}>Login</button> | ||
</form> | ||
) | ||
} | ||
|
||
|
||
export default Authorization(Login); |
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 @@ | ||
export { default } from './Login'; |
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,24 @@ | ||
import React from 'react'; | ||
import { | ||
BrowserRouter as Router, | ||
Switch, | ||
Route | ||
} from 'react-router-dom'; | ||
|
||
import IndexPage from 'pages/Index'; | ||
import LoginPage from 'pages/Login'; | ||
import Error404Page from 'pages/Error404'; | ||
|
||
// <Route path='/home/dashboards/support' component={LoginPage} /> | ||
const ServiceRoute = () => ( | ||
<Router> | ||
<Switch> | ||
<Route exact path="/" component={IndexPage} /> | ||
<Route path="/login" component={LoginPage} /> | ||
<Route path="*" component={Error404Page} /> | ||
</Switch> | ||
</Router> | ||
); | ||
|
||
|
||
export default ServiceRoute; |
Oops, something went wrong.