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? "

0 commit comments

Comments
 (0)