Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs UI #559

Merged
merged 14 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#.env.development
REACT_APP_API_ENDPOINT = "http://localhost:5000"
2 changes: 2 additions & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#.env.production
REACT_APP_API_ENDPOINT = "https://codeuino-donut-development.herokuapp.com"
5 changes: 5 additions & 0 deletions .env.staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# NODE_ENV will always be set to "production" for a build
# more details at https://create-react-app.dev/docs/deployment/#customizing-environment-variables-for-arbitrary-build-environments

REACT_APP_CUSTOM_NODE_ENV = "staging"
REACT_APP_API_ENDPOINT = "https://codeuino-donut-development.herokuapp.com"
981 changes: 974 additions & 7 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,32 @@
"@testing-library/react": "^9.4.0",
"@testing-library/user-event": "^7.2.1",
"@tinymce/tinymce-react": "^3.6.0",
"antd": "^4.4.2",
"axios": "^0.19.1",
"boostrap": "^2.0.0",
"chart.js": "^2.9.3",
"dotenv": "^8.2.0",
"env-cmd": "^10.1.0",
"html-react-parser": "^0.13.0",
"http-proxy-middleware": "^1.0.5",
"jwt-decode": "^2.2.0",
"markdown-it": "^11.0.0",
"moment": "^2.27.0",
"node-sass": "^4.13.0",
"react": "^16.12.0",
"react-bootstrap": "^1.0.0-beta.16",
"react-chartjs-2": "^2.9.0",
"react-content-loader": "^5.0.4",
"react-cookies": "^0.1.1",
"react-datepicker": "^3.1.3",
"react-dom": "^16.12.0",
"react-dropzone": "^11.0.1",
"react-ga": "^3.1.2",
"react-icons": "^3.10.0",
"react-images": "^1.1.7",
"react-lottie": "^1.2.3",
"react-markdown-editor-lite": "^1.1.4",
"react-moment": "^0.9.7",
"react-redux": "^7.2.0",
"react-responsive": "^8.0.3",
"react-router-dom": "^5.1.2",
Expand All @@ -36,12 +46,14 @@
"react-toastify": "^6.0.5",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"socket.io-client": "^2.3.0"
"showdown": "^1.9.1",
"socket.io-client": "^2.3.0",
"styled-components": "^5.1.1"
},
"proxy": "http://localhost:5000",
"scripts": {
"start": "react-scripts start",
"build": "CI=false && react-scripts build && ./build.sh",
"build:staging": "env-cmd -f .env.staging react-scripts build && ./build.sh",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Expand Down
8 changes: 6 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link href="https://fonts.googleapis.com/css?family=Playfair+Display&display=swap" rel="stylesheet">
<link
href="https://fonts.googleapis.com/css?family=Playfair+Display&display=swap"
rel="stylesheet"
/>
<!--
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" />
<script src="https://apis.google.com/js/client:platform.js"></script>
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Expand All @@ -29,7 +33,7 @@
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<script src='https://meet.jit.si/external_api.js'></script>
<script src="https://meet.jit.si/external_api.js"></script>
<div id="root"></div>
<!--
This HTML file is a template.
Expand Down
75 changes: 37 additions & 38 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
import React, { Component } from "react";
import React, { Component, useEffect } from "react";
import Router from "./router";
import "./App.css";

import { Provider } from "react-redux";
import store from "./store";
import jwt_decode from "jwt-decode";
import { setAuthToken } from "./utils/setAuthToken";
import { setCurrentUser, logoutUser } from "./actions/authAction";
import "./css/main.scss";
import ReactGA from "react-ga";

class App extends Component {
componentDidMount() {
// check if user already loggedIn
const token = JSON.parse(localStorage.getItem("jwtToken"));
console.log("CHECKING TOKEN ", token);
if (token) {
const decodedData = jwt_decode(token);
// set auth token in axios header
setAuthToken(token);
// set user in the state
setCurrentUser(decodedData);
// check if token is valid or expired
const currentTime = Date.now() / 1000; // in ms
const expiryTime = decodedData.iat + 10800000; // 24 hrs
if (expiryTime <= currentTime) {
store.dispatch(logoutUser());
// now redirect to home page
window.location.href = "/";
}
}
}
render() {
return (
<Provider store={store}>
<React.Fragment>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossOrigin="anonymous"
/>
<Router />
</React.Fragment>
</Provider>
);
// check if user already loggedIn
const token = localStorage.getItem("jwtToken");
console.log("CHECKING TOKEN ", token);
if (token) {
const decodedData = jwt_decode(token);
// set auth token in axios header
setAuthToken(token);
// set user in the state
setCurrentUser(decodedData);
// check if token is valid or expired
const currentTime = Date.now() / 1000; // in ms
const expiryTime = decodedData.iat + 10800000; // 24 hrs
if (expiryTime <= currentTime) {
store.dispatch(logoutUser());
window.location.href = "/";
}
}
document.title = "Donut";

function App() {
useEffect(() => {
ReactGA.initialize("UA-173245995-1");
});
return (
<Provider store={store}>
<React.Fragment>
<link
rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossOrigin="anonymous"
/>
<Router />
</React.Fragment>
</Provider>
);
}

document.title = "Donut";
export default App;
7 changes: 4 additions & 3 deletions src/actions/adminAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { SET_ADMIN, GET_ADMIN } from './types'
import { setAuthToken } from '../utils/setAuthToken'
import jwt_decode from 'jwt-decode';
import { setCurrentUser } from './authAction'
import { BASE_URL } from './baseApi'


export const createAdmin = (adminInfo) => async (dispatch) => {
try {
const res = await axios.post('/user/', adminInfo)
const res = await axios.post(`${BASE_URL}/user/`, adminInfo)
setRequestStatus(false)
if (res.status === 201) {
setRequestStatus(true)
Expand All @@ -25,14 +26,14 @@ export const createAdmin = (adminInfo) => async (dispatch) => {

export const loginAdmin = (adminInfo, history) => async (dispatch) => {
try {
const res = await axios.post('/auth/login/', adminInfo)
const res = await axios.post(`${BASE_URL}/auth/login/`, adminInfo)
dispatch(setRequestStatus(false));
if (res.status === 200) {

const token = res.data.token;
dispatch(setRequestStatus(true));

localStorage.setItem("jwtToken", JSON.stringify(token));
localStorage.setItem("jwtToken", (token));
setAuthToken(token);

// update state with user
Expand Down
139 changes: 139 additions & 0 deletions src/actions/analyticsAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import axios from "axios";
import { errorHandler } from "../utils/errorHandler";
import { setRequestStatus } from "../utils/setRequestStatus";
import {
GET_BROWSER_ANALYTICS,
GET_COUNTRY_ANALYTICS,
GET_DEVICE_ANALYTICS,
GET_MOSTVIEWED_ANALYTICS,
GET_PROPOSALVIEW_ANALYTICS
} from "../actions/types";
import moment from "moment";

// GET BROWSER ANALYTICS
export const getBrowserAnalytics = (
startingDate,
endingDate,
proposalId
) => async (dispatch) => {
try {
let data = {
startDate: moment(startingDate).format("YYYY-MM-DD"),
endDate: moment(endingDate).format("YYYY-MM-DD"),
proposalId: proposalId,
};
const res = await axios.post("/analytics/browser", data);
dispatch(setRequestStatus(false));
if (res.status === 200) {
dispatch(setRequestStatus(true));
dispatch({
type: GET_BROWSER_ANALYTICS,
payload: res.data.analytics || res.data.msg,
});
}
} catch (error) {
dispatch(errorHandler(error));
}
};

// GET MOSTVIEWED ANALYTICS
export const getMostViewedAnalytics = (startingDate, endingDate) => async (
dispatch
) => {
try {
let data = {
startDate: moment(startingDate).format("YYYY-MM-DD"),
endDate: moment(endingDate).format("YYYY-MM-DD"),
};
const res = await axios.post("/analytics/mostviewed", data);
dispatch(setRequestStatus(false));
if (res.status === 200) {
dispatch(setRequestStatus(true));
dispatch({
type: GET_MOSTVIEWED_ANALYTICS,
payload: res.data.analytics || res.data.msg,
});
}
} catch (error) {
dispatch(errorHandler(error));
}
};

// GET PROPOSAL VIEW ANALYTICS
export const getProposalviewAnalytics = (
startingDate,
endingDate,
proposalId
) => async (dispatch) => {
try {
let data = {
startDate: moment(startingDate).format("YYYY-MM-DD"),
endDate: moment(endingDate).format("YYYY-MM-DD"),
proposalId: proposalId,
};
const res = await axios.post("/analytics/views", data);
dispatch(setRequestStatus(false));
if (res.status === 200) {
dispatch(setRequestStatus(true));
console.log(res.data.analytics)
dispatch({
type: GET_PROPOSALVIEW_ANALYTICS,
payload: res.data.analytics || res.data.msg,
});
}
} catch (error) {
dispatch(errorHandler(error));
}
};

// GET COUNTRIES ANALYTICS
export const getCountryAnalytics = (
startingDate,
endingDate,
proposalId
) => async (dispatch) => {
try {
let data = {
startDate: moment(startingDate).format("YYYY-MM-DD"),
endDate: moment(endingDate).format("YYYY-MM-DD"),
proposalId: proposalId,
};
const res = await axios.post("/analytics/countries", data);
dispatch(setRequestStatus(false));
if (res.status === 200) {
dispatch(setRequestStatus(true));
dispatch({
type: GET_COUNTRY_ANALYTICS,
payload: res.data.analytics || res.data.msg,
});
}
} catch (error) {
dispatch(errorHandler(error));
}
};

// GET DEVICE ANALYTICS
export const getDeviceAnalytics = (
startingDate,
endingDate,
proposalId
) => async (dispatch) => {
try {
let data = {
startDate: moment(startingDate).format("YYYY-MM-DD"),
endDate: moment(endingDate).format("YYYY-MM-DD"),
proposalId: proposalId,
};
const res = await axios.post("/analytics/device", data);
dispatch(setRequestStatus(false));
if (res.status === 200) {
dispatch(setRequestStatus(true));
dispatch({
type: GET_DEVICE_ANALYTICS,
payload: res.data.analytics || res.data.msg,
});
}
} catch (error) {
dispatch(errorHandler(error));
}
};
Loading