Skip to content

Commit ebec902

Browse files
authored
Merge pull request #487 from Rupeshiya/notification_and_integration
Notification and integration of backend with frontend
2 parents fb20260 + dbd2b4c commit ebec902

Some content is hidden

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

41 files changed

+5250
-4575
lines changed

package-lock.json

Lines changed: 3927 additions & 4339 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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
"react-redux": "^7.2.0",
2525
"react-responsive": "^8.0.3",
2626
"react-router-dom": "^5.1.2",
27-
"react-scripts": "3.3.0",
27+
"react-scripts": "^3.4.0",
28+
"react-toastify": "^6.0.5",
2829
"redux": "^4.0.5",
29-
"redux-thunk": "^2.3.0"
30+
"redux-thunk": "^2.3.0",
31+
"socket.io-client": "^2.3.0"
3032
},
3133
"proxy": "http://localhost:5000",
3234
"scripts": {

src/actions/adminAction.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import axios from 'axios'
2+
import { errorHandler } from '../utils/errorHandler'
3+
import { setRequestStatus } from '../utils/setRequestStatus'
4+
import { SET_ADMIN } from './types'
5+
6+
export const createAdmin = (adminInfo) => async (dispatch) => {
7+
try {
8+
const res = await axios.post('/user/', adminInfo)
9+
setRequestStatus(false)
10+
if (res.status === 201) {
11+
setRequestStatus(true)
12+
}
13+
} catch (error) {
14+
dispatch(errorHandler(error))
15+
}
16+
}
17+
18+
export const loginAdmin = (adminInfo) => async (dispatch) => {
19+
try {
20+
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+
}
30+
} catch (error) {
31+
dispatch(errorHandler(error))
32+
}
33+
}

src/actions/authAction.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const registerUser = (userInfo, history) => async (dispatch) => {
1414

1515
if(res.status === 201) {
1616
dispatch(setRequestStatus(true));
17-
history.push('/dashboard');
17+
history.push('/');
1818
}
1919

2020
} catch(error) {
@@ -40,6 +40,7 @@ export const loginUser = (userInfo, history) => async (dispatch) => {
4040

4141
// update state with user
4242
const decodedData = await jwt_decode(token);
43+
localStorage.setItem('userId', decodedData._id)
4344
dispatch(setCurrentUser(decodedData));
4445
history.push("/dashboard");
4546

@@ -85,15 +86,26 @@ export const changePassword = (passObj) => async (dispatch) => {
8586

8687

8788
// to logout user
88-
export const logoutUser = () => {
89-
// remove token from the localStorage
90-
localStorage.removeItem('jwtToken');
91-
// delete authorization from the header
92-
setAuthToken(false);
93-
// set user to {}
94-
setCurrentUser({});
95-
// move to home
96-
window.location.href = "/";
89+
export const logoutUser = () => async (dispatch) => {
90+
try {
91+
console.log('Logging out!!')
92+
// clear token from backend
93+
const res = await axios.post('/user/logout')
94+
if (res.status === 200) {
95+
// remove token from the localStorage
96+
localStorage.removeItem('jwtToken');
97+
// remove userID
98+
localStorage.removeItem('userId')
99+
// delete authorization from the header
100+
setAuthToken(false);
101+
// set user to {}
102+
setCurrentUser({});
103+
// move to home
104+
window.location.href = "/";
105+
}
106+
} catch (error) {
107+
dispatch(errorHandler(error))
108+
}
97109
}
98110

99111
export const setCurrentUser = (decodedData) => {

src/actions/dashboardAction.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import axios from 'axios'
2+
import { setRequestStatus } from '../utils/setRequestStatus'
3+
import { errorHandler } from '../utils/errorHandler'
4+
import { GET_ALL_UPCOMING_EVENTS } from './types'
5+
6+
// GET UPCOMING EVENTS
7+
export const upcomingEvents = () => async (dispatch) => {
8+
try {
9+
const res = await axios.get('/event/upcoming')
10+
dispatch(setRequestStatus(false))
11+
if (res.status === 200) {
12+
dispatch(setRequestStatus(true))
13+
console.log('upcoming events called!', res.data)
14+
dispatch({
15+
type: GET_ALL_UPCOMING_EVENTS,
16+
payload: res.data.events || res.data.msg
17+
})
18+
}
19+
} catch (error) {
20+
dispatch(errorHandler(error))
21+
}
22+
}
23+
24+
// CREATE POST
25+
export const createPost = (postInfo) => async (dispatch) => {
26+
try {
27+
const res = await axios.post('/post/', postInfo)
28+
dispatch(setRequestStatus(false))
29+
if (res.status === 201) {
30+
dispatch(setRequestStatus(true))
31+
console.log('post created ', res.data)
32+
}
33+
} catch (error) {
34+
dispatch(errorHandler(error))
35+
}
36+
}
37+
38+
// CREATE EVENT
39+
export const createEvent = (eventInfo) => async (dispatch) => {
40+
try {
41+
const res = await axios.post('/event/', eventInfo)
42+
dispatch(setRequestStatus(false))
43+
if (res.status === 201) {
44+
dispatch(setRequestStatus(true))
45+
console.log('event created ', res.data)
46+
}
47+
} catch (error) {
48+
dispatch(errorHandler(error))
49+
}
50+
}
51+
52+
// CREATE PROJECT
53+
export const createProject = (projectInfo) => async (dispatch) => {
54+
try {
55+
console.log('projectInfo ', projectInfo)
56+
const res = await axios.post('/project/', projectInfo)
57+
dispatch(setRequestStatus(false))
58+
if (res.status === 201) {
59+
dispatch(setRequestStatus(true))
60+
console.log('project created ', res.data)
61+
}
62+
} catch (error) {
63+
dispatch(errorHandler(error))
64+
}
65+
}

src/actions/insightAction.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { GET_ALL_MEMBERS, GET_ORG_OVERVIEW, GET_PERSONAL_OVERVIEW, SEARCH_MEMBER, BLOCK_USER, UNBLOCK_USER } from './types'
2+
import axios from 'axios'
3+
import { errorHandler } from '../utils/errorHandler'
4+
import { setRequestStatus } from '../utils/setRequestStatus'
5+
6+
// GET ORGANIZATIONAL OVERVIEW
7+
export const getOrgOverview = () => async (dispatch) => {
8+
try {
9+
const res = await axios.get('/org/overview/all')
10+
dispatch(setRequestStatus(false))
11+
if (res.status === 200) {
12+
dispatch(setRequestStatus(true))
13+
console.log('getOrgOverview ', res.data)
14+
dispatch({
15+
type: GET_ORG_OVERVIEW,
16+
payload: res.data.orgOverView
17+
})
18+
}
19+
} catch (error) {
20+
dispatch(errorHandler(error))
21+
}
22+
}
23+
24+
// GET PERSONAL OVERVIEW
25+
export const getPersonalOverview = () => async (dispatch) => {
26+
try {
27+
const res = await axios.get('/user/overview')
28+
dispatch(setRequestStatus(false))
29+
if (res.status === 200) {
30+
dispatch(setRequestStatus(true))
31+
console.log('getPersonalOverview ', res.data)
32+
dispatch({
33+
type: GET_PERSONAL_OVERVIEW,
34+
payload: res.data.personalOverview
35+
})
36+
}
37+
} catch (error) {
38+
dispatch(errorHandler(error))
39+
}
40+
}
41+
42+
// GET ALL MEMBERS
43+
export const getMembers = () => async (dispatch) => {
44+
try {
45+
const res = await axios.get('/org/members/all')
46+
dispatch(setRequestStatus(false))
47+
if (res.status === 200) {
48+
dispatch(setRequestStatus(true))
49+
console.log('getMembers ', res.data)
50+
dispatch({
51+
type: GET_ALL_MEMBERS,
52+
payload: res.data.members
53+
})
54+
}
55+
} catch (error) {
56+
dispatch(errorHandler(error))
57+
}
58+
}
59+
60+
// SEARCH MEMBER BY FIRST NAME, LAST NAME, FULL NAME
61+
export const getMember = (query) => async (dispatch) => {
62+
try {
63+
console.log('Looking for member ', query)
64+
const res = await axios.get(`/org/members/all?search=${query}`)
65+
dispatch(setRequestStatus(false))
66+
if (res.status === 200) {
67+
dispatch(setRequestStatus(true))
68+
console.log('getMember by name ', res.data)
69+
dispatch({
70+
type: SEARCH_MEMBER,
71+
payload: res.data.member
72+
})
73+
}
74+
} catch (error) {
75+
dispatch(errorHandler(error))
76+
}
77+
}
78+
79+
// BLOCK A USER (BY ADMIN)
80+
export const blockUser = (userId) => async (dispatch) => {
81+
try {
82+
const res = await axios.patch(`/user/block/${userId}`)
83+
dispatch(setRequestStatus(false))
84+
if (res.status === 200) {
85+
dispatch(setRequestStatus(true))
86+
console.log('user blocked!', res.data)
87+
dispatch({
88+
type: BLOCK_USER,
89+
payload: true
90+
})
91+
}
92+
} catch (error) {
93+
dispatch(errorHandler(error))
94+
}
95+
}
96+
97+
// UNBLOCK A USER (BY ADMIN)
98+
export const unBlockUser = (userId) => async (dispatch) => {
99+
try {
100+
const res = await axios.patch(`/user/unblock/${userId}`)
101+
dispatch(setRequestStatus(false))
102+
if (res.status === 200) {
103+
dispatch(setRequestStatus(true))
104+
console.log('user unblocked!', res.data)
105+
dispatch({
106+
type: UNBLOCK_USER,
107+
payload: false // isBlocked = false
108+
})
109+
}
110+
} catch (error) {
111+
dispatch(errorHandler(error))
112+
}
113+
}

src/actions/notificationAction.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { GET_PLATFORM_NOTIFICATIONS, GET_USER_NOTIFICATIONS } from './types'
2+
import axios from 'axios'
3+
import { errorHandler } from '../utils/errorHandler';
4+
import { setRequestStatus } from '../utils/setRequestStatus';
5+
6+
// GET NOTIFICATIONS FOR WHOLE PLATFORM AS WELL AS FOR A USER
7+
export const getAllNotifications = () => async (dispatch) => {
8+
try {
9+
const res = await axios.get('/notification/org/all')
10+
dispatch(setRequestStatus(false))
11+
if (res.status === 200) {
12+
dispatch(setRequestStatus(true))
13+
console.log('Whole platform notification ', res.data.notifications)
14+
15+
dispatch({
16+
type: GET_PLATFORM_NOTIFICATIONS,
17+
payload: res.data.notifications
18+
})
19+
}
20+
} catch (error) {
21+
dispatch(errorHandler(error))
22+
}
23+
}
24+
25+
// GET NOTIFICATIONS FOR A USER
26+
export const getUserNotification = () => async (dispatch) => {
27+
try {
28+
const res = await axios.get('/notification/user/all')
29+
dispatch(setRequestStatus(false))
30+
if (res.status === 200) {
31+
dispatch(setRequestStatus(true))
32+
console.log('User notification ', res.data.notifications)
33+
dispatch({
34+
type: GET_USER_NOTIFICATIONS,
35+
payload: res.data.notifications
36+
})
37+
}
38+
} catch (error) {
39+
dispatch(errorHandler(error))
40+
}
41+
}

src/actions/orgAction.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import axios from 'axios'
2+
import { setRequestStatus } from '../utils/setRequestStatus'
3+
import { errorHandler } from '../utils/errorHandler'
4+
5+
// CREATE COMMUNITY
6+
export const registerCommunity = (orgInfo) => async (dispatch) => {
7+
try {
8+
const res = await axios.post('/org/', orgInfo)
9+
dispatch(setRequestStatus(false))
10+
if (res.status === 201) {
11+
dispatch(setRequestStatus(true))
12+
}
13+
} catch (error) {
14+
dispatch(errorHandler(error))
15+
}
16+
}

src/actions/types.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,17 @@ export const SET_CURRENT_USER = "SET_CURRENT_USER";
33
export const RESPONSE_MSG = "RESPONSE_MSG";
44
export const GET_ERRORS = "GET_ERRORS";
55
export const SET_ERROR = "SET_ERROR";
6-
export const SET_STATUS = "SET_STATUS";
6+
export const SET_STATUS = "SET_STATUS";
7+
export const GET_PLATFORM_NOTIFICATIONS = "GET_PLATFORM_NOTIFICATIONS";
8+
export const GET_USER_NOTIFICATIONS = "GET_USER_NOTIFICATIONS";
9+
export const GET_ALL_NOTIFICATIONS = "GET_ALL_NOTIFICATIONS";
10+
export const SET_ADMIN = "SET_ADMIN";
11+
export const GET_ALL_UPCOMING_EVENTS = "GET_ALL_UPCOMING_EVENTS";
12+
export const GET_ALL_MEMBERS = "GET_ALL_MEMBERS";
13+
export const GET_PERSONAL_OVERVIEW = "GET_PERSONAL_OVERVIEW";
14+
export const GET_ORG_OVERVIEW = "GET_ORG_OVERVIEW";
15+
export const SEARCH_MEMBER = "SEARCH_MEMBER";
16+
export const BLOCK_USER = "BLOCK_USER";
17+
export const UNBLOCK_USER = "UNBLOCK_USER";
18+
export const REMOVE_USER = "REMOVE_USER";
19+
export const GET_USER_PROFILE = "GET_USER_PROFILE";

src/actions/usersAction.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { GET_USER_PROFILE } from './types'
2+
import { errorHandler } from '../utils/errorHandler'
3+
import axios from 'axios'
4+
import { setRequestStatus } from '../utils/setRequestStatus'
5+
6+
export const getProfile = () => async (dispatch)=> {
7+
try {
8+
const res = await axios.get('/user/me')
9+
dispatch(setRequestStatus(false))
10+
if (res.status === 200) {
11+
setRequestStatus(true)
12+
console.log('user profile ', res.data)
13+
dispatch({
14+
type: GET_USER_PROFILE,
15+
payload: res.data.user
16+
})
17+
}
18+
} catch(error) {
19+
dispatch(errorHandler(error))
20+
}
21+
}

0 commit comments

Comments
 (0)