Skip to content

Commit f7eb4e2

Browse files
fixing conflicts
2 parents ca92134 + d0dec27 commit f7eb4e2

Some content is hidden

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

61 files changed

+7187
-5295
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
"react-redux": "^7.2.0",
3030
"react-responsive": "^8.0.3",
3131
"react-router-dom": "^5.1.2",
32-
"react-scripts": "3.3.0",
33-
"react-spinners": "^0.8.3",
32+
"react-scripts": "^3.4.0",
3433
"react-toastify": "^6.0.5",
34+
"react-spinners": "^0.8.3",
3535
"redux": "^4.0.5",
3636
"redux-thunk": "^2.3.0",
37-
"remarkable": "^2.0.1"
37+
"socket.io-client": "^2.3.0"
3838
},
3939
"proxy": "http://localhost:5000",
4040
"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/eventAction.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +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';
45

56
// DELETE EVENT REQUEST
67
export const deleteEvent = (eventId) => async (dispatch) => {
@@ -41,3 +42,21 @@ export const createEvent = (eventInfo, history) => async (dispatch) => {
4142
dispatch(errorHandler(error))
4243
}
4344
}
45+
46+
// GET ALL EVENTS
47+
export const getAllEvents = (pagination = 10, page = 1) => async (dispatch) => {
48+
try {
49+
const res = await axios.get(`/event/all?pagination=${pagination}&page=${page}`)
50+
dispatch(setRequestStatus(false))
51+
if(res.status === 200) {
52+
dispatch(setRequestStatus(true))
53+
console.log('all events ', res.data.events)
54+
dispatch({
55+
type: GET_ALL_EVENTS,
56+
payload: res.data.events
57+
})
58+
}
59+
} catch(error) {
60+
dispatch(errorHandler(error))
61+
}
62+
}

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+
}

0 commit comments

Comments
 (0)