Skip to content

Commit b7e3d69

Browse files
authored
Merge pull request #490 from Rupeshiya/features_integration
integrated events, projects, pinned post, dashboard comments etc
2 parents d0dec27 + 473dc3e commit b7e3d69

File tree

81 files changed

+1860
-694
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1860
-694
lines changed

src/actions/adminAction.js

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,52 @@
11
import axios from 'axios'
22
import { errorHandler } from '../utils/errorHandler'
33
import { setRequestStatus } from '../utils/setRequestStatus'
4-
import { SET_ADMIN } from './types'
4+
import { SET_ADMIN, GET_ADMIN } from './types'
5+
import { setAuthToken } from '../utils/setAuthToken'
6+
import jwt_decode from 'jwt-decode';
7+
import { setCurrentUser } from './authAction'
8+
59

610
export const createAdmin = (adminInfo) => async (dispatch) => {
711
try {
812
const res = await axios.post('/user/', adminInfo)
913
setRequestStatus(false)
1014
if (res.status === 201) {
1115
setRequestStatus(true)
16+
dispatch({
17+
type: GET_ADMIN,
18+
payload: res.data.user
19+
})
1220
}
1321
} catch (error) {
1422
dispatch(errorHandler(error))
1523
}
1624
}
1725

18-
export const loginAdmin = (adminInfo) => async (dispatch) => {
26+
export const loginAdmin = (adminInfo, history) => async (dispatch) => {
1927
try {
2028
const res = await axios.post('/auth/login/', adminInfo)
21-
dispatch(setRequestStatus(false))
22-
if (res.status === 200) {
23-
dispatch(setRequestStatus(true))
24-
localStorage.setItem('admin', true)
25-
dispatch({
26-
type: SET_ADMIN,
27-
payload: true
28-
})
29-
}
29+
dispatch(setRequestStatus(false));
30+
if (res.status === 200) {
31+
32+
const token = res.data.token;
33+
dispatch(setRequestStatus(true));
34+
35+
localStorage.setItem("jwtToken", JSON.stringify(token));
36+
setAuthToken(token);
37+
38+
// update state with user
39+
const decodedData = await jwt_decode(token);
40+
localStorage.setItem('userId', decodedData._id)
41+
dispatch(setCurrentUser(decodedData));
42+
43+
dispatch({
44+
type: SET_ADMIN,
45+
payload: true
46+
})
47+
48+
history.push("/dashboard");
49+
}
3050
} catch (error) {
3151
dispatch(errorHandler(error))
3252
}

src/actions/authAction.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SET_CURRENT_USER } from './types';
1+
import { SET_CURRENT_USER, GET_USER_PROFILE, PASSWORD_SUCCESSFULLY_CHANGED, PASSWORD_CHANGE_REQUEST_SUCCESS } from './types';
22
import axios from 'axios';
33
import { setAuthToken } from '../utils/setAuthToken';
44
import jwt_decode from 'jwt-decode';
@@ -14,6 +14,10 @@ export const registerUser = (userInfo, history) => async (dispatch) => {
1414

1515
if(res.status === 201) {
1616
dispatch(setRequestStatus(true));
17+
dispatch({
18+
type: GET_USER_PROFILE,
19+
payload: res.data.user
20+
})
1721
history.push('/');
1822
}
1923

@@ -53,13 +57,17 @@ export const loginUser = (userInfo, history) => async (dispatch) => {
5357
// forgot password
5458
export const forgotPassword = (email) => async (dispatch) => {
5559
try {
56-
const res = await axios.post('/user/password_reset', email);
60+
const res = await axios.patch('/user/password_reset/request/', email);
5761
dispatch(setRequestStatus(false));
5862

5963
if(res.status === 200){
6064
dispatch(setRequestStatus(true));
6165
console.log("Forgot password request sent!!");
6266
forgotPasswordToken = res.data.token;
67+
dispatch({
68+
type: PASSWORD_CHANGE_REQUEST_SUCCESS,
69+
payload: res.data.token
70+
})
6371
}
6472

6573
} catch (error) {
@@ -70,13 +78,17 @@ export const forgotPassword = (email) => async (dispatch) => {
7078
// update password
7179
export const changePassword = (passObj) => async (dispatch) => {
7280
try {
73-
const res = await axios.post(`/user/password_reset/${forgotPasswordToken}`, passObj);
81+
const res = await axios.patch(`/user/password_reset/${forgotPasswordToken}`, passObj);
7482
dispatch(setRequestStatus(false));
7583

7684
if(res.status === 200){
7785
dispatch(setRequestStatus(true));
7886
console.log("Password updated!", res.data);
7987
// show password updated notification from here
88+
dispatch({
89+
type: PASSWORD_SUCCESSFULLY_CHANGED,
90+
payload: res.data.updated
91+
})
8092
}
8193

8294
} catch(error) {

src/actions/commentAction.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { GET_COMMENTS_OF_A_POST } from './types'
2+
import { errorHandler } from '../utils/errorHandler'
3+
import axios from 'axios'
4+
import { setRequestStatus } from '../utils/setRequestStatus'
5+
6+
// CREATE COMMENT ON A PARTICULAR POST
7+
export const createComment = (postId, comment) => async (dispatch) => {
8+
try {
9+
const res = await axios.post(`/comment/${postId}`, comment)
10+
dispatch(setRequestStatus(false));
11+
if(res.status === 201) {
12+
dispatch(setRequestStatus(true))
13+
console.log('created comment ', res.data.comment)
14+
dispatch(getAllCommentsOfPost());
15+
}
16+
} catch(error) {
17+
dispatch(errorHandler(error))
18+
}
19+
}
20+
21+
// GET ALL COMMENTS OF A POST
22+
export const getAllCommentsOfPost = (postId) => async (dispatch) => {
23+
try {
24+
const res = await axios.get(`/comment/${postId}`)
25+
dispatch(setRequestStatus(false))
26+
if(res.status === 200) {
27+
dispatch(setRequestStatus(true));
28+
console.log('fetching comments of ', postId, res.data.comments);
29+
dispatch({
30+
type: GET_COMMENTS_OF_A_POST,
31+
payload: res.data.comments
32+
})
33+
}
34+
} catch(error) {
35+
dispatch(errorHandler(error))
36+
}
37+
}
38+
39+
// UPDATE COMMENT OF A POST
40+
export const updateComment = (commentId, updatedComment) => async (dispatch) => {
41+
try {
42+
const res = await axios.patch(`/comment/${commentId}`, updatedComment)
43+
dispatch(setRequestStatus(false))
44+
if(res.status === 200) {
45+
dispatch(setRequestStatus(true))
46+
console.log('comment updated ', res.data.comment)
47+
dispatch(getAllCommentsOfPost())
48+
}
49+
} catch(error) {
50+
errorHandler(error)
51+
}
52+
}
53+
54+
// DELETE COMMENT
55+
export const deleteComment = (commentId) => async (dispatch) => {
56+
try {
57+
const res = await axios.delete(`/comment/${commentId}`)
58+
dispatch(setRequestStatus(false))
59+
if(res.status === 200) {
60+
dispatch(setRequestStatus(true));
61+
console.log('comment deleted ', res.data)
62+
dispatch(getAllCommentsOfPost())
63+
}
64+
} catch(error) {
65+
dispatch(errorHandler(error))
66+
}
67+
}

src/actions/dashboardAction.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import axios from 'axios'
22
import { setRequestStatus } from '../utils/setRequestStatus'
33
import { errorHandler } from '../utils/errorHandler'
44
import { GET_ALL_UPCOMING_EVENTS } from './types'
5+
import { getAllEvents } from './eventAction'
6+
import { getAllPosts } from './postAction'
7+
import { getAllProjects } from './projectAction'
58

69
// GET UPCOMING EVENTS
710
export const upcomingEvents = () => async (dispatch) => {
@@ -29,6 +32,7 @@ export const createPost = (postInfo) => async (dispatch) => {
2932
if (res.status === 201) {
3033
dispatch(setRequestStatus(true))
3134
console.log('post created ', res.data)
35+
dispatch(getAllPosts())
3236
}
3337
} catch (error) {
3438
dispatch(errorHandler(error))
@@ -43,6 +47,7 @@ export const createEvent = (eventInfo) => async (dispatch) => {
4347
if (res.status === 201) {
4448
dispatch(setRequestStatus(true))
4549
console.log('event created ', res.data)
50+
dispatch(getAllEvents())
4651
}
4752
} catch (error) {
4853
dispatch(errorHandler(error))
@@ -58,6 +63,7 @@ export const createProject = (projectInfo) => async (dispatch) => {
5863
if (res.status === 201) {
5964
dispatch(setRequestStatus(true))
6065
console.log('project created ', res.data)
66+
dispatch(getAllProjects())
6167
}
6268
} catch (error) {
6369
dispatch(errorHandler(error))

src/actions/eventAction.js

Lines changed: 22 additions & 1 deletion
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_EVENTS } from './types';
4+
import { GET_ALL_EVENTS, GET_EVENT_BY_ID } from './types';
55

66
// DELETE EVENT REQUEST
77
export const deleteEvent = (eventId) => async (dispatch) => {
@@ -10,6 +10,7 @@ export const deleteEvent = (eventId) => async (dispatch) => {
1010
dispatch(setRequestStatus(false));
1111
if(res.status === 200){
1212
dispatch(setRequestStatus(true));
13+
dispatch(getAllEvents())
1314
}
1415
} catch(error) {
1516
dispatch(errorHandler(error))
@@ -23,6 +24,7 @@ export const updateEvent = (eventId, updatedInfo) => async (dispatch) => {
2324
dispatch(setRequestStatus(false));
2425
if(res.status === 200){
2526
dispatch(setRequestStatus(true));
27+
dispatch(getAllEvents())
2628
}
2729
} catch(error) {
2830
dispatch(errorHandler(error))
@@ -60,3 +62,22 @@ export const getAllEvents = (pagination = 10, page = 1) => async (dispatch) => {
6062
dispatch(errorHandler(error))
6163
}
6264
}
65+
66+
// GET EVENT BY ID
67+
export const getEventById = (eventId) => async (dispatch) => {
68+
try {
69+
console.log('fetching event ', eventId)
70+
const res = await axios.get(`/event/${eventId}`)
71+
dispatch(setRequestStatus(false))
72+
if(res.status === 200){
73+
dispatch(setRequestStatus(true))
74+
console.log('fetching event by id ', res.data.event)
75+
dispatch({
76+
type: GET_EVENT_BY_ID,
77+
payload: res.data.event
78+
})
79+
}
80+
} catch(error) {
81+
dispatch(errorHandler(error))
82+
}
83+
}

src/actions/orgAction.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const registerCommunity = (orgInfo) => async (dispatch) => {
1111
if (res.status === 201) {
1212
dispatch(setRequestStatus(true))
1313
localStorage.setItem('orgId', JSON.stringify(res.data.org._id))
14+
dispatch(getOrgProfile())
1415
}
1516
} catch (error) {
1617
dispatch(errorHandler(error))
@@ -61,15 +62,17 @@ export const getOrgProfile = () => async (dispatch) => {
6162
export const updateOrgProfile = (updatedInfo) => async (dispatch) => {
6263
try {
6364
let orgId = localStorage.getItem('orgId')
65+
console.log('updatedInfo ', updatedInfo);
6466
const res = await axios.patch(`/org/${orgId}`, updatedInfo)
6567
dispatch(setRequestStatus(false));
6668
if(res.status === 200) {
6769
dispatch(setRequestStatus(true))
6870
console.log('org profile updated!', res.data)
69-
dispatch({
70-
type: UPDATE_ORG_PROFILE,
71-
payload: res.data.organization
72-
})
71+
dispatch(getOrgProfile());
72+
// dispatch({
73+
// type: UPDATE_ORG_PROFILE,
74+
// payload: res.data.organization
75+
// })
7376
}
7477
} catch(error) {
7578
dispatch(errorHandler(error))

src/actions/postAction.js

Lines changed: 18 additions & 1 deletion
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 } from './types';
4+
import { GET_ALL_POSTS, GET_ALL_PINNED_POSTS } from './types';
55

66
// GET ALL POSTS
77
export const getAllPosts = (pagination = 10, page = 1) => async (dispatch) => {
@@ -21,3 +21,20 @@ export const getAllPosts = (pagination = 10, page = 1) => async (dispatch) => {
2121
}
2222
}
2323

24+
// GET ALL PINNED POSTS
25+
export const getAllPinnedPosts = (pagination = 10, page = 1) => async (dispatch) => {
26+
try {
27+
const res = await axios.get(`/post/all/pinned?pagination=${pagination}&page=${page}`)
28+
dispatch(setRequestStatus(false))
29+
if(res.status === 200){
30+
dispatch(setRequestStatus(true))
31+
console.log('fetching all pinned posts ', res.data.pinnedPost)
32+
dispatch({
33+
type: GET_ALL_PINNED_POSTS,
34+
payload: res.data.pinnedPost
35+
})
36+
}
37+
} catch(error) {
38+
dispatch(errorHandler(error))
39+
}
40+
}

src/actions/projectAction.js

Lines changed: 54 additions & 2 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_PROJECTS } from './types';
4+
import { GET_ALL_PROJECTS, GET_SINGLE_PROJECT } from './types';
55

66
// CREATE PROJECT
77
export const createProject = (projectInfo) => async (dispatch) => {
@@ -34,4 +34,56 @@ export const getAllProjects = (pagination = 10, page = 1) => async (dispatch) =>
3434
} catch(error) {
3535
dispatch(errorHandler(error))
3636
}
37-
}
37+
}
38+
39+
// GET PROJECT BY ID
40+
export const getProjectById = (projectId) => async (dispatch) => {
41+
try {
42+
const res = await axios.get(`/project/${projectId}`)
43+
dispatch(setRequestStatus(false))
44+
if(res.status === 200) {
45+
dispatch(setRequestStatus(true));
46+
dispatch({
47+
type: GET_SINGLE_PROJECT,
48+
payload: res.data.project
49+
})
50+
}
51+
} catch(error) {
52+
dispatch(errorHandler(error))
53+
}
54+
}
55+
56+
// UPDATE PROJECT
57+
export const updateProject = (projectId, updatedInfo) => async (dispatch) => {
58+
try {
59+
const res = await axios.patch(`/project/${projectId}`, updatedInfo)
60+
dispatch(setRequestStatus(false))
61+
if(res.status === 200) {
62+
dispatch(setRequestStatus(true));
63+
console.log('updated project info ', res.data)
64+
dispatch({
65+
type: GET_SINGLE_PROJECT,
66+
payload: res.data.project
67+
})
68+
}
69+
} catch(error) {
70+
dispatch(errorHandler(error))
71+
}
72+
}
73+
74+
// DELETE PROJECT BY ID
75+
export const deleteProjectById = (projectId, history) => async (dispatch) => {
76+
try {
77+
const res = await axios.delete(`/project/${projectId}`)
78+
dispatch(setRequestStatus(false))
79+
if(res.status === 200) {
80+
dispatch(setRequestStatus(true))
81+
console.log('Project deleted', res.data.msg);
82+
// window.location.href = '/projects'
83+
// dispatch(getAllProjects())
84+
history.push('/projects');
85+
}
86+
} catch(error) {
87+
dispatch(errorHandler(error))
88+
}
89+
}

0 commit comments

Comments
 (0)