Skip to content

Commit bc3493b

Browse files
authored
implemented user activity and fix inconsistencies (#527)
1 parent 7467b41 commit bc3493b

40 files changed

+2174
-489
lines changed

package-lock.json

Lines changed: 661 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
"@testing-library/react": "^9.4.0",
1212
"@testing-library/user-event": "^7.2.1",
1313
"@tinymce/tinymce-react": "^3.6.0",
14+
"antd": "^4.4.2",
1415
"axios": "^0.19.1",
1516
"boostrap": "^2.0.0",
1617
"html-react-parser": "^0.13.0",
18+
"http-proxy-middleware": "^1.0.5",
1719
"jwt-decode": "^2.2.0",
1820
"markdown-it": "^11.0.0",
21+
"moment": "^2.27.0",
1922
"node-sass": "^4.13.0",
2023
"react": "^16.12.0",
2124
"react-bootstrap": "^1.0.0-beta.16",
@@ -27,6 +30,7 @@
2730
"react-images": "^1.1.7",
2831
"react-lottie": "^1.2.3",
2932
"react-markdown-editor-lite": "^1.1.4",
33+
"react-moment": "^0.9.7",
3034
"react-redux": "^7.2.0",
3135
"react-responsive": "^8.0.3",
3236
"react-router-dom": "^5.1.2",

src/App.js

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
11
import React, { Component } from "react";
22
import Router from "./router";
33
import "./App.css";
4-
54
import { Provider } from "react-redux";
65
import store from "./store";
76
import jwt_decode from "jwt-decode";
87
import { setAuthToken } from "./utils/setAuthToken";
98
import { setCurrentUser, logoutUser } from "./actions/authAction";
109
import "./css/main.scss";
1110

12-
class App extends Component {
13-
componentDidMount() {
14-
// check if user already loggedIn
15-
const token = JSON.parse(localStorage.getItem("jwtToken"));
16-
console.log("CHECKING TOKEN ", token);
17-
if (token) {
18-
const decodedData = jwt_decode(token);
19-
// set auth token in axios header
20-
setAuthToken(token);
21-
// set user in the state
22-
setCurrentUser(decodedData);
23-
// check if token is valid or expired
24-
const currentTime = Date.now() / 1000; // in ms
25-
const expiryTime = decodedData.iat + 10800000; // 24 hrs
26-
if (expiryTime <= currentTime) {
27-
store.dispatch(logoutUser());
28-
// now redirect to home page
29-
window.location.href = "/";
30-
}
31-
}
11+
// check if user already loggedIn
12+
const token = localStorage.getItem("jwtToken")
13+
console.log("CHECKING TOKEN ", token);
14+
if (token) {
15+
const decodedData = jwt_decode(token);
16+
// set auth token in axios header
17+
setAuthToken(token);
18+
// set user in the state
19+
setCurrentUser(decodedData);
20+
// check if token is valid or expired
21+
const currentTime = Date.now() / 1000; // in ms
22+
const expiryTime = decodedData.iat + 10800000; // 24 hrs
23+
if (expiryTime <= currentTime) {
24+
store.dispatch(logoutUser());
25+
window.location.href = "/"
3226
}
33-
render() {
27+
}
28+
29+
function App() {
3430
return (
3531
<Provider store={store}>
3632
<React.Fragment>
@@ -44,8 +40,7 @@ class App extends Component {
4440
</React.Fragment>
4541
</Provider>
4642
);
47-
}
4843
}
49-
document.title = "Donut";
5044

45+
document.title = "Donut"
5146
export default App;

src/actions/adminAction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const loginAdmin = (adminInfo, history) => async (dispatch) => {
3232
const token = res.data.token;
3333
dispatch(setRequestStatus(true));
3434

35-
localStorage.setItem("jwtToken", JSON.stringify(token));
35+
localStorage.setItem("jwtToken", (token));
3636
setAuthToken(token);
3737

3838
// update state with user

src/actions/authAction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const loginUser = (userInfo, history) => async (dispatch) => {
3939
const token = res.data.token;
4040
dispatch(setRequestStatus(true));
4141

42-
localStorage.setItem("jwtToken", JSON.stringify(token));
42+
localStorage.setItem("jwtToken", (token));
4343
setAuthToken(token);
4444

4545
// update state with user

src/actions/commentAction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const createComment = (postId, comment) => async (dispatch) => {
1111
if(res.status === 201) {
1212
dispatch(setRequestStatus(true))
1313
console.log('created comment ', res.data.comment)
14-
dispatch(getAllCommentsOfPost());
14+
dispatch(getAllCommentsOfPost(postId));
1515
}
1616
} catch(error) {
1717
dispatch(errorHandler(error))

src/actions/insightAction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ export const getPersonalOverview = () => async (dispatch) => {
4040
}
4141

4242
// GET ALL MEMBERS
43-
export const getMembers = () => async (dispatch) => {
43+
export const getMembers = (pagination = 10, page = 1) => async (dispatch) => {
4444
try {
45-
const res = await axios.get('/org/members/all')
45+
const res = await axios.get(`/org/members/all?pagination=${pagination}&page=${page}`)
4646
dispatch(setRequestStatus(false))
4747
if (res.status === 200) {
4848
dispatch(setRequestStatus(true))

src/actions/postAction.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios from 'axios';
22
import { errorHandler } from '../utils/errorHandler';
33
import { setRequestStatus } from '../utils/setRequestStatus';
4-
import { GET_ALL_POSTS, GET_ALL_PINNED_POSTS } from './types';
4+
import { GET_ALL_POSTS, GET_ALL_PINNED_POSTS, GET_SINGLE_POST } from './types';
55

66
// GET ALL POSTS
77
export const getAllPosts = (pagination = 10, page = 1) => async (dispatch) => {
@@ -43,13 +43,52 @@ export const getAllPinnedPosts = (pagination = 10, page = 1) => async (dispatch)
4343
export const upVotePost = (postId) => async (dispatch) => {
4444
try {
4545
const res = await axios.patch(`/post/upvote/${postId}`)
46-
dispatch(setRequestStatus(false));
4746
if(res.status === 200) {
48-
dispatch(setRequestStatus(true));
4947
console.log('successfully upvoted post ', res.data)
5048
dispatch(getAllPosts());
5149
}
5250
} catch (error) {
5351
dispatch(errorHandler(error))
5452
}
5553
}
54+
55+
// GET POST BY ID
56+
export const getPostById = (postId) => async (dispatch) => {
57+
try {
58+
console.log('postId from action ', postId)
59+
const res = await axios.get(`/post/${postId}`);
60+
if (res.status === 200) {
61+
dispatch({
62+
type: GET_SINGLE_POST,
63+
payload: res.data.post
64+
})
65+
}
66+
} catch (error) {
67+
dispatch(errorHandler(error))
68+
}
69+
}
70+
71+
// UPDATE POST
72+
export const updatePost = (postId, updatedInfo) => async (dispatch) => {
73+
try {
74+
console.log('updatedPostInfo ', updatedInfo)
75+
const res = await axios.patch(`/post/${postId}`, updatedInfo)
76+
if (res.status === 200) {
77+
dispatch(getPostById(postId))
78+
}
79+
} catch (error) {
80+
dispatch(errorHandler(error))
81+
}
82+
}
83+
84+
// DELETE POST
85+
export const deletePost = (postId) => async (dispatch) => {
86+
try {
87+
const res = await axios.delete(`/post/${postId}`)
88+
if(res.status === 200) {
89+
dispatch(getAllPosts())
90+
}
91+
} catch (error) {
92+
dispatch(errorHandler(error))
93+
}
94+
}

src/actions/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ export const PASSWORD_SUCCESSFULLY_CHANGED = "PASSWORD_SUCCESSFULLY_CHANGED";
4444
export const GET_INVITE_LINK = "GET_INVITE_LINK";
4545
export const PROCESS_INVITE_LINK = "PROCESS_INVITE_LINK";
4646
export const TRIGGER_MAINTENANCE = "TRIGGER_MAINTENANCE";
47+
export const GET_SINGLE_POST = "GET_SINGLE_POST";

src/auth/login/login.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,44 @@ class Login extends Component {
5757
? "Or Sign In with"
5858
: "Or SignUp with"}
5959
</p>
60-
<div className="login__options">
61-
<div className="">
60+
<Row>
61+
<Col className = "button-column">
6262
<a
6363
href="http://localhost:5000/auth/google"
6464
style={{ padding: "1vh" }}
6565
>
66-
<img src={GoogleLogin} alt="Google" className="google__login"/>
66+
<Button
67+
className="selectorbtn"
68+
type="submit"
69+
variant="primary"
70+
color="primary"
71+
size="sm"
72+
>
73+
<span className="selectorbtn-content">
74+
<img src={GoogleLogin} alt="Google" className="google__login"/>Google
75+
</span>
76+
</Button>
6777
</a>
68-
</div>
69-
<div className="" >
78+
</Col>
79+
<Col className="button-column" >
7080
<a
71-
href="http://localhost:5000/auth/github"
81+
href="http://localhost:5000/auth/google"
7282
style={{ padding: "1vh" }}
7383
>
74-
<FaGithub color="#24292e" className="github__login"/>
84+
<Button
85+
className="selectorbtn"
86+
type="submit"
87+
variant="primary"
88+
color="primary"
89+
size="sm"
90+
>
91+
<span className="selectorbtn-content">
92+
<FaGithub color="#24292e" className="github__login"/>Github
93+
</span>
94+
</Button>
7595
</a>
76-
</div>
77-
</div>
96+
</Col>
97+
</Row>
7898
<p className="login-text-selector">
7999
{this.state.activeForm === "login"
80100
? "Don't have an account? "

src/auth/login/login.scss

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,15 @@
106106
background-color: #1a73e8;
107107
width: 104px;
108108
height: 38px;
109+
.google__login {
110+
height: 20px;
111+
width: 20px;
112+
padding-right: 5px;
113+
}
114+
.github__login {
115+
height: 20px;
116+
width: 20px;
117+
padding-right: 5px;
118+
}
109119
}
110120
}
111-
112-
.login__options {
113-
display: flex;
114-
justify-content: space-around;
115-
.google__login {
116-
height: 30px;
117-
}
118-
.github__login {
119-
height: 30px;
120-
width: 30px;
121-
}
122-
}

src/common/AdminRoute.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,28 @@ import PropTypes from 'prop-types';
33
import { Route, Redirect } from 'react-router-dom';
44
import { connect } from 'react-redux';
55

6-
function AdminRoute(props) {
7-
// const [mount, setMount] = useState(false);
8-
const [returnedRoute, setReturnedRoute] = useState("")
9-
10-
useEffect(() => {
11-
switch(props.role) {
12-
case "admin": {
13-
return setReturnedRoute(
14-
props.auth.isAuthenticated && (
15-
props.auth.isAdmin ||
16-
props.user.userProfile.isAdmin ||
17-
props.admin.isAdmin ) ? (
18-
<Route {...props} />
19-
) : (
20-
<Redirect to="/dashboard" />
21-
)
22-
);
23-
}
24-
default: {
25-
return setReturnedRoute(<Route {...props} />);
6+
function AdminRoute({ component: Component, auth, admin, user, ...rest }) {
7+
return (
8+
<Route
9+
{...rest}
10+
render={(props) =>
11+
auth.isAuthenticated === true && (
12+
auth.isAdmin === true ||
13+
admin.isAdmin === true ||
14+
localStorage.getItem('admin') === "true"
15+
) ? (
16+
<Component {...props} />
17+
) : (
18+
<Redirect to="/dashboard" />
19+
)
2620
}
27-
}
28-
}, [props.role, props])
29-
return <React.Fragment>{returnedRoute}</React.Fragment>;
21+
/>
22+
);
3023
}
3124

3225
AdminRoute.propTypes = {
33-
auth: PropTypes.object.isRequired
26+
auth: PropTypes.object.isRequired,
27+
org: PropTypes.object
3428
}
3529

3630
const mapStateToProps = (state) => {

src/css/components/_modals.scss

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/* border: 1px solid #CCCCCC; */
1212
box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.5);
1313
}
14+
1415
.modal__header {
1516
.modal__title {
1617
.modal__main-title {
@@ -42,6 +43,22 @@
4243
padding: 0.3em;
4344
margin-left: 1em;
4445
}
46+
.edit__post__option {
47+
float: right;
48+
margin-left: 12vw;
49+
font-size: 15px;
50+
cursor: pointer;
51+
border: 0px;
52+
text-decoration: underline;
53+
}
54+
.delete__post__option {
55+
float: right;
56+
margin-left: 1vw;
57+
font-size: 15px;
58+
cursor: pointer;
59+
border: 0px;
60+
text-decoration: underline;
61+
}
4562
}
4663
.modal__search {
4764
width: 50%;
@@ -115,6 +132,10 @@
115132
display: block;
116133
color: #6c757d;
117134
}
135+
.form-control:disabled,
136+
.form-control[readonly] {
137+
background-color: #ffffff;
138+
}
118139
}
119140
}
120141
.modal__secondary-title {
@@ -391,5 +412,24 @@
391412
color: #1a73e8;
392413
}
393414
}
415+
.modal__delete {
416+
border: 1px solid #eb5757;
417+
background: $color-modal-button-inactive;
418+
box-sizing: border-box;
419+
// border-radius: 34px;
420+
margin-right: 20px;
421+
margin-bottom: 10px;
422+
width: 80px;
423+
height: 38.5px;
424+
.modal__buttontext {
425+
font-family: $font-family-Inter;
426+
font-style: normal;
427+
font-weight: $font-weight-normal;
428+
font-size: 14px;
429+
line-height: 22px;
430+
/* identical to box height */
431+
color: #eb5757;
432+
}
433+
}
394434
}
395435
}

0 commit comments

Comments
 (0)