Skip to content

Commit

Permalink
feat(route): simple route with react-async eg
Browse files Browse the repository at this point in the history
  • Loading branch information
Simonbelete committed Aug 11, 2020
1 parent 2681750 commit c14c625
Show file tree
Hide file tree
Showing 21 changed files with 293 additions and 287 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# dev files
public/dev-lib

# Logs
logs
*.log
Expand Down
6 changes: 6 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@bit/guya-ltd.gcss.atoms.button": "^0.0.4",
"@bit/guya-ltd.gcss.molecules.field": "^0.0.2",
"@bit/guya-ltd.gcss.organisms.card": "^0.0.2",
"@bit/guya-ltd.gcss.organisms.formcontrol": "^0.0.1",
"@bit/guya-ltd.gcss.templates.landing.login": "^0.0.6",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^16.13.1",
"react-async": "^10.0.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-router-i18n": "^0.3.0",
"react-scripts": "3.4.1"
},
"devDependencies": {
Expand Down
Binary file removed public/logo192.png
Binary file not shown.
Binary file removed public/logo512.png
Binary file not shown.
38 changes: 0 additions & 38 deletions src/App.css

This file was deleted.

26 changes: 0 additions & 26 deletions src/App.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/App.test.js

This file was deleted.

12 changes: 12 additions & 0 deletions src/hocs/Authorization.js
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;
13 changes: 0 additions & 13 deletions src/index.css

This file was deleted.

13 changes: 3 additions & 10 deletions src/index.js
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();
);
7 changes: 0 additions & 7 deletions src/logo.svg

This file was deleted.

12 changes: 12 additions & 0 deletions src/pages/Error404/Error404.js
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;
1 change: 1 addition & 0 deletions src/pages/Error404/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Error404';
13 changes: 13 additions & 0 deletions src/pages/Index/index.js
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;
40 changes: 40 additions & 0 deletions src/pages/Login/Login.js
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);
1 change: 1 addition & 0 deletions src/pages/Login/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './Login';
24 changes: 24 additions & 0 deletions src/routes/ServiceRoute.js
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;
Loading

0 comments on commit c14c625

Please sign in to comment.