7 |
8 | پروژه پنل مدیریت یک پروژه به کمک اعضای انجمن ری اکت ایران است که هدف آن بالابردن تجربه و افزایش بار علمی انجمن است .
9 |
10 |
11 |
12 | #### لیست پکیج های فنی پروژه
13 |
14 | هر پروژه برای شروع نیاز به یک هماهنگی و نیاز های فنی دارد که در راستای انجام پروژه ، بتواند تیم را در مسیر صحیحی قرار دهد .
15 |
16 |
17 |
18 | در صورتی که برای هر کدام از پکیج ها جایگزینی مد نظر دارید یا نیاز بهتری را احساس میکنید ، لطفا در issue ها بنویسید .
19 |
20 |
21 |
22 | شروع پروژه با استفاده از cra یا همان create-react-app است .
23 |
24 | |نام | کاربرد |
25 | |-------|-----|
26 | | [ react router dom 4 ](https://www.npmjs.com/package/react-router-dom)| ایجاد روتر و لینک کردن |
27 | | [ material-ui ](https://material-ui.com/getting-started/installation/) | یک ui kit برای متریال |
28 | | [ axios ](https://www.npmjs.com/package/axios) | ارسال درخواست ها به API |
29 | | [ redux ](https://redux.js.org/introduction/installation) | مدیریت state ها |
30 | | [ react helmet ](https://www.npmjs.com/package/react-helmet) | مدیریت Meta ها در هدر |
31 |
32 | #### نیاز های برطرف نشده پروژه
33 |
34 | - طرح ui
35 |
36 | #### مدیریت پروژه در Trello
37 |
38 | برای رعایت نظم اجرای پروژه ، لطفا in progress های هر Board که علاقه به انجام آن را دارید را تکمیل کنید.
39 |
40 | [ لینک ترلو پروژه ](https://trello.com/reactpanelproject)
41 |
42 | بورد ها بعد از اتمام ، به روز شده و todo جدید جایگزین میشوند .
43 |
44 |
45 | #### نحوه همکاری
46 |
47 | - به منظور همکاری در پروژه ابتدا ریپوزیتوری را fork کنید و بر اساس Trello ، task های مانده را انجام بدید
48 | - پس از تکمیل کار انجام شده ، لطفا pull request بدید
49 | - در صورت یافتن باگ , به صورت یک issue آن را مطرح و پس از pull request دادن ، شماره pull request را در ایشو اعلام میکنیم .
50 |
51 |
52 | ##### API
53 | api routes are in progress and will be completed as soon as we can .
54 |
55 | ###### admin routes
56 | | name | router address | params | description |
57 | | ------------- | ------------- | ------------- | ------------- |
58 | | login admin | Post `shop.nimahabibkhoda.ir/api/v1/admin/login` | email,password | email is : admin@admin.com , password : admin123456 |
59 | | get products | Get `shop.nimahabibkhoda.ir/api/v1/admin/products` | authorization : Bearer < TOKEN HERE > | it will show last 10 new created products |
60 | | insert into products | Post `shop.nimahabibkhoda.ir/api/v1/admin/products/insert` | permalink,title,price,description,published,tags(tag1,tag2,tag3),optJson ({"رنگ":{"optName":"رنگ","optLabel":"رنگ","optType":"radio","optOptions":["قرمز","آبی"]}}),stock | insert new product into database |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "persian-admin-panel",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@material-ui/core": "^3.9.3",
7 | "@material-ui/icons": "^3.0.2",
8 | "axios": "^0.18.0",
9 | "prop-types": "^15.7.2",
10 | "react": "^16.8.6",
11 | "react-dom": "^16.8.6",
12 | "react-recaptcha-v3": "^1.1.0",
13 | "react-router-dom": "^5.0.0",
14 | "react-scripts": "2.1.8",
15 | "redux": "^4.0.1"
16 | },
17 | "scripts": {
18 | "start": "react-scripts start",
19 | "build": "react-scripts build",
20 | "test": "react-scripts test",
21 | "eject": "react-scripts eject"
22 | },
23 | "eslintConfig": {
24 | "extends": "react-app"
25 | },
26 | "browserslist": [
27 | ">0.2%",
28 | "not dead",
29 | "not ie <= 11",
30 | "not op_mini all"
31 | ]
32 | }
33 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iran-react-community/persian-admin-panel/7f95cfdedbc051fded6985af76186b8a037a892b/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
10 |
11 |
15 |
16 |
25 | React App
26 |
27 |
28 |
29 |
30 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/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 | "start_url": ".",
12 | "display": "standalone",
13 | "theme_color": "#000000",
14 | "background_color": "#ffffff"
15 | }
16 |
--------------------------------------------------------------------------------
/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | }
4 |
5 | .App-logo {
6 | animation: App-logo-spin infinite 20s linear;
7 | height: 40vmin;
8 | pointer-events: none;
9 | }
10 |
11 | .App-header {
12 | background-color: #282c34;
13 | min-height: 100vh;
14 | display: flex;
15 | flex-direction: column;
16 | align-items: center;
17 | justify-content: center;
18 | font-size: calc(10px + 2vmin);
19 | color: white;
20 | }
21 |
22 | .App-link {
23 | color: #61dafb;
24 | }
25 |
26 | @keyframes App-logo-spin {
27 | from {
28 | transform: rotate(0deg);
29 | }
30 | to {
31 | transform: rotate(360deg);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import { Route, BrowserRouter as Router } from "react-router-dom";
3 | import Dashboard from "./Component/Dashboard/index";
4 | import PrivateRoute from './Component/Utilities/PrivateRoutes'
5 | import Login from './Component/Login/index'
6 |
7 | function App() {
8 |
9 |
10 | return (
11 |
12 |
13 |
14 |
15 | )
16 |
17 | }
18 |
19 |
20 | export default App;
21 |
--------------------------------------------------------------------------------
/src/App.test.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import App from './App';
4 |
5 | it('renders without crashing', () => {
6 | const div = document.createElement('div');
7 | ReactDOM.render(, div);
8 | ReactDOM.unmountComponentAtNode(div);
9 | });
10 |
--------------------------------------------------------------------------------
/src/Component/Dashboard/index.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iran-react-community/persian-admin-panel/7f95cfdedbc051fded6985af76186b8a037a892b/src/Component/Dashboard/index.js
--------------------------------------------------------------------------------
/src/Component/Login/index.js:
--------------------------------------------------------------------------------
1 | import React, { useEffect, useState } from 'react';
2 | import axios from 'axios'
3 | import PropTypes from 'prop-types';
4 | import Avatar from '@material-ui/core/Avatar';
5 | import Button from '@material-ui/core/Button';
6 | import CssBaseline from '@material-ui/core/CssBaseline';
7 | import FormControl from '@material-ui/core/FormControl';
8 | import FormControlLabel from '@material-ui/core/FormControlLabel';
9 | import Checkbox from '@material-ui/core/Checkbox';
10 | import Input from '@material-ui/core/Input';
11 | import InputLabel from '@material-ui/core/InputLabel';
12 | import LockOutlinedIcon from '@material-ui/icons/LockOutlined';
13 | import Paper from '@material-ui/core/Paper';
14 | import Typography from '@material-ui/core/Typography';
15 | import withStyles from '@material-ui/core/styles/withStyles';
16 | import * as config from '../Utilities/config'
17 |
18 |
19 | const styles = theme => ({
20 | main: {
21 | width: 'auto',
22 | display: 'block', // Fix IE 11 issue.
23 | marginLeft: theme.spacing.unit * 3,
24 | marginRight: theme.spacing.unit * 3,
25 | [theme.breakpoints.up(400 + theme.spacing.unit * 3 * 2)]: {
26 | width: 400,
27 | marginLeft: 'auto',
28 | marginRight: 'auto',
29 | },
30 | },
31 | paper: {
32 | marginTop: theme.spacing.unit * 8,
33 | display: 'flex',
34 | flexDirection: 'column',
35 | alignItems: 'center',
36 | padding: `${theme.spacing.unit * 2}px ${theme.spacing.unit * 3}px ${theme.spacing.unit * 3}px`,
37 | },
38 | avatar: {
39 | margin: theme.spacing.unit,
40 | backgroundColor: theme.palette.secondary.main,
41 | },
42 | form: {
43 | width: '100%', // Fix IE 11 issue.
44 | marginTop: theme.spacing.unit,
45 | },
46 | submit: {
47 | marginTop: theme.spacing.unit * 3,
48 | },
49 | loginAlert:{
50 | padding:10,
51 | backgroundColor:'#e10026',
52 | color:'#ffffff',
53 | textAlign:'center',
54 | marginTop:10
55 | }
56 | });
57 |
58 | function Login(props) {
59 |
60 | const [email, setEMail] = useState(null);
61 | const [password, setPassword] = useState(null);
62 | const [auth, setAuth] = useState(false);
63 | const [token, setToken] = useState(null);
64 | const [showError, setShowError] = useState("");
65 |
66 | function handleEmail(e) {
67 | setEMail(e.target.value);
68 |
69 | }
70 |
71 | function handlePassword(e) {
72 | setPassword(e.target.value);
73 |
74 | }
75 |
76 | function handleSubmit(e) {
77 | e.preventDefault()
78 | axios({
79 | method: 'POST',
80 | url: config.Routers.Login_API,
81 | headers: {
82 | 'Content-Type': 'application/json',
83 | },
84 | data: {
85 | email: { email },
86 | password: { password }
87 | },
88 | }).then((res) => {
89 | if (res.data.status === 200) {
90 | setAuth(true);
91 | setToken(res.data.result.token);
92 | localStorage.setItem(token, { token });
93 | redirect();
94 | }
95 | else{
96 | setShowError(config.messages.Login_Alert)
97 | }
98 | }).catch((err) => {
99 | setShowError(config.messages.Login_Alert)
100 | })
101 |
102 | }
103 |
104 | function redirect() {
105 | props.history.push('/dashboard');
106 | }
107 |
108 | const { classes } = props;
109 |
110 | return (
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 | Sign in
119 |
120 |
150 |
151 |
152 | );
153 | }
154 |
155 | Login.propTypes = {
156 | classes: PropTypes.object.isRequired,
157 | };
158 |
159 | export default withStyles(styles)(Login);
--------------------------------------------------------------------------------
/src/Component/Utilities/PrivateRoutes.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Redirect, Route } from 'react-router-dom'
3 |
4 | const PrivateRoute = ({ component: Component, ...rest }) => (
5 |
8 | Auth.isAuthenticated ? :
9 | }
10 | />
11 | )
12 |
13 | const Auth = {
14 | isAuthenticated : false,
15 | authenticate(){
16 | this.isAuthenticated = true
17 | }
18 | }
19 |
20 | export default PrivateRoute;
--------------------------------------------------------------------------------
/src/Component/Utilities/config.js:
--------------------------------------------------------------------------------
1 | const server="http://shop.nimahabibkhoda.ir/api/v1/"
2 |
3 | export const Routers = {
4 | "Login_API":server+"admin/login"
5 | }
6 |
7 | export const messages={
8 | "Login_Alert":"خطا در ارسال داده ها"
9 | }
--------------------------------------------------------------------------------
/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | padding: 0;
4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
5 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
6 | sans-serif;
7 | -webkit-font-smoothing: antialiased;
8 | -moz-osx-font-smoothing: grayscale;
9 | }
10 |
11 | code {
12 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
13 | monospace;
14 | }
15 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom';
3 | import './index.css';
4 | import App from './App';
5 | import * as serviceWorker from './serviceWorker';
6 |
7 | ReactDOM.render(, document.getElementById('root'));
8 |
9 | // If you want your app to work offline and load faster, you can change
10 | // unregister() to register() below. Note this comes with some pitfalls.
11 | // Learn more about service workers: https://bit.ly/CRA-PWA
12 | serviceWorker.unregister();
13 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/src/serviceWorker.js:
--------------------------------------------------------------------------------
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 | export function register(config) {
24 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
25 | // The URL constructor is available in all browsers that support SW.
26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
27 | if (publicUrl.origin !== window.location.origin) {
28 | // Our service worker won't work if PUBLIC_URL is on a different origin
29 | // from what our page is served on. This might happen if a CDN is used to
30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374
31 | return;
32 | }
33 |
34 | window.addEventListener('load', () => {
35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
36 |
37 | if (isLocalhost) {
38 | // This is running on localhost. Let's check if a service worker still exists or not.
39 | checkValidServiceWorker(swUrl, config);
40 |
41 | // Add some additional logging to localhost, pointing developers to the
42 | // service worker/PWA documentation.
43 | navigator.serviceWorker.ready.then(() => {
44 | console.log(
45 | 'This web app is being served cache-first by a service ' +
46 | 'worker. To learn more, visit https://bit.ly/CRA-PWA'
47 | );
48 | });
49 | } else {
50 | // Is not localhost. Just register service worker
51 | registerValidSW(swUrl, config);
52 | }
53 | });
54 | }
55 | }
56 |
57 | function registerValidSW(swUrl, config) {
58 | navigator.serviceWorker
59 | .register(swUrl)
60 | .then(registration => {
61 | registration.onupdatefound = () => {
62 | const installingWorker = registration.installing;
63 | if (installingWorker == null) {
64 | return;
65 | }
66 | installingWorker.onstatechange = () => {
67 | if (installingWorker.state === 'installed') {
68 | if (navigator.serviceWorker.controller) {
69 | // At this point, the updated precached content has been fetched,
70 | // but the previous service worker will still serve the older
71 | // content until all client tabs are closed.
72 | console.log(
73 | 'New content is available and will be used when all ' +
74 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
75 | );
76 |
77 | // Execute callback
78 | if (config && config.onUpdate) {
79 | config.onUpdate(registration);
80 | }
81 | } else {
82 | // At this point, everything has been precached.
83 | // It's the perfect time to display a
84 | // "Content is cached for offline use." message.
85 | console.log('Content is cached for offline use.');
86 |
87 | // Execute callback
88 | if (config && config.onSuccess) {
89 | config.onSuccess(registration);
90 | }
91 | }
92 | }
93 | };
94 | };
95 | })
96 | .catch(error => {
97 | console.error('Error during service worker registration:', error);
98 | });
99 | }
100 |
101 | function checkValidServiceWorker(swUrl, config) {
102 | // Check if the service worker can be found. If it can't reload the page.
103 | fetch(swUrl)
104 | .then(response => {
105 | // Ensure service worker exists, and that we really are getting a JS file.
106 | const contentType = response.headers.get('content-type');
107 | if (
108 | response.status === 404 ||
109 | (contentType != null && contentType.indexOf('javascript') === -1)
110 | ) {
111 | // No service worker found. Probably a different app. Reload the page.
112 | navigator.serviceWorker.ready.then(registration => {
113 | registration.unregister().then(() => {
114 | window.location.reload();
115 | });
116 | });
117 | } else {
118 | // Service worker found. Proceed as normal.
119 | registerValidSW(swUrl, config);
120 | }
121 | })
122 | .catch(() => {
123 | console.log(
124 | 'No internet connection found. App is running in offline mode.'
125 | );
126 | });
127 | }
128 |
129 | export function unregister() {
130 | if ('serviceWorker' in navigator) {
131 | navigator.serviceWorker.ready.then(registration => {
132 | registration.unregister();
133 | });
134 | }
135 | }
136 |
--------------------------------------------------------------------------------