From ed457e470f9d5ec8f6924f24c0ab6c5976e70168 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Mon, 27 May 2019 14:39:22 +0200 Subject: [PATCH 01/10] add main menu navigation and door lock charges page --- client/package.json | 4 +- client/src/App.js | 9 ++- client/src/components/MainMenu/index.js | 15 ++++ client/src/constants/menuItems.js | 15 ++++ client/src/index.js | 1 + client/src/scenes/DoorLockCharges/index.js | 18 +++++ client/src/scenes/Home/index.js | 3 + client/src/scenes/NotFound/index.js | 3 + client/yarn.lock | 81 +++++++++++++++++++++- 9 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 client/src/components/MainMenu/index.js create mode 100644 client/src/constants/menuItems.js create mode 100644 client/src/scenes/DoorLockCharges/index.js diff --git a/client/package.json b/client/package.json index 0f3575a..c5cd1e0 100644 --- a/client/package.json +++ b/client/package.json @@ -6,7 +6,9 @@ "react": "^16.8.6", "react-dom": "^16.8.6", "react-router-dom": "^5.0.0", - "react-scripts": "3.0.1" + "react-scripts": "3.0.1", + "semantic-ui-css": "^2.4.1", + "semantic-ui-react": "^0.87.1" }, "scripts": { "start": "react-scripts start", diff --git a/client/src/App.js b/client/src/App.js index 5cc7ef6..ab6f9ba 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,15 +1,20 @@ import React, { Component } from 'react'; import './App.css'; import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'; -import Home from './scenes/Home'; + import NotFound from './scenes/NotFound'; +import { mainMenuItems } from './constants/menuItems'; + class App extends Component { render() { return ( - + { + mainMenuItems.map(mainMenuItem => + ) + } diff --git a/client/src/components/MainMenu/index.js b/client/src/components/MainMenu/index.js new file mode 100644 index 0000000..6b3b264 --- /dev/null +++ b/client/src/components/MainMenu/index.js @@ -0,0 +1,15 @@ +import React from 'react'; +import { NavLink } from 'react-router-dom'; +import { Menu } from 'semantic-ui-react'; + +import { mainMenuItems} from "../../constants/menuItems"; + +const MainMenu = () => + ( + { + mainMenuItems.map(mainMenuItem => + {mainMenuItem.title}) + } + ); + +export default MainMenu; diff --git a/client/src/constants/menuItems.js b/client/src/constants/menuItems.js new file mode 100644 index 0000000..ced64bb --- /dev/null +++ b/client/src/constants/menuItems.js @@ -0,0 +1,15 @@ +import DoorLockCharges from "../scenes/DoorLockCharges"; +import Home from "../scenes/Home"; + +export const mainMenuItems = [ + { + title: 'Home', + url: '/', + component: Home, + }, + { + title: 'Door Lock Charges', + url: '/door-lock-charges', + component: DoorLockCharges, + }, +]; diff --git a/client/src/index.js b/client/src/index.js index 87d1be5..59d987f 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -1,6 +1,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; import './index.css'; +import 'semantic-ui-css/semantic.min.css'; import App from './App'; import * as serviceWorker from './serviceWorker'; diff --git a/client/src/scenes/DoorLockCharges/index.js b/client/src/scenes/DoorLockCharges/index.js new file mode 100644 index 0000000..9e533bf --- /dev/null +++ b/client/src/scenes/DoorLockCharges/index.js @@ -0,0 +1,18 @@ +import React, { Component } from 'react'; + +import MainMenu from '../../components/MainMenu'; + +class DoorLockCharges extends Component { + + render () { + return ( +
+ +

Door Lock Charges

+
+
+ ); + } +} + +export default DoorLockCharges; diff --git a/client/src/scenes/Home/index.js b/client/src/scenes/Home/index.js index 1021f53..170a9ed 100644 --- a/client/src/scenes/Home/index.js +++ b/client/src/scenes/Home/index.js @@ -1,5 +1,7 @@ import React, { Component } from 'react'; +import MainMenu from '../../components/MainMenu'; + class Home extends Component { state = { apiStatus: 'loading', @@ -24,6 +26,7 @@ class Home extends Component { const {apiStatus} = this.state; return (
+

CRM Integration


Integration API Status : {apiStatus}
diff --git a/client/src/scenes/NotFound/index.js b/client/src/scenes/NotFound/index.js index 650f551..f63157a 100644 --- a/client/src/scenes/NotFound/index.js +++ b/client/src/scenes/NotFound/index.js @@ -1,8 +1,11 @@ import React from 'react'; +import MainMenu from "../../components/MainMenu"; export default function NotFound () { return (
+ +

Page not found

); diff --git a/client/yarn.lock b/client/yarn.lock index 89276a9..856d5a0 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -981,6 +981,13 @@ version "1.1.3" resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b" +"@semantic-ui-react/event-stack@^3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@semantic-ui-react/event-stack/-/event-stack-3.1.0.tgz#aadbe4a28b0dd7703c5f451640d0fefe66dd9208" + dependencies: + exenv "^1.2.2" + prop-types "^15.6.2" + "@svgr/babel-plugin-add-jsx-attribute@^4.2.0": version "4.2.0" resolved "https://registry.yarnpkg.com/@svgr/babel-plugin-add-jsx-attribute/-/babel-plugin-add-jsx-attribute-4.2.0.tgz#dadcb6218503532d6884b210e7f3c502caaa44b1" @@ -2126,6 +2133,10 @@ class-utils@^0.3.5: isobject "^3.0.0" static-extend "^0.1.1" +classnames@^2.2.6: + version "2.2.6" + resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.6.tgz#43935bffdd291f326dad0a205309b38d00f650ce" + clean-css@4.2.x: version "4.2.1" resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-4.2.1.tgz#2d411ef76b8569b6d0c84068dabe85b0aa5e5c17" @@ -2424,6 +2435,13 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4: safe-buffer "^5.0.1" sha.js "^2.4.8" +create-react-context@<=0.2.2: + version "0.2.2" + resolved "https://registry.yarnpkg.com/create-react-context/-/create-react-context-0.2.2.tgz#9836542f9aaa22868cd7d4a6f82667df38019dca" + dependencies: + fbjs "^0.8.0" + gud "^1.0.0" + create-react-context@^0.2.2: version "0.2.3" resolved "https://registry.yarnpkg.com/create-react-context/-/create-react-context-0.2.3.tgz#9ec140a6914a22ef04b8b09b7771de89567cb6f3" @@ -3258,6 +3276,10 @@ execa@^1.0.0: signal-exit "^3.0.0" strip-eof "^1.0.0" +exenv@^1.2.2: + version "1.2.2" + resolved "https://registry.yarnpkg.com/exenv/-/exenv-1.2.2.tgz#2ae78e85d9894158670b03d47bec1f03bd91bb9d" + exit@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c" @@ -4868,6 +4890,10 @@ jest@24.7.1: import-local "^2.0.0" jest-cli "^24.7.1" +jquery@x.*: + version "3.4.1" + resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.4.1.tgz#714f1f8d9dde4bdfa55764ba37ef214630d80ef2" + js-levenshtein@^1.1.3: version "1.1.6" resolved "https://registry.yarnpkg.com/js-levenshtein/-/js-levenshtein-1.1.6.tgz#c6cee58eb3550372df8deb85fad5ce66ce01d59d" @@ -5028,6 +5054,10 @@ jsx-ast-utils@^2.0.1: dependencies: array-includes "^3.0.3" +keyboard-key@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/keyboard-key/-/keyboard-key-1.0.4.tgz#52d8fa07b7e17757072aa22a67fb4ae85e4c46b0" + killable@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.1.tgz#4c8ce441187a061c7474fb87ca08e2a638194892" @@ -6097,6 +6127,10 @@ pnp-webpack-plugin@1.2.1: dependencies: ts-pnp "^1.0.0" +popper.js@^1.14.4: + version "1.15.0" + resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.15.0.tgz#5560b99bbad7647e9faa475c6b8056621f5a4ff2" + portfinder@^1.0.9: version "1.0.20" resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.20.tgz#bea68632e54b2e13ab7b0c4775e9b41bf270e44a" @@ -6745,7 +6779,7 @@ prompts@^2.0.1: kleur "^3.0.2" sisteransi "^1.0.0" -prop-types@^15.6.2: +prop-types@^15.6.1, prop-types@^15.6.2: version "15.7.2" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" dependencies: @@ -6942,6 +6976,17 @@ react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4: version "16.8.6" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16" +react-popper@^1.3.3: + version "1.3.3" + resolved "https://registry.yarnpkg.com/react-popper/-/react-popper-1.3.3.tgz#2c6cef7515a991256b4f0536cd4bdcb58a7b6af6" + dependencies: + "@babel/runtime" "^7.1.2" + create-react-context "<=0.2.2" + popper.js "^1.14.4" + prop-types "^15.6.1" + typed-styles "^0.0.7" + warning "^4.0.2" + react-router-dom@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-5.0.0.tgz#542a9b86af269a37f0b87218c4c25ea8dcf0c073" @@ -7434,6 +7479,26 @@ selfsigned@^1.9.1: dependencies: node-forge "0.7.5" +semantic-ui-css@^2.4.1: + version "2.4.1" + resolved "https://registry.yarnpkg.com/semantic-ui-css/-/semantic-ui-css-2.4.1.tgz#f5aea39fafb787cbd905ec724272a3f9cba9004a" + dependencies: + jquery x.* + +semantic-ui-react@^0.87.1: + version "0.87.1" + resolved "https://registry.yarnpkg.com/semantic-ui-react/-/semantic-ui-react-0.87.1.tgz#249cca258fe05ee0a7095d8be0b3a749f34a1837" + dependencies: + "@babel/runtime" "^7.1.2" + "@semantic-ui-react/event-stack" "^3.1.0" + classnames "^2.2.6" + keyboard-key "^1.0.4" + lodash "^4.17.11" + prop-types "^15.6.2" + react-is "^16.7.0" + react-popper "^1.3.3" + shallowequal "^1.1.0" + "semver@2 || 3 || 4 || 5", semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0: version "5.7.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.0.tgz#790a7cf6fea5459bac96110b29b60412dc8ff96b" @@ -7551,6 +7616,10 @@ shallow-clone@^1.0.0: kind-of "^5.0.0" mixin-object "^2.0.1" +shallowequal@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/shallowequal/-/shallowequal-1.1.0.tgz#188d521de95b9087404fd4dcb68b13df0ae4e7f8" + shebang-command@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" @@ -8174,6 +8243,10 @@ type-is@~1.6.17, type-is@~1.6.18: media-typer "0.3.0" mime-types "~2.1.24" +typed-styles@^0.0.7: + version "0.0.7" + resolved "https://registry.yarnpkg.com/typed-styles/-/typed-styles-0.0.7.tgz#93392a008794c4595119ff62dde6809dbc40a3d9" + typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" @@ -8450,6 +8523,12 @@ walker@^1.0.7, walker@~1.0.5: dependencies: makeerror "1.0.x" +warning@^4.0.2: + version "4.0.3" + resolved "https://registry.yarnpkg.com/warning/-/warning-4.0.3.tgz#16e9e077eb8a86d6af7d64aa1e05fd85b4678ca3" + dependencies: + loose-envify "^1.0.0" + watchpack@^1.5.0: version "1.6.0" resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.6.0.tgz#4bc12c2ebe8aa277a71f1d3f14d685c7b446cd00" From 790582ceda074932bf529185f101908906e6a99b Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Mon, 27 May 2019 19:35:00 +0200 Subject: [PATCH 02/10] fix code style --- client/src/components/MainMenu/index.js | 2 +- client/src/scenes/Home/index.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/client/src/components/MainMenu/index.js b/client/src/components/MainMenu/index.js index 6b3b264..80c9621 100644 --- a/client/src/components/MainMenu/index.js +++ b/client/src/components/MainMenu/index.js @@ -2,7 +2,7 @@ import React from 'react'; import { NavLink } from 'react-router-dom'; import { Menu } from 'semantic-ui-react'; -import { mainMenuItems} from "../../constants/menuItems"; +import { mainMenuItems } from "../../constants/menuItems"; const MainMenu = () => ( diff --git a/client/src/scenes/Home/index.js b/client/src/scenes/Home/index.js index 170a9ed..f4012bf 100644 --- a/client/src/scenes/Home/index.js +++ b/client/src/scenes/Home/index.js @@ -1,5 +1,7 @@ import React, { Component } from 'react'; +import { Container } from 'semantic-ui-react'; + import MainMenu from '../../components/MainMenu'; class Home extends Component { @@ -25,12 +27,12 @@ class Home extends Component { render () { const {apiStatus} = this.state; return ( -
+

CRM Integration


Integration API Status : {apiStatus}
-
+ ); } } From d3f8810c7cdb925ff5cbe4b7f7e21035a84dd41b Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Mon, 27 May 2019 19:35:22 +0200 Subject: [PATCH 03/10] add form for door lock charge report --- client/src/scenes/DoorLockCharges/index.js | 29 ++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/client/src/scenes/DoorLockCharges/index.js b/client/src/scenes/DoorLockCharges/index.js index 9e533bf..52020ee 100644 --- a/client/src/scenes/DoorLockCharges/index.js +++ b/client/src/scenes/DoorLockCharges/index.js @@ -1,16 +1,41 @@ import React, { Component } from 'react'; +import { Container, Form } from "semantic-ui-react"; + import MainMenu from '../../components/MainMenu'; class DoorLockCharges extends Component { render () { return ( -
+

Door Lock Charges


-
+
+ + + + + + Generate Report + + ); } } From 64ed7585939734b2be09f47f9aead8bfcd4a3a61 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Tue, 28 May 2019 01:28:14 +0200 Subject: [PATCH 04/10] add key to react components --- client/src/App.js | 6 +++++- client/src/components/MainMenu/index.js | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/client/src/App.js b/client/src/App.js index ab6f9ba..a773083 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -13,7 +13,11 @@ class App extends Component { { mainMenuItems.map(mainMenuItem => - ) + ) } diff --git a/client/src/components/MainMenu/index.js b/client/src/components/MainMenu/index.js index 80c9621..8581220 100644 --- a/client/src/components/MainMenu/index.js +++ b/client/src/components/MainMenu/index.js @@ -8,7 +8,13 @@ const MainMenu = () => ( { mainMenuItems.map(mainMenuItem => - {mainMenuItem.title}) + + {mainMenuItem.title} + ) } ); From 0f0fc497502e33a2289e389ab75bbd0a7bb28297 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Tue, 28 May 2019 04:38:14 +0200 Subject: [PATCH 05/10] add key to react components --- client/src/constants/menuItems.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/src/constants/menuItems.js b/client/src/constants/menuItems.js index ced64bb..cc0c1be 100644 --- a/client/src/constants/menuItems.js +++ b/client/src/constants/menuItems.js @@ -3,11 +3,13 @@ import Home from "../scenes/Home"; export const mainMenuItems = [ { + id: 'home', title: 'Home', url: '/', component: Home, }, { + id: 'doorLockCharges', title: 'Door Lock Charges', url: '/door-lock-charges', component: DoorLockCharges, From 0100f15960cfa46c35ddd839774ccabc76aee6fa Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Tue, 28 May 2019 04:38:53 +0200 Subject: [PATCH 06/10] add door lock charges controller --- controllers/doorLockCharges.js | 22 ++++++++++++++++++++++ routes/index.js | 2 ++ 2 files changed, 24 insertions(+) create mode 100644 controllers/doorLockCharges.js diff --git a/controllers/doorLockCharges.js b/controllers/doorLockCharges.js new file mode 100644 index 0000000..54948f8 --- /dev/null +++ b/controllers/doorLockCharges.js @@ -0,0 +1,22 @@ +'use strict'; + +const calculateDoorLockCharges = (req, res) => { + res.json([ + { + member: 'Dummy Member A', + date: new Date(), + room: 'Blue room', + fee: 10, + }, + { + member: 'Dummy Member B', + date: new Date(), + room: 'White room', + fee: 20, + } + ]); +}; + +module.exports = { + calculateDoorLockCharges, +}; diff --git a/routes/index.js b/routes/index.js index 98cd0a1..83ec460 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,10 +1,12 @@ 'use strict'; const { apiStatusCheck } = require('../controllers/apiStatusCheck'); +const { calculateDoorLockCharges } = require('../controllers/doorLockCharges'); const express = require('express'); const router = express.Router(); router.get('/', apiStatusCheck); +router.get('/doorLockCharges', calculateDoorLockCharges); module.exports = router; From 6cc3643501eb11c98d43cf212bf1dd9aaa8aacc7 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Tue, 28 May 2019 04:39:50 +0200 Subject: [PATCH 07/10] install and use redux to fetch data from server --- client/package.json | 3 ++ client/src/index.js | 8 ++++- client/src/scenes/DoorLockCharges/index.js | 23 ++++++++++-- client/src/store/actions/doorLockActions.js | 17 +++++++++ client/src/store/actions/index.js | 1 + client/src/store/constants.js | 3 ++ client/src/store/reducers/doorLockReducers.js | 35 +++++++++++++++++++ client/src/store/reducers/index.js | 8 +++++ client/yarn.lock | 34 +++++++++++++++--- 9 files changed, 124 insertions(+), 8 deletions(-) create mode 100644 client/src/store/actions/doorLockActions.js create mode 100644 client/src/store/actions/index.js create mode 100644 client/src/store/constants.js create mode 100644 client/src/store/reducers/doorLockReducers.js create mode 100644 client/src/store/reducers/index.js diff --git a/client/package.json b/client/package.json index c5cd1e0..a44f884 100644 --- a/client/package.json +++ b/client/package.json @@ -5,8 +5,11 @@ "dependencies": { "react": "^16.8.6", "react-dom": "^16.8.6", + "react-redux": "^7.0.3", "react-router-dom": "^5.0.0", "react-scripts": "3.0.1", + "redux": "^4.0.1", + "redux-thunk": "^2.3.0", "semantic-ui-css": "^2.4.1", "semantic-ui-react": "^0.87.1" }, diff --git a/client/src/index.js b/client/src/index.js index 59d987f..df0e4a4 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -4,8 +4,14 @@ import './index.css'; import 'semantic-ui-css/semantic.min.css'; import App from './App'; import * as serviceWorker from './serviceWorker'; +import { Provider } from 'react-redux'; +import { createStore, applyMiddleware } from 'redux'; +import thunkMiddleware from 'redux-thunk'; +import { rootReducer } from "./store/reducers"; -ReactDOM.render(, document.getElementById('root')); +const store = createStore(rootReducer, applyMiddleware(thunkMiddleware)); + +ReactDOM.render(, 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. diff --git a/client/src/scenes/DoorLockCharges/index.js b/client/src/scenes/DoorLockCharges/index.js index 52020ee..b8fc383 100644 --- a/client/src/scenes/DoorLockCharges/index.js +++ b/client/src/scenes/DoorLockCharges/index.js @@ -1,12 +1,16 @@ import React, { Component } from 'react'; +import { connect } from 'react-redux'; -import { Container, Form } from "semantic-ui-react"; +import { Container, Form, Loader } from "semantic-ui-react"; import MainMenu from '../../components/MainMenu'; +import { fetchDoorLockCharges } from "../../store/actions"; class DoorLockCharges extends Component { render () { + console.log(this.props); + const pending = false; return ( @@ -33,11 +37,24 @@ class DoorLockCharges extends Component { label="Select DLock file" type="file" /> - Generate Report + Generate Report + { + pending && + } ); } } -export default DoorLockCharges; +const mapStateToProps = state => ({ + incidents: state.doorLockCharges.incidents, + pending: state.doorLockCharges.pending, + error: state.doorLockCharges.error, +}); + +const mapDispatchToProps = (dispatch) => ({ + fetchDoorLockCharges: () => fetchDoorLockCharges(dispatch), +}); + +export default connect(mapStateToProps, mapDispatchToProps)(DoorLockCharges); diff --git a/client/src/store/actions/doorLockActions.js b/client/src/store/actions/doorLockActions.js new file mode 100644 index 0000000..4b09c0a --- /dev/null +++ b/client/src/store/actions/doorLockActions.js @@ -0,0 +1,17 @@ +import { + FETCH_DOOR_LOCK_CHARGES_PENDING, + FETCH_DOOR_LOCK_CHARGES_SUCCESS, + FETCH_DOOR_LOCK_CHARGES_FAILED +} from "../constants"; + +export const fetchDoorLockCharges = (dispatch) => { + dispatch({type: FETCH_DOOR_LOCK_CHARGES_PENDING}); + fetch('/api/doorLockCharges') + .then(response => response.json()) + .then(data => { + dispatch({type: FETCH_DOOR_LOCK_CHARGES_SUCCESS, payload: data}) + }) + .catch(err => { + dispatch({type: FETCH_DOOR_LOCK_CHARGES_FAILED, payload: err}) + }) +}; diff --git a/client/src/store/actions/index.js b/client/src/store/actions/index.js new file mode 100644 index 0000000..d21e20e --- /dev/null +++ b/client/src/store/actions/index.js @@ -0,0 +1 @@ +export * from './doorLockActions'; diff --git a/client/src/store/constants.js b/client/src/store/constants.js new file mode 100644 index 0000000..6dec00c --- /dev/null +++ b/client/src/store/constants.js @@ -0,0 +1,3 @@ +export const FETCH_DOOR_LOCK_CHARGES_PENDING = 'FETCH_DOOR_LOCK_CHARGES_PENDING'; +export const FETCH_DOOR_LOCK_CHARGES_SUCCESS = 'FETCH_DOOR_LOCK_CHARGES_SUCCESS'; +export const FETCH_DOOR_LOCK_CHARGES_FAILED = 'FETCH_DOOR_LOCK_CHARGES_FAILED'; diff --git a/client/src/store/reducers/doorLockReducers.js b/client/src/store/reducers/doorLockReducers.js new file mode 100644 index 0000000..ad22ac5 --- /dev/null +++ b/client/src/store/reducers/doorLockReducers.js @@ -0,0 +1,35 @@ +import { + FETCH_DOOR_LOCK_CHARGES_PENDING, + FETCH_DOOR_LOCK_CHARGES_SUCCESS, + FETCH_DOOR_LOCK_CHARGES_FAILED +} from "../constants"; + +const initialState = { + incidents: [], + pending: false, + error: '', +}; + +export const doorLockCharges = (state, action) => { + state = state || initialState; + action = action || {}; + + switch(action.type){ + case FETCH_DOOR_LOCK_CHARGES_PENDING: + return Object.assign({}, state, { + pending: true, + }); + case FETCH_DOOR_LOCK_CHARGES_SUCCESS: + return Object.assign({}, state, { + incidents: action.payload, + pending: false, + }); + case FETCH_DOOR_LOCK_CHARGES_FAILED: + return Object.assign({}, state, { + pending: false, + error: action.payload, + }); + default: + return state; + } +}; diff --git a/client/src/store/reducers/index.js b/client/src/store/reducers/index.js new file mode 100644 index 0000000..85381d2 --- /dev/null +++ b/client/src/store/reducers/index.js @@ -0,0 +1,8 @@ +import { combineReducers } from "redux"; + +import { doorLockCharges} from "./doorLockReducers"; + +export const rootReducer = combineReducers({ + doorLockCharges +}); + diff --git a/client/yarn.lock b/client/yarn.lock index 856d5a0..2f7cadb 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -761,7 +761,7 @@ dependencies: regenerator-runtime "^0.13.2" -"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.3.4", "@babel/runtime@^7.4.2": +"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.3.4", "@babel/runtime@^7.4.2", "@babel/runtime@^7.4.3": version "7.4.5" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.4.5.tgz#582bb531f5f9dc67d2fcb682979894f75e253f12" dependencies: @@ -3935,7 +3935,7 @@ hmac-drbg@^1.0.0: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.1" -hoist-non-react-statics@^3.1.0: +hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.0.tgz#b09178f0122184fb95acf525daaecb4d8f45958b" dependencies: @@ -6779,7 +6779,7 @@ prompts@^2.0.1: kleur "^3.0.2" sisteransi "^1.0.0" -prop-types@^15.6.1, prop-types@^15.6.2: +prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2: version "15.7.2" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" dependencies: @@ -6972,7 +6972,7 @@ react-error-overlay@^5.1.6: version "5.1.6" resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-5.1.6.tgz#0cd73407c5d141f9638ae1e0c63e7b2bf7e9929d" -react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4: +react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4, react-is@^16.8.6: version "16.8.6" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16" @@ -6987,6 +6987,17 @@ react-popper@^1.3.3: typed-styles "^0.0.7" warning "^4.0.2" +react-redux@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.0.3.tgz#983c5a6de81cb1e696bd1c090ba826545f9170f1" + dependencies: + "@babel/runtime" "^7.4.3" + hoist-non-react-statics "^3.3.0" + invariant "^2.2.4" + loose-envify "^1.4.0" + prop-types "^15.7.2" + react-is "^16.8.6" + react-router-dom@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-5.0.0.tgz#542a9b86af269a37f0b87218c4c25ea8dcf0c073" @@ -7152,6 +7163,17 @@ recursive-readdir@2.2.2: dependencies: minimatch "3.0.4" +redux-thunk@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622" + +redux@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.1.tgz#436cae6cc40fbe4727689d7c8fae44808f1bfef5" + dependencies: + loose-envify "^1.4.0" + symbol-observable "^1.2.0" + regenerate-unicode-properties@^8.0.2: version "8.1.0" resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.1.0.tgz#ef51e0f0ea4ad424b77bf7cb41f3e015c70a3f0e" @@ -8016,6 +8038,10 @@ svgo@^1.0.0, svgo@^1.2.1: unquote "~1.1.1" util.promisify "~1.0.0" +symbol-observable@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804" + symbol-tree@^3.2.2: version "3.2.2" resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6" From 90b6d7b7e5d3a80ea3c95d53c277f1b0070c1a70 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Tue, 28 May 2019 04:45:21 +0200 Subject: [PATCH 08/10] remove console logging --- client/src/scenes/DoorLockCharges/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/src/scenes/DoorLockCharges/index.js b/client/src/scenes/DoorLockCharges/index.js index b8fc383..35a06bf 100644 --- a/client/src/scenes/DoorLockCharges/index.js +++ b/client/src/scenes/DoorLockCharges/index.js @@ -9,8 +9,7 @@ import { fetchDoorLockCharges } from "../../store/actions"; class DoorLockCharges extends Component { render () { - console.log(this.props); - const pending = false; + const { pending } = this.props.pending; return ( From 19c08195b4f000a341cebfa40f7968cf824de698 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Tue, 28 May 2019 13:04:33 +0200 Subject: [PATCH 09/10] seperate upload and report screens --- client/src/constants/menuItems.js | 10 ++-- client/src/scenes/DoorLockCharges/index.js | 59 ------------------- client/src/scenes/Home/index.js | 41 ++++++------- client/src/scenes/UploadDLockData/index.js | 39 ++++++++++++ client/src/store/actions/doorLockActions.js | 16 ++--- client/src/store/constants.js | 6 +- client/src/store/reducers/doorLockReducers.js | 18 +++--- client/src/store/reducers/index.js | 4 +- controllers/doorLock.js | 9 +++ controllers/doorLockCharges.js | 22 ------- routes/index.js | 4 +- 11 files changed, 96 insertions(+), 132 deletions(-) delete mode 100644 client/src/scenes/DoorLockCharges/index.js create mode 100644 client/src/scenes/UploadDLockData/index.js create mode 100644 controllers/doorLock.js delete mode 100644 controllers/doorLockCharges.js diff --git a/client/src/constants/menuItems.js b/client/src/constants/menuItems.js index cc0c1be..6ea00f8 100644 --- a/client/src/constants/menuItems.js +++ b/client/src/constants/menuItems.js @@ -1,4 +1,4 @@ -import DoorLockCharges from "../scenes/DoorLockCharges"; +import UploadDLockData from "../scenes/UploadDLockData"; import Home from "../scenes/Home"; export const mainMenuItems = [ @@ -9,9 +9,9 @@ export const mainMenuItems = [ component: Home, }, { - id: 'doorLockCharges', - title: 'Door Lock Charges', - url: '/door-lock-charges', - component: DoorLockCharges, + id: 'uploadDLockData', + title: 'Upload DLock Data', + url: '/upload-dlock-data', + component: UploadDLockData, }, ]; diff --git a/client/src/scenes/DoorLockCharges/index.js b/client/src/scenes/DoorLockCharges/index.js deleted file mode 100644 index 35a06bf..0000000 --- a/client/src/scenes/DoorLockCharges/index.js +++ /dev/null @@ -1,59 +0,0 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; - -import { Container, Form, Loader } from "semantic-ui-react"; - -import MainMenu from '../../components/MainMenu'; -import { fetchDoorLockCharges } from "../../store/actions"; - -class DoorLockCharges extends Component { - - render () { - const { pending } = this.props.pending; - return ( - - -

Door Lock Charges

-
-
- - - - - - Generate Report - - { - pending && - } -
- ); - } -} - -const mapStateToProps = state => ({ - incidents: state.doorLockCharges.incidents, - pending: state.doorLockCharges.pending, - error: state.doorLockCharges.error, -}); - -const mapDispatchToProps = (dispatch) => ({ - fetchDoorLockCharges: () => fetchDoorLockCharges(dispatch), -}); - -export default connect(mapStateToProps, mapDispatchToProps)(DoorLockCharges); diff --git a/client/src/scenes/Home/index.js b/client/src/scenes/Home/index.js index f4012bf..9cd8925 100644 --- a/client/src/scenes/Home/index.js +++ b/client/src/scenes/Home/index.js @@ -1,37 +1,34 @@ import React, { Component } from 'react'; -import { Container } from 'semantic-ui-react'; +import { Container, Form } from "semantic-ui-react"; import MainMenu from '../../components/MainMenu'; class Home extends Component { - state = { - apiStatus: 'loading', - }; - - componentDidMount() { - fetch('/api') - .then(response => response.json()) - .then(result => { - if (result.status === 1) { - this.setState({apiStatus: 'working'}); - } else { - this.setState({apiStatus: 'NOT WORKING !'}); - } - }) - .catch(err => { - this.setState({apiStatus: `ERROR : ${err}`}); - }) - } render () { - const {apiStatus} = this.state; return ( -

CRM Integration

+

Report


-
Integration API Status : {apiStatus}
+
+ + + + + Generate Report +
); } diff --git a/client/src/scenes/UploadDLockData/index.js b/client/src/scenes/UploadDLockData/index.js new file mode 100644 index 0000000..b75da54 --- /dev/null +++ b/client/src/scenes/UploadDLockData/index.js @@ -0,0 +1,39 @@ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; + +import { Container, Form } from "semantic-ui-react"; + +import MainMenu from '../../components/MainMenu'; +import { uploadDoorLockData } from "../../store/actions"; + +class UploadDLockData extends Component { + + render () { + return ( + + +

DLock Data

+
+
+ + Upload + +
+ ); + } +} + +const mapStateToProps = (state) => ({ + +}); + +const mapDispatchToProps = (dispatch) => ({ + uploadDoorLockData: () => uploadDoorLockData(dispatch), +}); + +export default connect(mapStateToProps, mapDispatchToProps)(UploadDLockData); diff --git a/client/src/store/actions/doorLockActions.js b/client/src/store/actions/doorLockActions.js index 4b09c0a..9aa82ea 100644 --- a/client/src/store/actions/doorLockActions.js +++ b/client/src/store/actions/doorLockActions.js @@ -1,17 +1,17 @@ import { - FETCH_DOOR_LOCK_CHARGES_PENDING, - FETCH_DOOR_LOCK_CHARGES_SUCCESS, - FETCH_DOOR_LOCK_CHARGES_FAILED + UPLOAD_DOOR_LOCK_DATA_PENDING, + UPLOAD_DOOR_LOCK_DATA_SUCCESS, + UPLOAD_DOOR_LOCK_DATA_FAILED } from "../constants"; -export const fetchDoorLockCharges = (dispatch) => { - dispatch({type: FETCH_DOOR_LOCK_CHARGES_PENDING}); - fetch('/api/doorLockCharges') +export const uploadDoorLockData = (dispatch) => { + dispatch({type: UPLOAD_DOOR_LOCK_DATA_PENDING}); + fetch('/api/doorLockData') .then(response => response.json()) .then(data => { - dispatch({type: FETCH_DOOR_LOCK_CHARGES_SUCCESS, payload: data}) + dispatch({type: UPLOAD_DOOR_LOCK_DATA_SUCCESS, payload: data}) }) .catch(err => { - dispatch({type: FETCH_DOOR_LOCK_CHARGES_FAILED, payload: err}) + dispatch({type: UPLOAD_DOOR_LOCK_DATA_FAILED, payload: err}) }) }; diff --git a/client/src/store/constants.js b/client/src/store/constants.js index 6dec00c..5034375 100644 --- a/client/src/store/constants.js +++ b/client/src/store/constants.js @@ -1,3 +1,3 @@ -export const FETCH_DOOR_LOCK_CHARGES_PENDING = 'FETCH_DOOR_LOCK_CHARGES_PENDING'; -export const FETCH_DOOR_LOCK_CHARGES_SUCCESS = 'FETCH_DOOR_LOCK_CHARGES_SUCCESS'; -export const FETCH_DOOR_LOCK_CHARGES_FAILED = 'FETCH_DOOR_LOCK_CHARGES_FAILED'; +export const UPLOAD_DOOR_LOCK_DATA_PENDING = 'UPLOAD_DOOR_LOCK_DATA_PENDING'; +export const UPLOAD_DOOR_LOCK_DATA_SUCCESS = 'UPLOAD_DOOR_LOCK_DATA_SUCCESS'; +export const UPLOAD_DOOR_LOCK_DATA_FAILED = 'UPLOAD_DOOR_LOCK_DATA_FAILED'; diff --git a/client/src/store/reducers/doorLockReducers.js b/client/src/store/reducers/doorLockReducers.js index ad22ac5..759e4fd 100644 --- a/client/src/store/reducers/doorLockReducers.js +++ b/client/src/store/reducers/doorLockReducers.js @@ -1,30 +1,30 @@ import { - FETCH_DOOR_LOCK_CHARGES_PENDING, - FETCH_DOOR_LOCK_CHARGES_SUCCESS, - FETCH_DOOR_LOCK_CHARGES_FAILED + UPLOAD_DOOR_LOCK_DATA_PENDING, + UPLOAD_DOOR_LOCK_DATA_SUCCESS, + UPLOAD_DOOR_LOCK_DATA_FAILED } from "../constants"; const initialState = { - incidents: [], pending: false, + result: {}, error: '', }; -export const doorLockCharges = (state, action) => { +export const doorLockData = (state, action) => { state = state || initialState; action = action || {}; switch(action.type){ - case FETCH_DOOR_LOCK_CHARGES_PENDING: + case UPLOAD_DOOR_LOCK_DATA_PENDING: return Object.assign({}, state, { pending: true, }); - case FETCH_DOOR_LOCK_CHARGES_SUCCESS: + case UPLOAD_DOOR_LOCK_DATA_SUCCESS: return Object.assign({}, state, { - incidents: action.payload, pending: false, + result: action.payload, }); - case FETCH_DOOR_LOCK_CHARGES_FAILED: + case UPLOAD_DOOR_LOCK_DATA_FAILED: return Object.assign({}, state, { pending: false, error: action.payload, diff --git a/client/src/store/reducers/index.js b/client/src/store/reducers/index.js index 85381d2..274b7bd 100644 --- a/client/src/store/reducers/index.js +++ b/client/src/store/reducers/index.js @@ -1,8 +1,8 @@ import { combineReducers } from "redux"; -import { doorLockCharges} from "./doorLockReducers"; +import { doorLockData} from "./doorLockReducers"; export const rootReducer = combineReducers({ - doorLockCharges + doorLockData }); diff --git a/controllers/doorLock.js b/controllers/doorLock.js new file mode 100644 index 0000000..8376c64 --- /dev/null +++ b/controllers/doorLock.js @@ -0,0 +1,9 @@ +'use strict'; + +const uploadDoorLockData = (req, res) => { + res.json({status: 'ok'}); +}; + +module.exports = { + uploadDoorLockData, +}; diff --git a/controllers/doorLockCharges.js b/controllers/doorLockCharges.js deleted file mode 100644 index 54948f8..0000000 --- a/controllers/doorLockCharges.js +++ /dev/null @@ -1,22 +0,0 @@ -'use strict'; - -const calculateDoorLockCharges = (req, res) => { - res.json([ - { - member: 'Dummy Member A', - date: new Date(), - room: 'Blue room', - fee: 10, - }, - { - member: 'Dummy Member B', - date: new Date(), - room: 'White room', - fee: 20, - } - ]); -}; - -module.exports = { - calculateDoorLockCharges, -}; diff --git a/routes/index.js b/routes/index.js index 83ec460..f5a4487 100644 --- a/routes/index.js +++ b/routes/index.js @@ -1,12 +1,12 @@ 'use strict'; const { apiStatusCheck } = require('../controllers/apiStatusCheck'); -const { calculateDoorLockCharges } = require('../controllers/doorLockCharges'); +const { uploadDoorLockData } = require('../controllers/doorLock'); const express = require('express'); const router = express.Router(); router.get('/', apiStatusCheck); -router.get('/doorLockCharges', calculateDoorLockCharges); +router.get('/doorLockData', uploadDoorLockData); module.exports = router; From e5c5a6384a6ccd288400dc7be2dee743f8fb9982 Mon Sep 17 00:00:00 2001 From: Bilal Catic Date: Tue, 28 May 2019 13:36:07 +0200 Subject: [PATCH 10/10] change labels --- client/src/constants/menuItems.js | 4 ++-- client/src/scenes/Home/index.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/constants/menuItems.js b/client/src/constants/menuItems.js index 6ea00f8..cd4f3d2 100644 --- a/client/src/constants/menuItems.js +++ b/client/src/constants/menuItems.js @@ -10,8 +10,8 @@ export const mainMenuItems = [ }, { id: 'uploadDLockData', - title: 'Upload DLock Data', - url: '/upload-dlock-data', + title: 'DLock', + url: '/dlock', component: UploadDLockData, }, ]; diff --git a/client/src/scenes/Home/index.js b/client/src/scenes/Home/index.js index 9cd8925..6f77d40 100644 --- a/client/src/scenes/Home/index.js +++ b/client/src/scenes/Home/index.js @@ -27,7 +27,7 @@ class Home extends Component { type="date" /> - Generate Report + Show report
);