Merge pull request #2773 from 488kuroi/feature-add_react
[ ADD ] react configuration
This commit is contained in:
commit
1bfbe9a99a
|
@ -53,6 +53,8 @@ volumes:
|
||||||
driver: ${VOLUMES_DRIVER}
|
driver: ${VOLUMES_DRIVER}
|
||||||
docker-in-docker:
|
docker-in-docker:
|
||||||
driver: ${VOLUMES_DRIVER}
|
driver: ${VOLUMES_DRIVER}
|
||||||
|
react:
|
||||||
|
driver: ${VOLUMES_DRIVER}
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
|
||||||
|
@ -1853,3 +1855,20 @@ services:
|
||||||
- ${DATA_PATH_HOST}/tomcat/logs:/usr/local/tomcat/logs
|
- ${DATA_PATH_HOST}/tomcat/logs:/usr/local/tomcat/logs
|
||||||
# restart: always
|
# restart: always
|
||||||
|
|
||||||
|
### react #####################################################
|
||||||
|
react:
|
||||||
|
build:
|
||||||
|
context: ./react
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
container_name: react
|
||||||
|
stdin_open: true
|
||||||
|
environment:
|
||||||
|
- CHOKIDAR_USEPOLLING=true
|
||||||
|
networks:
|
||||||
|
- frontend
|
||||||
|
- backend
|
||||||
|
volumes:
|
||||||
|
- ./react:/usr/src/app/react
|
||||||
|
- /usr/src/app/react/node_modules
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
|
@ -0,0 +1,11 @@
|
||||||
|
FROM node:10
|
||||||
|
|
||||||
|
WORKDIR /usr/src/app/react
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
RUN npm install node-sass && npm install
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["npm", "start"]
|
|
@ -0,0 +1,68 @@
|
||||||
|
This project was bootstrapped with [react-redux-boilerplate](https://github.com/Marinashafiq/react-redux-boilerplate).
|
||||||
|
|
||||||
|
## Available Scripts
|
||||||
|
|
||||||
|
In the project directory, you can run:
|
||||||
|
|
||||||
|
### `npm start`
|
||||||
|
|
||||||
|
Runs the app in the development mode.<br />
|
||||||
|
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||||
|
|
||||||
|
The page will reload if you make edits.<br />
|
||||||
|
You will also see any lint errors in the console.
|
||||||
|
|
||||||
|
### `npm test`
|
||||||
|
|
||||||
|
Launches the test runner in the interactive watch mode.<br />
|
||||||
|
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||||
|
|
||||||
|
### `npm run build`
|
||||||
|
|
||||||
|
Builds the app for production to the `build` folder.<br />
|
||||||
|
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||||
|
|
||||||
|
The build is minified and the filenames include the hashes.<br />
|
||||||
|
Your app is ready to be deployed!
|
||||||
|
|
||||||
|
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||||
|
|
||||||
|
### `npm run eject`
|
||||||
|
|
||||||
|
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## Learn More
|
||||||
|
|
||||||
|
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||||
|
|
||||||
|
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||||
|
|
||||||
|
### Code Splitting
|
||||||
|
|
||||||
|
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
|
||||||
|
|
||||||
|
### Analyzing the Bundle Size
|
||||||
|
|
||||||
|
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
|
||||||
|
|
||||||
|
### Making a Progressive Web App
|
||||||
|
|
||||||
|
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
|
||||||
|
|
||||||
|
### Advanced Configuration
|
||||||
|
|
||||||
|
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
|
||||||
|
|
||||||
|
### Deployment
|
||||||
|
|
||||||
|
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
|
||||||
|
|
||||||
|
### `npm run build` fails to minify
|
||||||
|
|
||||||
|
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,48 @@
|
||||||
|
{
|
||||||
|
"name": "react-redux-boilerplate",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@material-ui/core": "^4.11.0",
|
||||||
|
"@material-ui/icons": "^4.9.1",
|
||||||
|
"@material-ui/lab": "^4.0.0-alpha.56",
|
||||||
|
"@testing-library/jest-dom": "^4.2.4",
|
||||||
|
"@testing-library/react": "^9.5.0",
|
||||||
|
"@testing-library/user-event": "^7.2.1",
|
||||||
|
"axios": "^0.19.2",
|
||||||
|
"bootstrap": "^4.5.3",
|
||||||
|
"jss-rtl": "^0.3.0",
|
||||||
|
"node-sass": "^4.14.1",
|
||||||
|
"prop-types": "^15.7.2",
|
||||||
|
"react": "^17.0.1",
|
||||||
|
"react-bootstrap": "^1.4.0",
|
||||||
|
"react-dom": "^17.0.1",
|
||||||
|
"react-intl": "^4.7.6",
|
||||||
|
"react-redux": "^7.2.2",
|
||||||
|
"react-router-dom": "^5.2.0",
|
||||||
|
"react-scripts": "3.4.1",
|
||||||
|
"redux": "^4.0.5",
|
||||||
|
"redux-saga": "^1.1.3"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "react-scripts start",
|
||||||
|
"build": "react-scripts build",
|
||||||
|
"test": "react-scripts test",
|
||||||
|
"eject": "react-scripts eject"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": "react-app"
|
||||||
|
},
|
||||||
|
"browserslist": {
|
||||||
|
"production": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"development": [
|
||||||
|
"last 1 chrome version",
|
||||||
|
"last 1 firefox version",
|
||||||
|
"last 1 safari version"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
|
@ -0,0 +1,43 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta name="theme-color" content="#000000" />
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
content="Web site created using create-react-app"
|
||||||
|
/>
|
||||||
|
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||||
|
<!--
|
||||||
|
manifest.json provides metadata used when your web app is installed on a
|
||||||
|
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||||
|
-->
|
||||||
|
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||||
|
<!--
|
||||||
|
Notice the use of %PUBLIC_URL% in the tags above.
|
||||||
|
It will be replaced with the URL of the `public` folder during the build.
|
||||||
|
Only files inside the `public` folder can be referenced from the HTML.
|
||||||
|
|
||||||
|
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||||
|
work correctly both with client-side routing and a non-root public URL.
|
||||||
|
Learn how to configure a non-root public URL by running `npm run build`.
|
||||||
|
-->
|
||||||
|
<title>React App</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
<div id="root"></div>
|
||||||
|
<!--
|
||||||
|
This HTML file is a template.
|
||||||
|
If you open it directly in the browser, you will see an empty page.
|
||||||
|
|
||||||
|
You can add webfonts, meta tags, or analytics to this file.
|
||||||
|
The build step will place the bundled scripts into the <body> tag.
|
||||||
|
|
||||||
|
To begin the development, run `npm start` or `yarn start`.
|
||||||
|
To create a production bundle, use `npm run build` or `yarn build`.
|
||||||
|
-->
|
||||||
|
</body>
|
||||||
|
</html>
|
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"short_name": "React App",
|
||||||
|
"name": "Create React App Sample",
|
||||||
|
"icons": [
|
||||||
|
{
|
||||||
|
"src": "favicon.ico",
|
||||||
|
"sizes": "64x64 32x32 24x24 16x16",
|
||||||
|
"type": "image/x-icon"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "logo192.png",
|
||||||
|
"type": "image/png",
|
||||||
|
"sizes": "192x192"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "logo512.png",
|
||||||
|
"type": "image/png",
|
||||||
|
"sizes": "512x512"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"start_url": ".",
|
||||||
|
"display": "standalone",
|
||||||
|
"theme_color": "#000000",
|
||||||
|
"background_color": "#ffffff"
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
# https://www.robotstxt.org/robotstxt.html
|
||||||
|
User-agent: *
|
||||||
|
Disallow:
|
|
@ -0,0 +1,39 @@
|
||||||
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { createMuiTheme } from "@material-ui/core/styles";
|
||||||
|
import { ThemeProvider } from "@material-ui/styles";
|
||||||
|
import rtl from "jss-rtl";
|
||||||
|
import { create } from "jss";
|
||||||
|
import { StylesProvider, jssPreset } from "@material-ui/styles";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import App from "./containers/App";
|
||||||
|
|
||||||
|
function ThemeApp() {
|
||||||
|
const jss = create({ plugins: [...jssPreset().plugins, rtl()] });
|
||||||
|
const lang = useSelector(state => state.lang);
|
||||||
|
const [direction, setDirection] = useState(lang === "en" ? "ltr" : "rtl");
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setDirection(lang === "en" ? "ltr" : "rtl");
|
||||||
|
}, [lang]);
|
||||||
|
|
||||||
|
const theme = createMuiTheme({
|
||||||
|
direction: direction,
|
||||||
|
palette: {
|
||||||
|
primary: {
|
||||||
|
main: "#1976d2"
|
||||||
|
},
|
||||||
|
secondary: {
|
||||||
|
main: "#ac4556"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<StylesProvider jss={jss}>
|
||||||
|
<ThemeProvider theme={theme}>
|
||||||
|
<App />
|
||||||
|
</ThemeProvider>
|
||||||
|
</StylesProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ThemeApp;
|
|
@ -0,0 +1,13 @@
|
||||||
|
export default {
|
||||||
|
ar: {
|
||||||
|
hello: "مرحبا",
|
||||||
|
langBtn : "English",
|
||||||
|
home: {
|
||||||
|
content:
|
||||||
|
'لوريم إيبسوم(Lorem Ipsum) هو ببساطة نص شكلي (بمعنى أن الغاية هي الشكل وليس المحتوى) ويُستخدم في صناعات المطابع ودور النشر. كان لوريم إيبسوم ولايزال المعيار للنص الشكلي منذ القرن الخامس عشر عندما قامت مطبعة مجهولة برص مجموعة من الأحرف بشكل عشوائي أخذتها من نص، لتكوّن كتيّب بمثابة دليل أو مرجع شكلي لهذه الأحرف. خمسة قرون من الزمن لم تقضي على هذا النص، بل انه حتى صار مستخدماً وبشكله الأصلي في الطباعة والتنضيد الإلكتروني. انتشر بشكل كبير في ستينيّات هذا القرن مع إصدار رقائق "ليتراسيت" (Letraset) البلاستيكية تحوي مقاطع من هذا النص، وعاد لينتشر مرة أخرى مؤخراَ مع ظهور برامج النشر الإلكتروني مثل "ألدوس بايج مايكر" (Aldus PageMaker) والتي حوت أيضاً على نسخ من نص لوريم إيبسوم.'
|
||||||
|
},
|
||||||
|
snackbar: {
|
||||||
|
'success' : 'تم بنجاح'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,13 @@
|
||||||
|
export default {
|
||||||
|
en: {
|
||||||
|
hello : 'Hello',
|
||||||
|
langBtn : "عربى",
|
||||||
|
home: {
|
||||||
|
content:
|
||||||
|
"What is Lorem Ipsum?Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
|
||||||
|
},
|
||||||
|
snackbar: {
|
||||||
|
'success' : 'Done successfully'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
import en from './en';
|
||||||
|
import ar from './ar';
|
||||||
|
|
||||||
|
const messages = {
|
||||||
|
...ar,
|
||||||
|
...en
|
||||||
|
}
|
||||||
|
|
||||||
|
export default messages;
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 134 KiB |
|
@ -0,0 +1,10 @@
|
||||||
|
import React from "react";
|
||||||
|
import Button from '@material-ui/core/Button';
|
||||||
|
|
||||||
|
export const Btn = ({text , handleClick}) => {
|
||||||
|
return (
|
||||||
|
<Button variant="contained" color="primary" onClick={handleClick}>
|
||||||
|
{text}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,32 @@
|
||||||
|
import React from "react";
|
||||||
|
import { TextField } from "@material-ui/core";
|
||||||
|
|
||||||
|
export const InputField = ({
|
||||||
|
name,
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
error,
|
||||||
|
handleChange,
|
||||||
|
helperText,
|
||||||
|
isMultiline,
|
||||||
|
isRequired
|
||||||
|
}) => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TextField
|
||||||
|
className="my-3"
|
||||||
|
name={name}
|
||||||
|
type="text"
|
||||||
|
label={isRequired ? label+"*" : label}
|
||||||
|
inputProps={{ maxLength: isMultiline ? 500 : 50 }}
|
||||||
|
variant="outlined"
|
||||||
|
fullWidth
|
||||||
|
value={value}
|
||||||
|
error={error}
|
||||||
|
helperText={error && helperText}
|
||||||
|
onChange={handleChange}
|
||||||
|
multiline={isMultiline}
|
||||||
|
rows={isMultiline ? 3 : 1}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,14 @@
|
||||||
|
import React from "react";
|
||||||
|
import "./Loader.scss";
|
||||||
|
|
||||||
|
const Loader = () => {
|
||||||
|
return (
|
||||||
|
<div className="spinnerContainer d-flex justify-content-center align-items-center h-100">
|
||||||
|
<div className="spinner-border text-primary" role="status">
|
||||||
|
<span className="sr-only">Loading...</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Loader;
|
|
@ -0,0 +1,31 @@
|
||||||
|
.spinnerContainer {
|
||||||
|
height: 100vh;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-indicator:before {
|
||||||
|
content: "";
|
||||||
|
background: #000000cc;
|
||||||
|
position: fixed;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-indicator:after {
|
||||||
|
content: "\f1ce";
|
||||||
|
font-family: FontAwesome;
|
||||||
|
position: fixed;
|
||||||
|
width: 100%;
|
||||||
|
top: 50%;
|
||||||
|
left: 0;
|
||||||
|
z-index: 1001;
|
||||||
|
color: white;
|
||||||
|
text-align: center;
|
||||||
|
font-weight: 100;
|
||||||
|
font-size: 4rem;
|
||||||
|
-webkit-animation: fa-spin 1s infinite linear;
|
||||||
|
animation: fa-spin 1s infinite linear;
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
import React from "react";
|
||||||
|
import messages from "./../../assets/Local/messages";
|
||||||
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
|
import { setCurrentLang } from "../../store/Lang/LangAction";
|
||||||
|
import { Link } from "react-router-dom";
|
||||||
|
import { Btn } from "../Controls/Button/Button";
|
||||||
|
|
||||||
|
export default function Navbar() {
|
||||||
|
const lang = useSelector(state => state.lang);
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const message = messages[lang];
|
||||||
|
const switchLanguage = lang => {
|
||||||
|
dispatch(setCurrentLang(lang === "ar" ? "en" : "ar"));
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<nav className="navbar navbar-dark bg-dark">
|
||||||
|
<a className="navbar-brand">{message.hello}</a>
|
||||||
|
<div className="d-flex align-items-center">
|
||||||
|
{/* This private route won't be accessible if no token in lcoal storage */}
|
||||||
|
<Link to="/" className="text-white mx-3">
|
||||||
|
Private Route
|
||||||
|
</Link>
|
||||||
|
<Btn
|
||||||
|
handleClick={() => switchLanguage(lang)}
|
||||||
|
text={message.langBtn}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
const NotFound = () => {
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<div className="text-center">
|
||||||
|
<h1 className="my-5 pt-5">Sorry we can’t find this page</h1>
|
||||||
|
</div>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default NotFound;
|
|
@ -0,0 +1,33 @@
|
||||||
|
import React from "react";
|
||||||
|
import Snackbar from "@material-ui/core/Snackbar";
|
||||||
|
import MuiAlert from "@material-ui/lab/Alert";
|
||||||
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
|
import { hideSnackbarAction } from "../../store/Snackbar/SnackbarAction";
|
||||||
|
|
||||||
|
function Alert(props) {
|
||||||
|
return <MuiAlert elevation={6} variant="filled" {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MaterialSnackbar(props) {
|
||||||
|
const { isOpen, message, type } = useSelector(state => state.snackbar);
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const handleClose = (event, reason) => {
|
||||||
|
if (reason === "clickaway") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dispatch(hideSnackbarAction());
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<Snackbar
|
||||||
|
open={isOpen}
|
||||||
|
autoHideDuration={4000}
|
||||||
|
anchorOrigin={{ vertical: "bottom", horizontal: "center" }}
|
||||||
|
key={`bottom,center`}
|
||||||
|
onClose={() => handleClose}
|
||||||
|
>
|
||||||
|
<Alert onClose={handleClose} severity={type} className="medium_font">
|
||||||
|
{message}
|
||||||
|
</Alert>
|
||||||
|
</Snackbar>
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
import React from "react";
|
||||||
|
import Navbar from "../components/Navbar/Navbar";
|
||||||
|
import { Router } from "react-router-dom";
|
||||||
|
import history from "../routes/History";
|
||||||
|
import Routes from "../routes/Routes";
|
||||||
|
import { IntlProvider } from "react-intl";
|
||||||
|
import messages from "../assets/Local/messages";
|
||||||
|
import { MaterialSnackbar } from "../components/Snackbar/Snackbar";
|
||||||
|
import Loader from "../components/Loader/Loader";
|
||||||
|
import "./App.scss";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
|
||||||
|
class App extends React.Component {
|
||||||
|
// App contains routes and also wrapped with snackbar and intl for localization
|
||||||
|
render() {
|
||||||
|
const { lang , loading } = this.props;
|
||||||
|
return (
|
||||||
|
<IntlProvider locale={lang} messages={messages[lang]}>
|
||||||
|
<div
|
||||||
|
className={lang === "ar" ? "rtl" : "ltr"}
|
||||||
|
dir={lang === "ar" ? "rtl" : "ltr"}
|
||||||
|
>
|
||||||
|
{loading ? <Loader /> : null}
|
||||||
|
<Router history={history}>
|
||||||
|
<MaterialSnackbar />
|
||||||
|
<Navbar />
|
||||||
|
{Routes}
|
||||||
|
</Router>
|
||||||
|
</div>
|
||||||
|
</IntlProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = ({ lang, loading }) => ({
|
||||||
|
lang,
|
||||||
|
loading
|
||||||
|
});
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, null)(App);
|
|
@ -0,0 +1 @@
|
||||||
|
@import '../scss/base.scss';
|
|
@ -0,0 +1,23 @@
|
||||||
|
import React from 'react';
|
||||||
|
import messages from "./../../assets/Local/messages";
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
|
class Home extends React.Component {
|
||||||
|
render(){
|
||||||
|
const { lang } = this.props;
|
||||||
|
const message = messages[lang]
|
||||||
|
return(
|
||||||
|
<div className="container my-5">
|
||||||
|
<p>{message.home.content}</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => {
|
||||||
|
return {
|
||||||
|
lang : state.lang
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps,null)(Home);
|
|
@ -0,0 +1,23 @@
|
||||||
|
import React from 'react';
|
||||||
|
import {Btn} from '../../components/Controls/Button/Button';
|
||||||
|
import History from '../../routes/History';
|
||||||
|
class Login extends React.Component {
|
||||||
|
|
||||||
|
// this method is only to trigger route guards , remove and use your own logic
|
||||||
|
handleLogin = () => {
|
||||||
|
localStorage.setItem('token','token');
|
||||||
|
History.push('/')
|
||||||
|
}
|
||||||
|
|
||||||
|
render(){
|
||||||
|
return(
|
||||||
|
<div className="container my-5">
|
||||||
|
<h1>Login Page</h1>
|
||||||
|
<Btn text='Login' handleClick={this.handleLogin}/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default Login;
|
|
@ -0,0 +1,12 @@
|
||||||
|
import React from "react";
|
||||||
|
import ReactDOM from "react-dom";
|
||||||
|
import { Provider } from "react-redux";
|
||||||
|
import store from "./store";
|
||||||
|
import ThemeApp from "./Theme";
|
||||||
|
|
||||||
|
ReactDOM.render(
|
||||||
|
<Provider store={store}>
|
||||||
|
<ThemeApp />
|
||||||
|
</Provider>,
|
||||||
|
document.querySelector('#root')
|
||||||
|
);
|
|
@ -0,0 +1,19 @@
|
||||||
|
import axios from "axios";
|
||||||
|
import { requestHandler, successHandler, errorHandler } from "../interceptors";
|
||||||
|
import { BASE_URL } from "../../utils/Constants";
|
||||||
|
|
||||||
|
//add your BASE_URL to Constants file
|
||||||
|
export const axiosInstance = axios.create({
|
||||||
|
baseURL: BASE_URL,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle request process
|
||||||
|
axiosInstance.interceptors.request.use(request => requestHandler(request));
|
||||||
|
// Handle response process
|
||||||
|
axiosInstance.interceptors.response.use(
|
||||||
|
response => successHandler(response),
|
||||||
|
error => errorHandler(error)
|
||||||
|
);
|
|
@ -0,0 +1,35 @@
|
||||||
|
import store from "../../store";
|
||||||
|
import { loader } from "../../store/Loader/LoaderAction";
|
||||||
|
import Auth from "../../utils/Auth";
|
||||||
|
|
||||||
|
export const isHandlerEnabled = (config = {}) => {
|
||||||
|
return config.hasOwnProperty("handlerEnabled") && !config.handlerEnabled
|
||||||
|
? false
|
||||||
|
: true;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const requestHandler = request => {
|
||||||
|
if (isHandlerEnabled(request)) {
|
||||||
|
// Modify request here
|
||||||
|
store.dispatch(loader(true));
|
||||||
|
}
|
||||||
|
return request;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const successHandler = response => {
|
||||||
|
if (isHandlerEnabled(response)) {
|
||||||
|
// Hanlde Response
|
||||||
|
store.dispatch(loader(false));
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const errorHandler = error => {
|
||||||
|
if (isHandlerEnabled(error.config)) {
|
||||||
|
store.dispatch(loader(false));
|
||||||
|
// You can decide what you need to do to handle errors.
|
||||||
|
// here's example for unautherized user to log them out .
|
||||||
|
// error.response.status === 401 && Auth.signOut();
|
||||||
|
}
|
||||||
|
return Promise.reject({ ...error });
|
||||||
|
};
|
|
@ -0,0 +1,2 @@
|
||||||
|
import { createBrowserHistory } from "history";
|
||||||
|
export default createBrowserHistory();
|
|
@ -0,0 +1,22 @@
|
||||||
|
import React, { Suspense } from "react";
|
||||||
|
import { Router, Switch } from "react-router-dom";
|
||||||
|
import history from "./History";
|
||||||
|
import * as LazyComponent from "../utils/LazyLoaded";
|
||||||
|
import Loader from "../components/Loader/Loader";
|
||||||
|
import PrivateRoute from "../utils/PrivateRoute";
|
||||||
|
|
||||||
|
const Routes = (
|
||||||
|
<Suspense fallback={<Loader />}>
|
||||||
|
<Router history={history}>
|
||||||
|
<Switch>
|
||||||
|
{/* For private routes */}
|
||||||
|
<PrivateRoute component={LazyComponent.Home} path="/" exact />
|
||||||
|
{/* Public routes that doesn't need any auth */}
|
||||||
|
<LazyComponent.Login path="/login" exact />
|
||||||
|
<LazyComponent.NotFound path="**" title="This page doesn't exist..." exact />
|
||||||
|
</Switch>
|
||||||
|
</Router>
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default Routes;
|
|
@ -0,0 +1 @@
|
||||||
|
// Add you general and shared styles here
|
|
@ -0,0 +1,4 @@
|
||||||
|
.rtl{
|
||||||
|
font-family: Arial, Helvetica, sans-serif;
|
||||||
|
text-align: right;
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
$primaryColor: rgb(50, 61, 165);
|
||||||
|
$secondaryColor : rgba(62, 62, 62, 1);
|
|
@ -0,0 +1,4 @@
|
||||||
|
@import 'bootstrap/scss/bootstrap';
|
||||||
|
@import './variables';
|
||||||
|
@import './rtl';
|
||||||
|
@import './general';
|
|
@ -0,0 +1,11 @@
|
||||||
|
import * as types from "./FeatureTypes";
|
||||||
|
|
||||||
|
//Replace action name and update action types
|
||||||
|
export const actionRequest = () => ({
|
||||||
|
type: types.GET_DATA_REQUEST
|
||||||
|
});
|
||||||
|
|
||||||
|
export const actionReceive = payload => ({
|
||||||
|
type: types.GET_DATA_REQUEST,
|
||||||
|
payload
|
||||||
|
});
|
|
@ -0,0 +1,11 @@
|
||||||
|
import {axiosInstance} from '../../network/apis';
|
||||||
|
const handlerEnabled = false;
|
||||||
|
|
||||||
|
// Replace endpoint and change api name
|
||||||
|
const apiExampleRequest = async () => {
|
||||||
|
return await axiosInstance.get(`ENDPOINT`, { handlerEnabled });
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
apiExampleRequest
|
||||||
|
};
|
|
@ -0,0 +1,16 @@
|
||||||
|
import * as types from "./FeatureTypes";
|
||||||
|
|
||||||
|
const INITIAL_STATE = {};
|
||||||
|
|
||||||
|
// Replace with you own reducer
|
||||||
|
export default (state = INITIAL_STATE, action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case types.GET_DATA_RECEIVE:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
...action.payload
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { call, put } from "redux-saga/effects";
|
||||||
|
import API from "./FeatureApis";
|
||||||
|
import * as ACTIONS from "./FeatureAction";
|
||||||
|
import { dispatchSnackbarError } from "../../utils/Shared";
|
||||||
|
import { takeLatest } from "redux-saga/effects";
|
||||||
|
import * as TYPES from "./FeatureTypes";
|
||||||
|
|
||||||
|
// Replace with your sagas
|
||||||
|
export function* sagasRequestExample() {
|
||||||
|
try {
|
||||||
|
const response = yield call(API.apiExampleRequest);
|
||||||
|
yield put(ACTIONS.actionReceive(response.data));
|
||||||
|
} catch (err) {
|
||||||
|
dispatchSnackbarError(err.response.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function* FeatureSaga1() {
|
||||||
|
yield takeLatest(TYPES.GET_DATA_REQUEST, sagasRequestExample);
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
// Replace with your request types
|
||||||
|
export const GET_DATA_REQUEST = 'GET_DATA_REQUEST';
|
||||||
|
export const GET_DATA_RECEIVE = 'GET_DATA_RECEIVE';
|
|
@ -0,0 +1,10 @@
|
||||||
|
import * as types from './LangTypes';
|
||||||
|
|
||||||
|
export const setCurrentLang = payload => {
|
||||||
|
localStorage.setItem('lang', payload);
|
||||||
|
return { type: types.SET_LANG, payload };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getCurrentLang = () => {
|
||||||
|
return { type: types.GET_LANG };
|
||||||
|
};
|
|
@ -0,0 +1,14 @@
|
||||||
|
import * as types from "./LangTypes";
|
||||||
|
|
||||||
|
const INITIAL_STATE = localStorage.getItem("lang") || "en";
|
||||||
|
|
||||||
|
export default function locale(state = INITIAL_STATE, action) {
|
||||||
|
switch (action.type) {
|
||||||
|
case types.SET_LANG:
|
||||||
|
return action.payload;
|
||||||
|
case types.GET_LANG:
|
||||||
|
return action.payload;
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
export const SET_LANG = 'SET_LANG';
|
||||||
|
export const GET_LANG = 'GET_LANG';
|
|
@ -0,0 +1,13 @@
|
||||||
|
import * as types from "./LoaderTypes";
|
||||||
|
|
||||||
|
export const loader = isLoading => {
|
||||||
|
return isLoading
|
||||||
|
? {
|
||||||
|
type: types.SHOW_LOADER,
|
||||||
|
data: isLoading
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
type: types.HIDE_LOADER,
|
||||||
|
data: isLoading
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,14 @@
|
||||||
|
import * as types from "./LoaderTypes";
|
||||||
|
|
||||||
|
const INITIAL_STATE = false;
|
||||||
|
|
||||||
|
export default (state = INITIAL_STATE, action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case types.SHOW_LOADER:
|
||||||
|
return action.data;
|
||||||
|
case types.HIDE_LOADER:
|
||||||
|
return action.data;
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,2 @@
|
||||||
|
export const SHOW_LOADER = 'SHOW_LOADER';
|
||||||
|
export const HIDE_LOADER = 'HIDE_LOADER';
|
|
@ -0,0 +1,15 @@
|
||||||
|
import * as types from './SnackbarTypes';
|
||||||
|
|
||||||
|
export const showSnackbarAction = (message , snacknarType) => {
|
||||||
|
return {
|
||||||
|
type: types.SHOW_SNACKBAR,
|
||||||
|
message ,
|
||||||
|
snacknarType
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const hideSnackbarAction = () => {
|
||||||
|
return {
|
||||||
|
type: types.HIDE_SNACKBAR
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,21 @@
|
||||||
|
import * as types from "./SnackbarTypes";
|
||||||
|
|
||||||
|
export default (state = {}, action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case types.SHOW_SNACKBAR:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isOpen: true,
|
||||||
|
message: action.message,
|
||||||
|
type: action.snacknarType
|
||||||
|
};
|
||||||
|
case types.HIDE_SNACKBAR:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
isOpen: false
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
export const SHOW_SNACKBAR = 'SHOW_SNACKBAR';
|
||||||
|
export const HIDE_SNACKBAR = 'HIDE_SNACKBAR';
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { createStore, applyMiddleware, compose } from "redux";
|
||||||
|
import reducers from "./reducers";
|
||||||
|
import createSagaMiddleware from "redux-saga";
|
||||||
|
import { watchSagas } from "./sagas";
|
||||||
|
const saga = createSagaMiddleware();
|
||||||
|
//redux dev tool
|
||||||
|
const composeEnhancers =
|
||||||
|
typeof window === "object" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
|
||||||
|
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
|
||||||
|
: compose;
|
||||||
|
const enhancer = composeEnhancers(applyMiddleware(saga));
|
||||||
|
|
||||||
|
const store = createStore(reducers, enhancer);
|
||||||
|
|
||||||
|
saga.run(watchSagas);
|
||||||
|
|
||||||
|
export default store;
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { combineReducers } from "redux";
|
||||||
|
import lang from "../Lang/LangReducer";
|
||||||
|
import loader from "../Loader/LoaderReducer";
|
||||||
|
import snackbar from "../Snackbar/SnackbarReducer";
|
||||||
|
import Feature1 from "../Feature1/FeatureReducer";
|
||||||
|
|
||||||
|
export default combineReducers({
|
||||||
|
lang,
|
||||||
|
loader,
|
||||||
|
snackbar,
|
||||||
|
Feature1
|
||||||
|
});
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { FeatureSaga1 } from '../Feature1/FeatureSagas';
|
||||||
|
import { fork, all } from "redux-saga/effects";
|
||||||
|
|
||||||
|
export function* watchSagas() {
|
||||||
|
//Combine sagas with
|
||||||
|
yield all([FeatureSaga1()]);
|
||||||
|
// OR
|
||||||
|
// yield all([fork(FeatureSaga1)]);
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
// Service to check authentication for user and to signOut
|
||||||
|
const Auth = {
|
||||||
|
signOut() {
|
||||||
|
localStorage.removeItem("token");
|
||||||
|
},
|
||||||
|
isAuth() {
|
||||||
|
return localStorage.getItem("token");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
export default Auth;
|
|
@ -0,0 +1 @@
|
||||||
|
export const BASE_URL = 'BASE_URL';
|
|
@ -0,0 +1,5 @@
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
export const Home = React.lazy(() => import('../containers/Home/Home'));
|
||||||
|
export const Login = React.lazy(() => import('../containers/Login/Login'));
|
||||||
|
export const NotFound = React.lazy(() => import('../components/NotFound/NotFound'));
|
|
@ -0,0 +1,18 @@
|
||||||
|
import React from "react";
|
||||||
|
import { Route, Redirect } from "react-router-dom";
|
||||||
|
import Auth from "../utils/Auth";
|
||||||
|
|
||||||
|
const PrivateRoute = ({ component: Component, ...rest }) => {
|
||||||
|
return (
|
||||||
|
// Show the component only when the user is logged in
|
||||||
|
// Otherwise, redirect the user to /signin page
|
||||||
|
<Route
|
||||||
|
{...rest}
|
||||||
|
render={props =>
|
||||||
|
Auth.isAuth() ? <Component {...props} /> : <Redirect to="/login" />
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PrivateRoute;
|
|
@ -0,0 +1,18 @@
|
||||||
|
import store from "../store";
|
||||||
|
import { showSnackbarAction } from "../store/Snackbar/SnackbarAction";
|
||||||
|
import messages from "../assets/Local/messages";
|
||||||
|
|
||||||
|
// To show error message that returned from backend
|
||||||
|
export function dispatchSnackbarError(data) {
|
||||||
|
if (data) {
|
||||||
|
const errorMsg = data.error.message;
|
||||||
|
store.dispatch(showSnackbarAction(errorMsg, "error"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// To show success message after any success request if needed and rendered from locale files
|
||||||
|
export function dispatchSnackbarSuccess(message) {
|
||||||
|
const lang = store.getState().lang;
|
||||||
|
store.dispatch(
|
||||||
|
showSnackbarAction(messages[lang].snackbar[message], "success")
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue