Skip to content

Commit 23887f6

Browse files
committed
implemented trigger maintenance and restricted admin mechanisms
1 parent 5efecb2 commit 23887f6

Some content is hidden

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

50 files changed

+789
-202
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"react-router-dom": "^5.1.2",
3333
"react-scripts": "^3.4.0",
3434
"react-spinners": "^0.8.3",
35+
"react-switch": "^5.0.1",
3536
"react-toastify": "^6.0.5",
3637
"redux": "^4.0.5",
3738
"redux-thunk": "^2.3.0",

src/actions/adminAction.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ export const loginAdmin = (adminInfo, history) => async (dispatch) => {
4040
localStorage.setItem('userId', decodedData._id)
4141
dispatch(setCurrentUser(decodedData));
4242

43+
// update localStorage with admin status
44+
localStorage.setItem('admin', true)
45+
4346
dispatch({
4447
type: SET_ADMIN,
4548
payload: true

src/actions/authAction.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SET_CURRENT_USER, GET_USER_PROFILE, PASSWORD_SUCCESSFULLY_CHANGED, PASSWORD_CHANGE_REQUEST_SUCCESS } from './types';
1+
import { SET_CURRENT_USER, GET_USER_PROFILE, PASSWORD_SUCCESSFULLY_CHANGED, PASSWORD_CHANGE_REQUEST_SUCCESS, SET_ADMIN } from './types';
22
import axios from 'axios';
33
import { setAuthToken } from '../utils/setAuthToken';
44
import jwt_decode from 'jwt-decode';
@@ -46,8 +46,19 @@ export const loginUser = (userInfo, history) => async (dispatch) => {
4646
const decodedData = await jwt_decode(token);
4747
localStorage.setItem('userId', decodedData._id)
4848
dispatch(setCurrentUser(decodedData));
49-
history.push("/dashboard");
5049

50+
// update user role in localStorage
51+
localStorage.setItem('admin', res.data.user.isAdmin)
52+
53+
// store orgId in localStorage
54+
localStorage.setItem('orgId', res.data.user.orgId);
55+
56+
// if user is admin update admin in store
57+
dispatch({
58+
type: SET_ADMIN,
59+
payload: res.data.user.isAdmin
60+
})
61+
history.push("/dashboard");
5162
}
5263
} catch(error) {
5364
dispatch(errorHandler(error));
@@ -104,10 +115,10 @@ export const logoutUser = () => async (dispatch) => {
104115
// clear token from backend
105116
const res = await axios.post('/user/logout')
106117
if (res.status === 200) {
107-
// remove token from the localStorage
108-
localStorage.removeItem('jwtToken');
109-
// remove userID
110-
localStorage.removeItem('userId')
118+
// remove all keys from the localStorage except the orgId
119+
const orgId = localStorage.getItem('orgId');
120+
localStorage.clear()
121+
localStorage.setItem('orgId', orgId)
111122
// delete authorization from the header
112123
setAuthToken(false);
113124
// set user to {}

src/actions/eventAction.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,19 @@ export const getEventById = (eventId) => async (dispatch) => {
8080
} catch(error) {
8181
dispatch(errorHandler(error))
8282
}
83+
}
84+
85+
// RSVP FOR EVENT SECTION
86+
export const rsvpYes = (eventId, info) => async (dispatch) => {
87+
try {
88+
const res = await axios.patch(`/event/rsvp/${eventId}`, info);
89+
dispatch(setRequestStatus(false))
90+
if(res.status === 200) {
91+
dispatch(setRequestStatus(true));
92+
console.log('Doing rsvp for the event', res.data);
93+
dispatch(getAllEvents());
94+
}
95+
} catch (error) {
96+
dispatch(errorHandler(error))
97+
}
8398
}

src/actions/orgAction.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +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'
4+
import { GET_ORG_PROFILE, UPDATE_ORG_PROFILE, DEACTIVATE_ORG, GET_ALL_MEMBERS, TRIGGER_MAINTENANCE } from './types'
55

66
// CREATE COMMUNITY
77
export const registerCommunity = (orgInfo) => async (dispatch) => {
@@ -120,4 +120,24 @@ export const deactivateOrg = () => async (dispatch) => {
120120
} catch(error) {
121121
dispatch(errorHandler(error))
122122
}
123+
}
124+
125+
// TRIGGER MAINTENANCE MODE
126+
export const TriggerMaintenance = () => async (dispatch) => {
127+
try {
128+
const orgId = localStorage.getItem('orgId')
129+
const res = await axios.patch(`/org/${orgId}/maintenance`);
130+
dispatch(setRequestStatus(false))
131+
if(res.status === 200) {
132+
dispatch(setRequestStatus(true))
133+
// set maintenance to true in localStorage
134+
localStorage.setItem('isMaintenance', res.data.maintenance);
135+
dispatch({
136+
type: TRIGGER_MAINTENANCE,
137+
payload: res.data.maintenance
138+
})
139+
}
140+
} catch (error) {
141+
dispatch(errorHandler(error))
142+
}
123143
}

src/actions/postAction.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,19 @@ export const getAllPinnedPosts = (pagination = 10, page = 1) => async (dispatch)
3737
} catch(error) {
3838
dispatch(errorHandler(error))
3939
}
40-
}
40+
}
41+
42+
// UPVOTE POST
43+
export const upVotePost = (postId) => async (dispatch) => {
44+
try {
45+
const res = await axios.patch(`/post/upvote/${postId}`)
46+
dispatch(setRequestStatus(false));
47+
if(res.status === 200) {
48+
dispatch(setRequestStatus(true));
49+
console.log('successfully upvoted post ', res.data)
50+
dispatch(getAllPosts());
51+
}
52+
} catch (error) {
53+
dispatch(errorHandler(error))
54+
}
55+
}

src/actions/types.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export const GET_EVENT_BY_ID = "GET_EVENT_BY_ID";
3939
export const GET_ADMIN = "GET_ADMIN";
4040
export const GET_COMMENTS_OF_A_POST = "GET_COMMENTS_OF_A_POST";
4141
export const GET_SINGLE_PROJECT = "GET_SINGLE_PROJECT";
42-
export const PASSWORD_CHANGE_REQUEST_SUCCESS =
43-
"PASSWORD_CHANGE_REQUEST_SUCCESS";
42+
export const PASSWORD_CHANGE_REQUEST_SUCCESS = "PASSWORD_CHANGE_REQUEST_SUCCESS";
4443
export const PASSWORD_SUCCESSFULLY_CHANGED = "PASSWORD_SUCCESSFULLY_CHANGED";
4544
export const GET_INVITE_LINK = "GET_INVITE_LINK";
4645
export const PROCESS_INVITE_LINK = "PROCESS_INVITE_LINK";
46+
export const TRIGGER_MAINTENANCE = "TRIGGER_MAINTENANCE";

src/actions/usersAction.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GET_USER_PROFILE, GET_ALL_MEMBERS, UPDATE_USER_PROFILE, GET_USER_EVENTS, GET_USER_PROJECTS, GET_USER_POSTS, GET_INVITE_LINK, PROCESS_INVITE_LINK } from './types'
1+
import { GET_USER_PROFILE, GET_ALL_MEMBERS, UPDATE_USER_PROFILE, GET_USER_EVENTS, GET_USER_PROJECTS, GET_USER_POSTS, GET_INVITE_LINK, PROCESS_INVITE_LINK, SET_ADMIN } from './types'
22
import { errorHandler } from '../utils/errorHandler'
33
import axios from 'axios'
44
import { setRequestStatus } from '../utils/setRequestStatus'
@@ -15,6 +15,13 @@ export const getProfile = () => async (dispatch)=> {
1515
type: GET_USER_PROFILE,
1616
payload: res.data.user
1717
})
18+
// if user is admin
19+
if(res.data.user.isAdmin === true) {
20+
dispatch({
21+
type: SET_ADMIN,
22+
payload: true
23+
})
24+
}
1825
}
1926
} catch(error) {
2027
dispatch(errorHandler(error))

src/auth/login-form/login-form.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
padding: 15px 0;
33
.form-group {
44
label {
5-
color: #00abff;
5+
color: #1a73e8;
6+
font-family: Inter;
67
}
78
}
89
.cta-login {
@@ -11,8 +12,8 @@
1112
justify-content: center;
1213
margin-top: 30px;
1314
button {
14-
// padding: 8px 10px;
1515
width: 104px;
16+
background-color: #1a73e8;
1617
// border-radius: 30px;
1718
}
1819
}
@@ -23,6 +24,7 @@
2324
align-items: center;
2425
justify-content: center;
2526
margin-top: 10px;
27+
color: #1a73e8;
2628
}
2729
#validation_msg {
2830
color: rgb(247, 134, 134);

0 commit comments

Comments
 (0)