├── src
├── test
│ └── dummy.ts
├── types
│ ├── index.ts
│ ├── auth.ts
│ ├── handlers
│ │ └── ILoginArguments.ts
│ └── user.ts
├── utils
│ └── dummy.ts
├── redux
│ ├── constants
│ │ ├── index.ts
│ │ └── user.ts
│ ├── actions
│ │ ├── index.ts
│ │ ├── auth.ts
│ │ └── user.ts
│ ├── sagas
│ │ └── index.ts
│ ├── reducers
│ │ ├── state.ts
│ │ ├── user.ts
│ │ ├── auth.ts
│ │ └── index.ts
│ └── store
│ │ └── index.ts
├── react-app-env.d.ts
├── config
│ ├── env
│ │ ├── production.ts
│ │ └── development.ts
│ └── index.ts
├── pages
│ ├── home
│ │ ├── style.scss
│ │ └── index.tsx
│ └── auth
│ │ ├── login.tsx
│ │ └── signup.tsx
├── components
│ ├── common
│ │ ├── styles.scss
│ │ └── fallback.tsx
│ └── auth
│ │ ├── login
│ │ ├── styles.scss
│ │ └── loginForm.tsx
│ │ └── signup
│ │ ├── styles.scss
│ │ └── signUpForm.tsx
├── containers
│ └── auth
│ │ ├── login
│ │ ├── styles.scss
│ │ └── index.tsx
│ │ └── signup
│ │ ├── styles.scss
│ │ └── index.tsx
├── index.scss
├── index.tsx
├── router
│ └── index.tsx
├── logo.svg
└── serviceWorker.ts
├── public
├── robots.txt
├── favicon.ico
├── logo192.png
├── logo512.png
├── manifest.json
└── index.html
├── .gitignore
├── tslint.json
├── tsconfig.json
├── package.json
└── README.md
/src/test/dummy.ts:
--------------------------------------------------------------------------------
1 | export default () => {}
--------------------------------------------------------------------------------
/src/types/index.ts:
--------------------------------------------------------------------------------
1 | export * from './user';
--------------------------------------------------------------------------------
/src/utils/dummy.ts:
--------------------------------------------------------------------------------
1 | export default () => {}
--------------------------------------------------------------------------------
/src/redux/constants/index.ts:
--------------------------------------------------------------------------------
1 | export * from './user';
--------------------------------------------------------------------------------
/src/redux/constants/user.ts:
--------------------------------------------------------------------------------
1 | export const FETCH_USER_URL = '';
--------------------------------------------------------------------------------
/src/react-app-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/src/config/env/production.ts:
--------------------------------------------------------------------------------
1 | export default {
2 | BASE_URL: '',
3 | };
--------------------------------------------------------------------------------
/src/redux/actions/index.ts:
--------------------------------------------------------------------------------
1 | export * from './user';
2 | export * from './auth';
--------------------------------------------------------------------------------
/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 |
--------------------------------------------------------------------------------
/src/config/env/development.ts:
--------------------------------------------------------------------------------
1 | export default {
2 | BASE_URL: 'http://localhost:3000',
3 | };
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/js-code-ua/nestjs-demo-fe/HEAD/public/favicon.ico
--------------------------------------------------------------------------------
/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/js-code-ua/nestjs-demo-fe/HEAD/public/logo192.png
--------------------------------------------------------------------------------
/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/js-code-ua/nestjs-demo-fe/HEAD/public/logo512.png
--------------------------------------------------------------------------------
/src/types/auth.ts:
--------------------------------------------------------------------------------
1 | export interface IAuth {
2 | accessToken: string;
3 | refreshToken: string;
4 | }
--------------------------------------------------------------------------------
/src/types/handlers/ILoginArguments.ts:
--------------------------------------------------------------------------------
1 | export interface ILoginArguments {
2 | email: string;
3 | password: string;
4 | }
--------------------------------------------------------------------------------
/src/pages/home/style.scss:
--------------------------------------------------------------------------------
1 | div {
2 | color: blue;
3 | }
4 | .some-class {
5 | font-size: 128px;
6 | padding: 50px;
7 | }
8 |
--------------------------------------------------------------------------------
/src/redux/sagas/index.ts:
--------------------------------------------------------------------------------
1 | import { all } from 'redux-saga/effects';
2 |
3 | export default function* rootSaga() {
4 | yield all([]);
5 | }
--------------------------------------------------------------------------------
/src/components/common/styles.scss:
--------------------------------------------------------------------------------
1 | .router-lazy-spin {
2 | width: 100vw;
3 | height: 100vh;
4 | display: flex;
5 | justify-content: center;
6 | align-items: center;
7 | }
--------------------------------------------------------------------------------
/src/containers/auth/login/styles.scss:
--------------------------------------------------------------------------------
1 | .login-form-container{
2 | display: flex;
3 | flex-flow: row wrap;
4 | justify-content: center;
5 | align-content: center;
6 | width: 100%;
7 | height: 90%;
8 | }
--------------------------------------------------------------------------------
/src/containers/auth/signup/styles.scss:
--------------------------------------------------------------------------------
1 | .signup-form-container{
2 | display: flex;
3 | flex-flow: row wrap;
4 | justify-content: center;
5 | align-content: center;
6 | width: 100%;
7 | height: 90%;
8 | }
--------------------------------------------------------------------------------
/src/pages/auth/login.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import LoginContainer from '../../containers/auth/login'
3 |
4 | export default function LoginPage() {
5 | return (
6 |
7 | )
8 | }
9 |
--------------------------------------------------------------------------------
/src/redux/reducers/state.ts:
--------------------------------------------------------------------------------
1 | import { IUser } from "../../types";
2 | import { IAuth } from "../../types/auth";
3 |
4 | export interface IRootReducer {
5 | router: any,
6 | user: IUser,
7 | auth: IAuth,
8 | }
9 |
--------------------------------------------------------------------------------
/src/pages/auth/signup.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import SignUpContainer from '../../containers/auth/signup';
3 |
4 | export default function SignupPage() {
5 | return (
6 |
7 | )
8 | }
9 |
--------------------------------------------------------------------------------
/src/pages/home/index.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import './style.scss';
3 |
4 | export default function Home() {
5 | return (
6 |
7 | Hello React!
8 |
9 | )
10 | }
11 |
--------------------------------------------------------------------------------
/src/config/index.ts:
--------------------------------------------------------------------------------
1 | import * as _ from 'lodash';
2 |
3 | const environment = process.env.NODE_ENV || 'development';
4 |
5 | export default _.extend({
6 | environment,
7 | },
8 | require(`${__dirname}/env/${environment}`), /* eslint "import/no-dynamic-require": 0 */
9 | );
10 |
--------------------------------------------------------------------------------
/src/components/common/fallback.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { Spin } from 'antd';
3 |
4 | import './styles.scss';
5 |
6 | export default function Fallback() {
7 | return (
8 |
9 |
10 |
11 | )
12 | }
13 |
--------------------------------------------------------------------------------
/src/redux/reducers/user.ts:
--------------------------------------------------------------------------------
1 | import { handleActions } from 'redux-actions';
2 | import { IUser } from '../../types';
3 | import { UserActions } from '../actions';
4 |
5 | const initialState = null;
6 |
7 | export const UserReducer = handleActions({
8 | [UserActions.Type.SET_USER]: (state, action) => action.payload,
9 | }, initialState);
--------------------------------------------------------------------------------
/src/redux/reducers/auth.ts:
--------------------------------------------------------------------------------
1 | import { handleActions } from "redux-actions";
2 | import { IAuth } from "../../types/auth";
3 | import { AuthActions } from "../actions";
4 |
5 | const initialState = null;
6 |
7 | export const AuthReducer = handleActions({
8 | [AuthActions.Type.SET_AUTH]: (state, action) => action.payload,
9 | }, initialState)
--------------------------------------------------------------------------------
/src/redux/actions/auth.ts:
--------------------------------------------------------------------------------
1 | import { createAction } from 'redux-actions';
2 | import { IAuth } from '../../types/auth';
3 |
4 | enum Type {
5 | SET_AUTH = 'SET_AUTH'
6 | }
7 |
8 | const setAuthInfo = createAction(Type.SET_AUTH);
9 |
10 | export const AuthActions = {
11 | Type,
12 |
13 | setAuthInfo,
14 | }
15 |
16 | export type AuthActions = Omit;
--------------------------------------------------------------------------------
/src/containers/auth/login/index.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import LoginForm from '../../../components/auth/login/loginForm';
3 |
4 | import './styles.scss';
5 |
6 | export default function LoginContainer() {
7 | return (
8 |
9 |
10 |
11 | )
12 | }
13 |
--------------------------------------------------------------------------------
/src/containers/auth/signup/index.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import './styles.scss';
3 | import SignUpForm from '../../../components/auth/signup/signUpForm';
4 |
5 | export default function SignupContainer() {
6 | return (
7 |
8 |
9 |
10 | )
11 | }
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/src/redux/actions/user.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable @typescript-eslint/no-namespace */
2 | import { createAction } from 'redux-actions';
3 | import { IUser } from '../../types';
4 |
5 | enum Type {
6 | SET_USER = 'SET_USER'
7 | }
8 |
9 | const setUser = createAction(Type.SET_USER);
10 |
11 | export const UserActions = {
12 | Type,
13 |
14 | setUser,
15 | }
16 |
17 | export type UserActions = Omit;
--------------------------------------------------------------------------------
/src/types/user.ts:
--------------------------------------------------------------------------------
1 | export interface IAddress {
2 | country: string;
3 | city: string;
4 | addressLine1: string;
5 | addressLine2: string;
6 | }
7 |
8 | export interface IUser {
9 | email: string;
10 | status: string;
11 | avatar: string;
12 | lastName: string;
13 | firstName: string;
14 | gender: string;
15 | address: IAddress;
16 | profession: string;
17 | phone: string;
18 | roles: Array;
19 | }
--------------------------------------------------------------------------------
/src/components/auth/login/styles.scss:
--------------------------------------------------------------------------------
1 | .login-form {
2 | max-width: 400px;
3 | display: flex;
4 | flex-flow: column;
5 | padding: 2em;
6 | animation-name: appear;
7 | animation-duration: 2s;
8 |
9 | // shadow
10 | -webkit-box-shadow: 17px 13px 80px 2px rgba(166, 166, 171, 1);
11 | -moz-box-shadow: 17px 13px 80px 2px rgba(166, 166, 171, 1);
12 | box-shadow: 17px 13px 80px 2px rgba(166, 166, 171, 1);
13 |
14 | .login-form-button {
15 | width: 100%;
16 | }
17 | .main-label {
18 | text-align: center;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/components/auth/signup/styles.scss:
--------------------------------------------------------------------------------
1 | .signup-form {
2 | display: flex;
3 | flex-flow: column;
4 | padding: 2em;
5 | animation-name: appear;
6 | animation-duration: 2s;
7 | width: 400px;
8 |
9 | // shadow
10 | -webkit-box-shadow: 17px 13px 80px 2px rgba(166, 166, 171, 1);
11 | -moz-box-shadow: 17px 13px 80px 2px rgba(166, 166, 171, 1);
12 | box-shadow: 17px 13px 80px 2px rgba(166, 166, 171, 1);
13 |
14 | .signup-form-button {
15 | width: 100%;
16 | }
17 | .main-label {
18 | text-align: center;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "defaultSeverity": "error",
3 | "extends": [
4 | "tslint-react"
5 | ],
6 | "jsRules": {
7 | },
8 | "rules": {
9 | "member-access": false,
10 | "ordered-imports": false,
11 | "quotemark": false,
12 | "no-console": false,
13 | "semicolon": false,
14 | "jsx-no-lambda": false
15 | },
16 | "rulesDirectory": [
17 | ],
18 | "linterOptions": {
19 | "exclude": [
20 | "config/**/*.js",
21 | "node_modules/**/*.ts"
22 | ]
23 | }
24 | }
--------------------------------------------------------------------------------
/src/index.scss:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | }
9 |
10 | code {
11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
12 | monospace;
13 | }
14 |
15 | #root {
16 | width: 100%;
17 | height: 100%;
18 | }
19 |
20 | // animations
21 | @keyframes appear {
22 | from {opacity: 0;}
23 | to {opacity: 1;}
24 | }
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": [
5 | "dom",
6 | "dom.iterable",
7 | "esnext"
8 | ],
9 | "allowJs": true,
10 | "skipLibCheck": true,
11 | "esModuleInterop": true,
12 | "allowSyntheticDefaultImports": true,
13 | "strict": true,
14 | "forceConsistentCasingInFileNames": true,
15 | "module": "esnext",
16 | "moduleResolution": "node",
17 | "resolveJsonModule": true,
18 | "isolatedModules": true,
19 | "noEmit": true,
20 | "jsx": "react"
21 | },
22 | "include": [
23 | "src"
24 | ]
25 | }
26 |
--------------------------------------------------------------------------------
/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/src/redux/reducers/index.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable @typescript-eslint/no-namespace */
2 | import { combineReducers } from 'redux';
3 | import { routerReducer } from 'react-router-redux';
4 | import { UserReducer } from './user';
5 | import { IRootReducer } from './state';
6 | import { AuthReducer } from './auth';
7 |
8 | // NOTE: current type definition of Reducer in 'redux-actions' module
9 | // doesn't go well with redux@4
10 | const rootReducer = combineReducers({
11 | router: routerReducer,
12 | user: UserReducer as any,
13 | auth: AuthReducer as any,
14 | });
15 |
16 | export default rootReducer;
--------------------------------------------------------------------------------
/src/index.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import { Provider } from 'react-redux';
4 | import * as serviceWorker from './serviceWorker';
5 | import store from './redux/store';
6 | import MainRouter from './router';
7 |
8 | import './index.scss';
9 |
10 | const app = (
11 |
12 |
13 |
14 | );
15 |
16 | ReactDOM.render(app, document.getElementById('root'));
17 |
18 | // If you want your app to work offline and load faster, you can change
19 | // unregister() to register() below. Note this comes with some pitfalls.
20 | // Learn more about service workers: https://bit.ly/CRA-PWA
21 | serviceWorker.unregister();
22 |
--------------------------------------------------------------------------------
/src/redux/store/index.ts:
--------------------------------------------------------------------------------
1 | import { createStore, applyMiddleware, compose } from "redux";
2 | import { routerMiddleware } from 'react-router-redux';
3 | import createSagaMiddleware from 'redux-saga';
4 | import { createBrowserHistory } from 'history';
5 |
6 | import rootReducer from "../reducers";
7 | import rootSaga from '../sagas';
8 |
9 | export const history = createBrowserHistory();
10 |
11 | const sagaMiddleware = createSagaMiddleware();
12 | const composeEnhancers =
13 | (window && (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) || compose;
14 | const enhancer = composeEnhancers(
15 | applyMiddleware(sagaMiddleware, routerMiddleware(history))
16 | );
17 | const store = createStore(rootReducer, enhancer);
18 |
19 | sagaMiddleware.run(rootSaga);
20 |
21 | export default store;
--------------------------------------------------------------------------------
/src/router/index.tsx:
--------------------------------------------------------------------------------
1 | import React, { Suspense, Fragment } from 'react';
2 | import { connect } from 'react-redux';
3 | import { Router, Route, Switch, RouteProps } from 'react-router-dom';
4 | import { history } from '../redux/store';
5 | import Fallback from '../components/common/fallback';
6 | import { IRootReducer } from '../redux/reducers/state';
7 | import { IAuth } from '../types/auth';
8 | import 'antd/dist/antd.css';
9 |
10 | const HomePage = React.lazy(() => import('../pages/home'));
11 | const LoginPage = React.lazy(() => import('../pages/auth/login'));
12 | const SignUpPage = React.lazy(() => import('../pages/auth/signup'));
13 |
14 | interface IMainRouterProps extends RouteProps {
15 | auth: IAuth,
16 | }
17 |
18 | function MainRouter(props: IMainRouterProps) {
19 | return (
20 |
21 | }>
22 |
23 | {
24 | props.auth
25 | ? (
26 |
27 | )
28 | : (
29 |
30 |
31 |
32 |
33 | )
34 | }
35 |
36 |
37 |
38 | );
39 | }
40 |
41 | const mapStateToProps = (state: IRootReducer): IMainRouterProps => ({
42 | auth: state.auth,
43 | });
44 |
45 | export default connect(mapStateToProps)(MainRouter);
46 |
47 |
48 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "saga-template-ts",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "antd": "^3.26.9",
7 | "connected-react-router": "^6.6.1",
8 | "history": "^4.10.1",
9 | "less": "^3.10.3",
10 | "less-loader": "^5.0.0",
11 | "lodash": "^4.17.15",
12 | "node-sass": "^4.13.1",
13 | "react": "^16.9.0",
14 | "react-dom": "^16.9.0",
15 | "react-redux": "^7.1.3",
16 | "react-router-dom": "^5.1.2",
17 | "react-router-redux": "^4.0.8",
18 | "react-scripts": "^3.4.0",
19 | "redux": "^4.0.5",
20 | "redux-actions": "^2.6.5",
21 | "redux-saga": "^1.1.3",
22 | "ts-loader": "^6.2.1",
23 | "typesafe-actions": "^5.1.0",
24 | "typescript": "^3.6.0"
25 | },
26 | "scripts": {
27 | "start": "react-scripts start",
28 | "build": "react-scripts build",
29 | "test": "react-scripts test",
30 | "eject": "react-scripts eject"
31 | },
32 | "eslintConfig": {
33 | "extends": "react-app"
34 | },
35 | "browserslist": {
36 | "production": [
37 | ">0.2%",
38 | "not dead",
39 | "not op_mini all"
40 | ],
41 | "development": [
42 | "last 1 chrome version",
43 | "last 1 firefox version",
44 | "last 1 safari version"
45 | ]
46 | },
47 | "devDependencies": {
48 | "@types/antd": "^1.0.0",
49 | "@types/jest": "24.0.18",
50 | "@types/lodash": "^4.14.149",
51 | "@types/node": "12.7.5",
52 | "@types/react": "16.9.2",
53 | "@types/react-dom": "16.9.0",
54 | "@types/react-redux": "^7.1.7",
55 | "@types/react-router-dom": "^5.1.3",
56 | "@types/react-router-redux": "^5.0.18",
57 | "@types/redux": "^3.6.0",
58 | "@types/redux-actions": "^2.6.1",
59 | "@types/redux-saga": "^0.10.5"
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | #JS Code App
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2 |
3 | ## Available Scripts
4 |
5 | In the project directory, you can run:
6 |
7 | ### `npm start`
8 |
9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
11 |
12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console.
14 |
15 | ### `npm test`
16 |
17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
19 |
20 | ### `npm run build`
21 |
22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance.
24 |
25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed!
27 |
28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
29 |
30 | ### `npm run eject`
31 |
32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!**
33 |
34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
35 |
36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
37 |
38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
39 |
40 | ## Learn More
41 |
42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
43 |
44 | To learn React, check out the [React documentation](https://reactjs.org/).
45 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/src/components/auth/login/loginForm.tsx:
--------------------------------------------------------------------------------
1 | import React, { FormEvent } from 'react';
2 | import { Form, Icon, Input, Button, Checkbox } from 'antd';
3 | import { FormComponentProps } from 'antd/es/form';
4 |
5 | import './styles.scss';
6 | import { Link } from 'react-router-dom';
7 | import { ILoginArguments } from '../../../types/handlers/ILoginArguments';
8 |
9 | interface ILoginFormProps extends FormComponentProps {
10 | handleSubmit(values: ILoginArguments): void,
11 | handleError(error: any): void,
12 | }
13 |
14 | function LoginForm(props: ILoginFormProps) {
15 | function onSubmit(e: FormEvent): void {
16 | e.preventDefault();
17 | props.form.validateFields((error, values) => {
18 | if (error) {
19 | return props.handleError(error);
20 | }
21 | props.handleSubmit(values);
22 | });
23 | }
24 |
25 | return (
26 |
29 | {props.form.getFieldDecorator('email', {
30 | rules: [{ required: true, message: 'Please add your email!' }],
31 | })(
32 | }
35 | placeholder="Email"
36 | />,
37 | )}
38 |
39 |
40 | {props.form.getFieldDecorator('password', {
41 | rules: [{ required: true, message: 'Please add your Password!' }],
42 | })(
43 | }
45 | type="password"
46 | placeholder="Password"
47 | />,
48 | )}
49 |
50 |
51 | {props.form.getFieldDecorator('remember', {
52 | valuePropName: 'checked',
53 | initialValue: true,
54 | })(Remember me)}
55 |
56 | Forgot password
57 |
58 |
61 | Or register now!
62 |
63 |
64 | )
65 | }
66 |
67 | export default Form.create({ name: 'LoginForm' })(LoginForm);
68 |
--------------------------------------------------------------------------------
/src/components/auth/signup/signUpForm.tsx:
--------------------------------------------------------------------------------
1 | import React, { FormEvent } from 'react';
2 | import { Form, Icon, Input, Button, Select } from 'antd';
3 |
4 | import './styles.scss';
5 | import { Link } from 'react-router-dom';
6 | import { FormComponentProps } from 'antd/lib/form';
7 |
8 | const { Option } = Select;
9 |
10 | interface ISignUpFormProps extends FormComponentProps {
11 | handleSubmit(values: any): void;
12 | handleError(error: any): void;
13 | }
14 |
15 | export default Form.create()(function SignUpForm(props: ISignUpFormProps) {
16 | function onSubmit(e: FormEvent): void {
17 | e.preventDefault();
18 | props.form.validateFields((error, values) => {
19 | if (error) {
20 | return props.handleError(error);
21 | }
22 | props.handleSubmit(values);
23 | });
24 | }
25 |
26 | return (
27 |
30 | {props.form.getFieldDecorator('firstName', {
31 | rules: [{ required: true, message: 'Please add your First Name!' }],
32 | })(
33 | }
36 | placeholder="First Name"
37 | />,
38 | )}
39 |
40 |
41 | {props.form.getFieldDecorator('lastName', {
42 | rules: [{ required: true, message: 'Please add your Last Name!' }],
43 | })(
44 | }
47 | placeholder="Last Name"
48 | />,
49 | )}
50 |
51 |
52 | {props.form.getFieldDecorator('gender', {
53 | rules: [{ required: true, message: 'Please select your gender!' }],
54 | })(
55 | ,
59 | )}
60 |
61 |
62 | {props.form.getFieldDecorator('email', {
63 | rules: [{ required: true, message: 'Please add your email!' }],
64 | })(
65 | }
68 | placeholder="Email"
69 | />,
70 | )}
71 |
72 |
73 | {props.form.getFieldDecorator('password', {
74 | rules: [{ required: true, message: 'Please add your Password!' }],
75 | })(
76 | }
78 | type="password"
79 | placeholder="Password"
80 | />,
81 | )}
82 |
83 |
84 | {props.form.getFieldDecorator('confirmPassword', {
85 | rules: [{ required: true, message: 'Please confirm your Password!' }],
86 | })(
87 | }
89 | type="password"
90 | placeholder="Confirm Password"
91 | />,
92 | )}
93 |
94 |
95 |
98 | Or Log In
99 |
100 |
101 | )
102 | })
103 |
--------------------------------------------------------------------------------
/src/serviceWorker.ts:
--------------------------------------------------------------------------------
1 | // This optional code is used to register a service worker.
2 | // register() is not called by default.
3 |
4 | // This lets the app load faster on subsequent visits in production, and gives
5 | // it offline capabilities. However, it also means that developers (and users)
6 | // will only see deployed updates on subsequent visits to a page, after all the
7 | // existing tabs open on the page have been closed, since previously cached
8 | // resources are updated in the background.
9 |
10 | // To learn more about the benefits of this model and instructions on how to
11 | // opt-in, read https://bit.ly/CRA-PWA
12 |
13 | const isLocalhost = Boolean(
14 | window.location.hostname === 'localhost' ||
15 | // [::1] is the IPv6 localhost address.
16 | window.location.hostname === '[::1]' ||
17 | // 127.0.0.1/8 is considered localhost for IPv4.
18 | window.location.hostname.match(
19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
20 | )
21 | );
22 |
23 | type Config = {
24 | onSuccess?: (registration: ServiceWorkerRegistration) => void;
25 | onUpdate?: (registration: ServiceWorkerRegistration) => void;
26 | };
27 |
28 | export function register(config?: Config) {
29 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
30 | // The URL constructor is available in all browsers that support SW.
31 | const publicUrl = new URL(
32 | (process as { env: { [key: string]: string } }).env.PUBLIC_URL,
33 | window.location.href
34 | );
35 | if (publicUrl.origin !== window.location.origin) {
36 | // Our service worker won't work if PUBLIC_URL is on a different origin
37 | // from what our page is served on. This might happen if a CDN is used to
38 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
39 | return;
40 | }
41 |
42 | window.addEventListener('load', () => {
43 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
44 |
45 | if (isLocalhost) {
46 | // This is running on localhost. Let's check if a service worker still exists or not.
47 | checkValidServiceWorker(swUrl, config);
48 |
49 | // Add some additional logging to localhost, pointing developers to the
50 | // service worker/PWA documentation.
51 | navigator.serviceWorker.ready.then(() => {
52 | console.log(
53 | 'This web app is being served cache-first by a service ' +
54 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
55 | );
56 | });
57 | } else {
58 | // Is not localhost. Just register service worker
59 | registerValidSW(swUrl, config);
60 | }
61 | });
62 | }
63 | }
64 |
65 | function registerValidSW(swUrl: string, config?: Config) {
66 | navigator.serviceWorker
67 | .register(swUrl)
68 | .then(registration => {
69 | registration.onupdatefound = () => {
70 | const installingWorker = registration.installing;
71 | if (installingWorker == null) {
72 | return;
73 | }
74 | installingWorker.onstatechange = () => {
75 | if (installingWorker.state === 'installed') {
76 | if (navigator.serviceWorker.controller) {
77 | // At this point, the updated precached content has been fetched,
78 | // but the previous service worker will still serve the older
79 | // content until all client tabs are closed.
80 | console.log(
81 | 'New content is available and will be used when all ' +
82 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
83 | );
84 |
85 | // Execute callback
86 | if (config && config.onUpdate) {
87 | config.onUpdate(registration);
88 | }
89 | } else {
90 | // At this point, everything has been precached.
91 | // It's the perfect time to display a
92 | // "Content is cached for offline use." message.
93 | console.log('Content is cached for offline use.');
94 |
95 | // Execute callback
96 | if (config && config.onSuccess) {
97 | config.onSuccess(registration);
98 | }
99 | }
100 | }
101 | };
102 | };
103 | })
104 | .catch(error => {
105 | console.error('Error during service worker registration:', error);
106 | });
107 | }
108 |
109 | function checkValidServiceWorker(swUrl: string, config?: Config) {
110 | // Check if the service worker can be found. If it can't reload the page.
111 | fetch(swUrl)
112 | .then(response => {
113 | // Ensure service worker exists, and that we really are getting a JS file.
114 | const contentType = response.headers.get('content-type');
115 | if (
116 | response.status === 404 ||
117 | (contentType != null && contentType.indexOf('javascript') === -1)
118 | ) {
119 | // No service worker found. Probably a different app. Reload the page.
120 | navigator.serviceWorker.ready.then(registration => {
121 | registration.unregister().then(() => {
122 | window.location.reload();
123 | });
124 | });
125 | } else {
126 | // Service worker found. Proceed as normal.
127 | registerValidSW(swUrl, config);
128 | }
129 | })
130 | .catch(() => {
131 | console.log(
132 | 'No internet connection found. App is running in offline mode.'
133 | );
134 | });
135 | }
136 |
137 | export function unregister() {
138 | if ('serviceWorker' in navigator) {
139 | navigator.serviceWorker.ready.then(registration => {
140 | registration.unregister();
141 | });
142 | }
143 | }
144 |
--------------------------------------------------------------------------------