Skip to content

Commit d0dec27

Browse files
Rupeshiyavaibhavdaren
authored andcommitted
integrated profile page, popups, dashboard
1 parent f3d98cf commit d0dec27

31 files changed

+1784
-728
lines changed

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/orgAction.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import axios from 'axios'
22
import { setRequestStatus } from '../utils/setRequestStatus'
33
import { errorHandler } from '../utils/errorHandler'
4+
import { GET_ORG_PROFILE, UPDATE_ORG_PROFILE, DEACTIVATE_ORG, GET_ALL_MEMBERS } from './types'
45

56
// CREATE COMMUNITY
67
export const registerCommunity = (orgInfo) => async (dispatch) => {
@@ -25,8 +26,95 @@ export const removeAdmin = (userId) => async (dispatch) => {
2526
if (res.status === 200) {
2627
dispatch(setRequestStatus(true))
2728
console.log('admin removed ', userId)
29+
const response = await axios.get('/org/members/all')
30+
if (response.status === 200) {
31+
dispatch({
32+
type: GET_ALL_MEMBERS,
33+
payload: response.data.members
34+
});
35+
}
2836
}
2937
} catch (error) {
3038
dispatch(errorHandler(error))
3139
}
3240
}
41+
42+
// GET ORG INFO
43+
export const getOrgProfile = () => async (dispatch) => {
44+
try {
45+
let orgId = localStorage.getItem('orgId')
46+
const res = await axios.get(`/org/${orgId}`)
47+
dispatch(setRequestStatus(false))
48+
if(res.status === 200) {
49+
dispatch(setRequestStatus(true))
50+
dispatch({
51+
type: GET_ORG_PROFILE,
52+
payload: res.data.organization
53+
})
54+
}
55+
} catch(error) {
56+
dispatch(errorHandler(error))
57+
}
58+
}
59+
60+
// UPDATE ORG PROFILE
61+
export const updateOrgProfile = (updatedInfo) => async (dispatch) => {
62+
try {
63+
let orgId = localStorage.getItem('orgId')
64+
const res = await axios.patch(`/org/${orgId}`, updatedInfo)
65+
dispatch(setRequestStatus(false));
66+
if(res.status === 200) {
67+
dispatch(setRequestStatus(true))
68+
console.log('org profile updated!', res.data)
69+
dispatch({
70+
type: UPDATE_ORG_PROFILE,
71+
payload: res.data.organization
72+
})
73+
}
74+
} catch(error) {
75+
dispatch(errorHandler(error))
76+
}
77+
}
78+
79+
// UPDATE ORG SETTINGS
80+
export const updateSettings = (updatedInfo) => async (dispatch) => {
81+
try {
82+
let orgId = localStorage.getItem('orgId')
83+
const res = await axios.patch(`/org/${orgId}/settings/update`, updatedInfo)
84+
dispatch(setRequestStatus(false))
85+
if(res.status === 200) {
86+
dispatch(setRequestStatus(true))
87+
console.log('Updated org settings ', res.data)
88+
dispatch({
89+
type: UPDATE_ORG_PROFILE,
90+
payload: res.data.organization
91+
})
92+
}
93+
} catch(error) {
94+
dispatch(errorHandler(error))
95+
}
96+
}
97+
98+
// DEACTIVATE/ARCHIVE ORG
99+
export const deactivateOrg = () => async (dispatch) => {
100+
try {
101+
let orgId = localStorage.getItem('orgId')
102+
const res = await axios.patch(`/org/archive/${orgId}`);
103+
dispatch(setRequestStatus(false))
104+
if(res.status === 200) {
105+
dispatch(setRequestStatus(true))
106+
console.log('org deactivated ', res.data)
107+
dispatch({
108+
type: DEACTIVATE_ORG,
109+
payload: res.data.organization.isArchived
110+
})
111+
// set deactivation to the localStorage for future ref
112+
localStorage.setItem(
113+
"isDeactivated",
114+
JSON.stringify(res.data.organization.isArchived)
115+
);
116+
}
117+
} catch(error) {
118+
dispatch(errorHandler(error))
119+
}
120+
}

src/actions/postAction.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import axios from 'axios';
2+
import { errorHandler } from '../utils/errorHandler';
3+
import { setRequestStatus } from '../utils/setRequestStatus';
4+
import { GET_ALL_POSTS } from './types';
5+
6+
// GET ALL POSTS
7+
export const getAllPosts = (pagination = 10, page = 1) => async (dispatch) => {
8+
try {
9+
const res = await axios.get(`/post/all_posts?pagination=${pagination}&page=${page}`)
10+
dispatch(setRequestStatus(false))
11+
if(res.status === 200) {
12+
dispatch(setRequestStatus(true))
13+
console.log('all posts ', res.data.posts)
14+
dispatch({
15+
type: GET_ALL_POSTS,
16+
payload: res.data.posts
17+
})
18+
}
19+
} catch(error) {
20+
dispatch(errorHandler(error))
21+
}
22+
}
23+

src/actions/projectAction.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import axios from 'axios';
2+
import { errorHandler } from '../utils/errorHandler';
3+
import { setRequestStatus } from '../utils/setRequestStatus';
4+
import { GET_ALL_PROJECTS } from './types';
5+
6+
// CREATE PROJECT
7+
export const createProject = (projectInfo) => async (dispatch) => {
8+
try {
9+
console.log('projectInfo ', projectInfo)
10+
const res = await axios.post('/project/', projectInfo)
11+
dispatch(setRequestStatus(false))
12+
if (res.status === 201) {
13+
dispatch(setRequestStatus(true))
14+
console.log('project created ', res.data)
15+
}
16+
} catch (error) {
17+
dispatch(errorHandler(error))
18+
}
19+
}
20+
21+
// GET ALL PROJECTS
22+
export const getAllProjects = (pagination = 10, page = 1) => async (dispatch) => {
23+
try {
24+
const res = await axios.get(`/project/?pagination=${pagination}&page=${page}`)
25+
dispatch(setRequestStatus(false))
26+
if(res.status === 200) {
27+
dispatch(setRequestStatus(true))
28+
console.log('all projects ', res.data.projects)
29+
dispatch({
30+
type: GET_ALL_PROJECTS,
31+
payload: res.data.projects
32+
})
33+
}
34+
} catch(error) {
35+
dispatch(errorHandler(error))
36+
}
37+
}

src/actions/types.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ export const BLOCK_USER = "BLOCK_USER";
1717
export const UNBLOCK_USER = "UNBLOCK_USER";
1818
export const REMOVE_USER = "REMOVE_USER";
1919
export const GET_USER_PROFILE = "GET_USER_PROFILE";
20+
export const GET_ORG_PROFILE = "GET_ORG_PROFILE";
21+
export const UPDATE_ORG_PROFILE = "UPDATE_ORG_PROFILE";
22+
export const DEACTIVATE_ORG = "DEACTIVATE_ORG";
23+
export const UPDATE_USER_PROFILE = "UPDATE_USER_PROFILE";
24+
export const GET_USER_EVENTS = "GET_USER_EVENTS";
25+
export const GET_USER_PROJECTS = "GET_USER_PROJECTS";
26+
export const GET_ALL_EVENTS = "GET_ALL_EVENTS";
27+
export const GET_ALL_PROJECTS = "GET_ALL_PROJECTS";
28+
export const GET_ALL_POSTS = "GET_ALL_POSTS";
29+
export const GET_USER_POSTS = "GET_USER_POSTS";

src/actions/usersAction.js

Lines changed: 94 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { GET_USER_PROFILE } from './types'
1+
import { GET_USER_PROFILE, GET_ALL_MEMBERS, UPDATE_USER_PROFILE, GET_USER_EVENTS, GET_USER_PROJECTS, GET_USER_POSTS } from './types'
22
import { errorHandler } from '../utils/errorHandler'
33
import axios from 'axios'
44
import { setRequestStatus } from '../utils/setRequestStatus'
55

6+
// GET USER PROFILE
67
export const getProfile = () => async (dispatch)=> {
78
try {
89
const res = await axios.get('/user/me')
@@ -20,6 +21,7 @@ export const getProfile = () => async (dispatch)=> {
2021
}
2122
}
2223

24+
// FOLLOW USER
2325
export const followUser = (userId) => async (dispatch) => {
2426
try {
2527
let followObj = {
@@ -31,16 +33,17 @@ export const followUser = (userId) => async (dispatch) => {
3133
if (res.status === 200) {
3234
dispatch(setRequestStatus(true))
3335
console.log('started following ', followObj)
34-
// dispatch({
35-
// type: GET_USER_PROFILE,
36-
// payload: res.data.user,
37-
// });
36+
dispatch({
37+
type: GET_USER_PROFILE,
38+
payload: res.data.user,
39+
});
3840
}
3941
} catch(error) {
4042
dispatch(errorHandler(error))
4143
}
4244
}
4345

46+
// UnFOLLOW USER
4447
export const unFollowUser = (userId) => async (dispatch) => {
4548
try {
4649
let unFollowObj = {
@@ -52,25 +55,106 @@ export const unFollowUser = (userId) => async (dispatch) => {
5255
if (res.status === 200) {
5356
dispatch(setRequestStatus(true))
5457
console.log('unfollowed ', unFollowObj)
55-
// dispatch({
56-
// type: GET_USER_PROFILE,
57-
// payload: res.data.user,
58-
// });
58+
dispatch({
59+
type: GET_USER_PROFILE,
60+
payload: res.data.user,
61+
});
5962
}
6063
} catch(error) {
6164
dispatch(errorHandler(error))
6265
}
6366
}
6467

68+
// REMOVE USER
6569
export const removeUser = (userId) => async (dispatch) => {
6670
try {
6771
const res = await axios.patch(`/user/remove/${userId}`)
6872
dispatch(setRequestStatus(false))
6973
if(res.status === 200) {
7074
dispatch(setRequestStatus(true))
7175
console.log('user removed ', userId)
76+
const response = await axios.get('/org/members/all')
77+
if (response.status === 200) {
78+
dispatch({
79+
type: GET_ALL_MEMBERS,
80+
payload: response.data.members
81+
});
82+
}
7283
}
7384
} catch (error) {
7485
dispatch(errorHandler(error))
7586
}
76-
}
87+
}
88+
89+
// UPDATE USER PROFILE
90+
export const updateProfile = (updatedInfo) => async (dispatch) => {
91+
try {
92+
console.log('updating ', updatedInfo)
93+
const res = await axios.patch('/user/me', updatedInfo)
94+
dispatch(setRequestStatus(false))
95+
if(res.status === 200) {
96+
dispatch(setRequestStatus(true))
97+
console.log('user profile updated ', res.data)
98+
dispatch({
99+
type: UPDATE_USER_PROFILE,
100+
payload: res.data.data
101+
})
102+
}
103+
} catch(error) {
104+
dispatch(errorHandler(error))
105+
}
106+
}
107+
108+
// GET EVENTS CREATED BY USER
109+
export const getEventsCreatedByUser = (pagination = 10, page = 1) => async (dispatch) => {
110+
try {
111+
const res = await axios.get(`event/me/all?pagination=${pagination}&page=${page}`);
112+
dispatch(setRequestStatus(false))
113+
if(res.status === 200) {
114+
dispatch(setRequestStatus(true))
115+
console.log('fetching all events created by user ', res.data.events)
116+
dispatch({
117+
type: GET_USER_EVENTS,
118+
payload: res.data.events
119+
})
120+
}
121+
} catch (error) {
122+
dispatch(errorHandler(error))
123+
}
124+
}
125+
126+
// GET ALL PROJECT CREATED BY A USER
127+
export const getProjectCreatedByUser = (pagination = 10, page = 1) => async (dispatch) => {
128+
try {
129+
const res = await axios.get(`/project/me/all?pagination=${pagination}&page=${page}`);
130+
dispatch(setRequestStatus(false))
131+
if(res.status === 200) {
132+
dispatch(setRequestStatus(true))
133+
console.log('fetching all projects created by user ', res.data.projects)
134+
dispatch({
135+
type: GET_USER_PROJECTS,
136+
payload: res.data.projects
137+
});
138+
}
139+
} catch (error) {
140+
dispatch(errorHandler(error))
141+
}
142+
}
143+
144+
// GET POSTS CREATED BY USER
145+
export const getPostsCreatedByUser = (pagination = 10, page = 1) => async (dispatch) => {
146+
try {
147+
const res = await axios.get(`/post/me/all?pagination=${pagination}&page=${page}`);
148+
dispatch(setRequestStatus(false))
149+
if(res.status === 200) {
150+
dispatch(setRequestStatus(true))
151+
console.log('fetching all posts created by user ', res.data.posts)
152+
dispatch({
153+
type: GET_USER_POSTS,
154+
payload: res.data.posts
155+
})
156+
}
157+
} catch (error) {
158+
dispatch(errorHandler(error))
159+
}
160+
}

src/reducers/eventReducer.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { GET_ALL_EVENTS } from '../actions/types'
2+
const initialState = {
3+
allEvents: []
4+
}
5+
6+
export default (state = initialState, action) => {
7+
switch(action.type) {
8+
case GET_ALL_EVENTS: {
9+
return {
10+
...state,
11+
allEvents: action.payload
12+
}
13+
}
14+
default:{
15+
return state
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)