Skip to content

Commit 03d3f4f

Browse files
integrating redux for state management and other requested changes
1 parent e38f279 commit 03d3f4f

File tree

24 files changed

+528
-1266
lines changed

24 files changed

+528
-1266
lines changed

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "pwa-chrome",
9+
"request": "launch",
10+
"name": "Launch Chrome against localhost",
11+
"url": "http://localhost:8080",
12+
"webRoot": "${workspaceFolder}"
13+
}
14+
]
15+
}

src/actions/notificationAction.js

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,63 @@
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';
1+
import {
2+
GET_PLATFORM_NOTIFICATIONS,
3+
GET_USER_NOTIFICATIONS,
4+
GET_PROPOSAL_NOTIFICATIONS,
5+
} from "./types";
6+
import axios from "axios";
7+
import { errorHandler } from "../utils/errorHandler";
8+
import { setRequestStatus } from "../utils/setRequestStatus";
59

610
// GET NOTIFICATIONS FOR WHOLE PLATFORM AS WELL AS FOR A USER
711
export const getAllNotifications = () => async (dispatch) => {
812
try {
9-
const res = await axios.get('/notification/org/all')
10-
dispatch(setRequestStatus(false))
13+
const res = await axios.get("/notification/org/all");
14+
dispatch(setRequestStatus(false));
1115
if (res.status === 200) {
12-
dispatch(setRequestStatus(true))
13-
console.log('Whole platform notification ', res.data.notifications)
16+
dispatch(setRequestStatus(true));
17+
console.log("Whole platform notification ", res.data.notifications);
1418

1519
dispatch({
1620
type: GET_PLATFORM_NOTIFICATIONS,
17-
payload: res.data.notifications
18-
})
21+
payload: res.data.notifications,
22+
});
1923
}
2024
} catch (error) {
21-
dispatch(errorHandler(error))
25+
dispatch(errorHandler(error));
2226
}
23-
}
27+
};
2428

2529
// GET NOTIFICATIONS FOR A USER
2630
export const getUserNotification = () => async (dispatch) => {
2731
try {
28-
const res = await axios.get('/notification/user/all')
29-
dispatch(setRequestStatus(false))
32+
const res = await axios.get("/notification/user/all");
33+
dispatch(setRequestStatus(false));
3034
if (res.status === 200) {
31-
dispatch(setRequestStatus(true))
32-
console.log('User notification ', res.data.notifications)
35+
dispatch(setRequestStatus(true));
36+
console.log("User notification ", res.data.notifications);
3337
dispatch({
3438
type: GET_USER_NOTIFICATIONS,
35-
payload: res.data.notifications
36-
})
39+
payload: res.data.notifications,
40+
});
3741
}
3842
} catch (error) {
39-
dispatch(errorHandler(error))
43+
dispatch(errorHandler(error));
4044
}
41-
}
45+
};
46+
47+
// GET PROPOSAL NOTIFICATIONS
48+
export const getProposalNotifications = () => async (dispatch) => {
49+
try {
50+
const res = await axios.get("/notification/proposal/all");
51+
dispatch(setRequestStatus(false));
52+
if (res.status === 200) {
53+
dispatch(setRequestStatus(true));
54+
console.log("Proposal notification ", res.data.notifications);
55+
dispatch({
56+
type: GET_PROPOSAL_NOTIFICATIONS,
57+
payload: res.data.notifications,
58+
});
59+
}
60+
} catch (error) {
61+
dispatch(errorHandler(error));
62+
}
63+
};

src/actions/proposalActions.js

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import axios from "axios";
22
import { errorHandler } from "../utils/errorHandler";
33
import { setRequestStatus } from "../utils/setRequestStatus";
4-
import { CREATE_PROPOSAL, GET_PROPOSAL } from "../actions/types";
4+
import {
5+
CREATE_PROPOSAL,
6+
GET_PROPOSAL,
7+
GET_USER_PROPOSAL_NOTIFICATIONS,
8+
GET_ALL_PROPOSALS,
9+
GET_USER_PROPOSALS,
10+
} from "../actions/types";
511

612
// CREATE PROPOSAL
713
export const createProposal = (proposalInfo) => async (dispatch) => {
814
try {
9-
console.log("proposalInfo", proposalInfo);
1015
const res = await axios.post("/proposal", proposalInfo);
1116
dispatch(setRequestStatus(false));
1217
if (res.status === 201) {
@@ -39,3 +44,116 @@ export const getProposal = (proposalId) => async (dispatch) => {
3944
dispatch(errorHandler(error));
4045
}
4146
};
47+
48+
// SAVE PROPOSAL DATA
49+
export const saveProposal = (proposalData) => async (dispatch) => {
50+
try {
51+
const res = await axios.patch(
52+
"/proposal/" + proposalData.proposalId,
53+
proposalData
54+
);
55+
dispatch(setRequestStatus(false));
56+
if (res.status === 200) {
57+
dispatch(setRequestStatus(true));
58+
}
59+
} catch (error) {
60+
dispatch(errorHandler(error));
61+
}
62+
};
63+
64+
// SUBMIT PROPOSAL
65+
export const submitProposal = (proposalData) => async (dispatch) => {
66+
console.log(proposalData);
67+
try {
68+
const res = await axios.patch(
69+
"/proposal/change/" + proposalData.proposalId,
70+
proposalData
71+
);
72+
dispatch(setRequestStatus(false));
73+
if (res.status === 200) {
74+
dispatch(setRequestStatus(true));
75+
}
76+
} catch (error) {
77+
dispatch(errorHandler(error));
78+
}
79+
};
80+
81+
// DELETE PROPOSAL
82+
export const deleteProposal = (proposalId) => async (dispatch) => {
83+
try {
84+
const res = await axios.delete("/proposal", {
85+
headers: {},
86+
data: { proposalId: proposalId },
87+
});
88+
dispatch(setRequestStatus(false));
89+
if (res.status === 200) {
90+
dispatch(setRequestStatus(true));
91+
}
92+
} catch (error) {
93+
dispatch(errorHandler(error));
94+
}
95+
};
96+
97+
// COMMENT ON PROPOSAL
98+
export const commentProposal = (commentData) => async (dispatch) => {
99+
try {
100+
const res = await axios.post("/proposal/comment", commentData);
101+
dispatch(setRequestStatus(false));
102+
if (res.status === 200) {
103+
dispatch(setRequestStatus(true));
104+
}
105+
} catch (error) {
106+
dispatch(errorHandler(error));
107+
}
108+
};
109+
110+
// GET USER RELATED PROPOSAL NOTIFICATIONS
111+
export const getUserProposalNotifications = (data) => async (dispatch) => {
112+
try {
113+
const res = await axios.post("/proposal/notifications", data);
114+
console.log(res);
115+
if (res.status === 200) {
116+
dispatch(setRequestStatus(true));
117+
dispatch({
118+
type: GET_USER_PROPOSAL_NOTIFICATIONS,
119+
payload: res.data.proposal || res.data.msg,
120+
});
121+
}
122+
} catch (error) {
123+
dispatch(errorHandler(error));
124+
}
125+
};
126+
127+
// GET ALL PROPOSALS
128+
export const getAllProposals = () => async (dispatch) => {
129+
try {
130+
const res = await axios.post("/proposal/all");
131+
dispatch(setRequestStatus(false));
132+
if (res.status === 200) {
133+
dispatch(setRequestStatus(true));
134+
dispatch({
135+
type: GET_ALL_PROPOSALS,
136+
payload: res.data.proposals || res.data.msg,
137+
});
138+
}
139+
} catch (error) {
140+
dispatch(errorHandler(error));
141+
}
142+
};
143+
144+
// GET PROPOSALS BY USER ID
145+
export const getProposalsByUser = (userId) => async (dispatch) => {
146+
try {
147+
const res = await axios.get(`/proposal/user/${userId}`);
148+
dispatch(setRequestStatus(false));
149+
if (res.status === 200) {
150+
dispatch(setRequestStatus(true));
151+
dispatch({
152+
type: GET_USER_PROPOSALS,
153+
payload: res.data.proposal || res.data.msg,
154+
});
155+
}
156+
} catch (error) {
157+
dispatch(errorHandler(error));
158+
}
159+
};

src/actions/types.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export const SET_ERROR = "SET_ERROR";
66
export const SET_STATUS = "SET_STATUS";
77
export const GET_PLATFORM_NOTIFICATIONS = "GET_PLATFORM_NOTIFICATIONS";
88
export const GET_USER_NOTIFICATIONS = "GET_USER_NOTIFICATIONS";
9-
export const GET_ALL_NOTIFICATIONS = "GET_ALL_NOTIFICATIONS";
9+
export const GET_PROPOSAL_NOTIFICATIONS = "GET_PROPOSAL_NOTIFICATIONS";
10+
export const GET_USER_PROPOSAL_NOTIFICATIONS =
11+
"GET_USER_PROPOSAL_NOTIFICATIONS";
1012
export const SET_ADMIN = "SET_ADMIN";
1113
export const GET_ALL_UPCOMING_EVENTS = "GET_ALL_UPCOMING_EVENTS";
1214
export const GET_ALL_MEMBERS = "GET_ALL_MEMBERS";
@@ -29,3 +31,6 @@ export const GET_ALL_POSTS = "GET_ALL_POSTS";
2931
export const GET_USER_POSTS = "GET_USER_POSTS";
3032
export const CREATE_PROPOSAL = "CREATE_PROPOSAL";
3133
export const GET_PROPOSAL = "GET_PROPOSAL";
34+
export const GET_ALL_PROPOSALS = "GET_ALL_PROPOSALS";
35+
export const EXIT = "EXIT";
36+
export const GET_USER_PROPOSALS = "GET USER PROPOSALS";
Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
1-
import { GET_PLATFORM_NOTIFICATIONS, GET_USER_NOTIFICATIONS } from "../actions/types"
1+
import {
2+
GET_PLATFORM_NOTIFICATIONS,
3+
GET_USER_NOTIFICATIONS,
4+
GET_PROPOSAL_NOTIFICATIONS,
5+
} from "../actions/types";
26

37
const initialState = {
48
platformNotifications: [],
5-
userNotifications: []
6-
}
9+
userNotifications: [],
10+
proposalNotifications: [],
11+
};
712

813
export default (state = initialState, action) => {
9-
switch(action.type) {
14+
switch (action.type) {
1015
case GET_PLATFORM_NOTIFICATIONS: {
1116
return {
1217
...state,
13-
platformNotifications: [action.payload, ...state.platformNotifications][0]
14-
}
18+
platformNotifications: [
19+
action.payload,
20+
...state.platformNotifications,
21+
][0],
22+
};
1523
}
1624
case GET_USER_NOTIFICATIONS: {
1725
return {
1826
...state,
19-
userNotifications: [action.payload, ...state.userNotifications][0]
20-
}
27+
userNotifications: [action.payload, ...state.userNotifications][0],
28+
};
29+
}
30+
case GET_PROPOSAL_NOTIFICATIONS: {
31+
return {
32+
...state,
33+
proposalNotifications: [action.payload, ...state.userNotifications][0],
34+
};
2135
}
2236
default: {
23-
return state
37+
return state;
2438
}
2539
}
26-
}
40+
};

src/reducers/proposalReducer.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,60 @@
1-
import { CREATE_PROPOSAL, GET_PROPOSAL } from "../actions/types";
1+
import {
2+
CREATE_PROPOSAL,
3+
GET_PROPOSAL,
4+
EXIT,
5+
GET_USER_PROPOSAL_NOTIFICATIONS,
6+
GET_ALL_PROPOSALS,
7+
GET_USER_PROPOSALS,
8+
} from "../actions/types";
29

310
const initialState = {
411
createdProposal: {},
512
fetchedProposal: {},
613
proposalIsFetched: false,
14+
userNotifications: [],
15+
allProposals: [],
16+
userProposals: [],
717
};
818

919
export default (state = initialState, action) => {
1020
switch (action.type) {
1121
case CREATE_PROPOSAL: {
12-
console.log("in reducer CREATE_PROPOSAL switch case");
1322
return {
1423
...state,
1524
createdProposal: action.payload,
1625
};
1726
}
1827
case GET_PROPOSAL: {
19-
console.log("in reducer");
2028
return {
2129
...state,
2230
fetchedProposal: action.payload,
2331
};
2432
}
33+
case GET_USER_PROPOSAL_NOTIFICATIONS: {
34+
return {
35+
...state,
36+
userNotification: action.payload,
37+
};
38+
}
39+
case GET_ALL_PROPOSALS: {
40+
return {
41+
...state,
42+
allProposals: action.payload,
43+
};
44+
}
45+
case GET_USER_PROPOSALS: {
46+
return {
47+
...state,
48+
userProposals: action.payload,
49+
};
50+
}
51+
case EXIT: {
52+
return {
53+
...state,
54+
createdProposal: {},
55+
fetchedProposal: {},
56+
};
57+
}
2558
default: {
2659
return state;
2760
}

0 commit comments

Comments
 (0)