Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,266 changes: 3,927 additions & 4,339 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
"react-redux": "^7.2.0",
"react-responsive": "^8.0.3",
"react-router-dom": "^5.1.2",
"react-scripts": "3.3.0",
"react-scripts": "^3.4.0",
"react-toastify": "^6.0.5",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
"redux-thunk": "^2.3.0",
"socket.io-client": "^2.3.0"
},
"proxy": "http://localhost:5000",
"scripts": {
Expand Down
33 changes: 33 additions & 0 deletions src/actions/adminAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import axios from 'axios'
import { errorHandler } from '../utils/errorHandler'
import { setRequestStatus } from '../utils/setRequestStatus'
import { SET_ADMIN } from './types'

export const createAdmin = (adminInfo) => async (dispatch) => {
try {
const res = await axios.post('/user/', adminInfo)
setRequestStatus(false)
if (res.status === 201) {
setRequestStatus(true)
}
} catch (error) {
dispatch(errorHandler(error))
}
}

export const loginAdmin = (adminInfo) => async (dispatch) => {
try {
const res = await axios.post('/auth/login/', adminInfo)
dispatch(setRequestStatus(false))
if (res.status === 200) {
dispatch(setRequestStatus(true))
localStorage.setItem('admin', true)
dispatch({
type: SET_ADMIN,
payload: true
})
}
} catch (error) {
dispatch(errorHandler(error))
}
}
32 changes: 22 additions & 10 deletions src/actions/authAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const registerUser = (userInfo, history) => async (dispatch) => {

if(res.status === 201) {
dispatch(setRequestStatus(true));
history.push('/dashboard');
history.push('/');
}

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

// update state with user
const decodedData = await jwt_decode(token);
localStorage.setItem('userId', decodedData._id)
dispatch(setCurrentUser(decodedData));
history.push("/dashboard");

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


// to logout user
export const logoutUser = () => {
// remove token from the localStorage
localStorage.removeItem('jwtToken');
// delete authorization from the header
setAuthToken(false);
// set user to {}
setCurrentUser({});
// move to home
window.location.href = "/";
export const logoutUser = () => async (dispatch) => {
try {
console.log('Logging out!!')
// clear token from backend
const res = await axios.post('/user/logout')
if (res.status === 200) {
// remove token from the localStorage
localStorage.removeItem('jwtToken');
// remove userID
localStorage.removeItem('userId')
// delete authorization from the header
setAuthToken(false);
// set user to {}
setCurrentUser({});
// move to home
window.location.href = "/";
}
} catch (error) {
dispatch(errorHandler(error))
}
}

export const setCurrentUser = (decodedData) => {
Expand Down
65 changes: 65 additions & 0 deletions src/actions/dashboardAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import axios from 'axios'
import { setRequestStatus } from '../utils/setRequestStatus'
import { errorHandler } from '../utils/errorHandler'
import { GET_ALL_UPCOMING_EVENTS } from './types'

// GET UPCOMING EVENTS
export const upcomingEvents = () => async (dispatch) => {
try {
const res = await axios.get('/event/upcoming')
dispatch(setRequestStatus(false))
if (res.status === 200) {
dispatch(setRequestStatus(true))
console.log('upcoming events called!', res.data)
dispatch({
type: GET_ALL_UPCOMING_EVENTS,
payload: res.data.events || res.data.msg
})
}
} catch (error) {
dispatch(errorHandler(error))
}
}

// CREATE POST
export const createPost = (postInfo) => async (dispatch) => {
try {
const res = await axios.post('/post/', postInfo)
dispatch(setRequestStatus(false))
if (res.status === 201) {
dispatch(setRequestStatus(true))
console.log('post created ', res.data)
}
} catch (error) {
dispatch(errorHandler(error))
}
}

// CREATE EVENT
export const createEvent = (eventInfo) => async (dispatch) => {
try {
const res = await axios.post('/event/', eventInfo)
dispatch(setRequestStatus(false))
if (res.status === 201) {
dispatch(setRequestStatus(true))
console.log('event created ', res.data)
}
} catch (error) {
dispatch(errorHandler(error))
}
}

// CREATE PROJECT
export const createProject = (projectInfo) => async (dispatch) => {
try {
console.log('projectInfo ', projectInfo)
const res = await axios.post('/project/', projectInfo)
dispatch(setRequestStatus(false))
if (res.status === 201) {
dispatch(setRequestStatus(true))
console.log('project created ', res.data)
}
} catch (error) {
dispatch(errorHandler(error))
}
}
113 changes: 113 additions & 0 deletions src/actions/insightAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { GET_ALL_MEMBERS, GET_ORG_OVERVIEW, GET_PERSONAL_OVERVIEW, SEARCH_MEMBER, BLOCK_USER, UNBLOCK_USER } from './types'
import axios from 'axios'
import { errorHandler } from '../utils/errorHandler'
import { setRequestStatus } from '../utils/setRequestStatus'

// GET ORGANIZATIONAL OVERVIEW
export const getOrgOverview = () => async (dispatch) => {
try {
const res = await axios.get('/org/overview/all')
dispatch(setRequestStatus(false))
if (res.status === 200) {
dispatch(setRequestStatus(true))
console.log('getOrgOverview ', res.data)
dispatch({
type: GET_ORG_OVERVIEW,
payload: res.data.orgOverView
})
}
} catch (error) {
dispatch(errorHandler(error))
}
}

// GET PERSONAL OVERVIEW
export const getPersonalOverview = () => async (dispatch) => {
try {
const res = await axios.get('/user/overview')
dispatch(setRequestStatus(false))
if (res.status === 200) {
dispatch(setRequestStatus(true))
console.log('getPersonalOverview ', res.data)
dispatch({
type: GET_PERSONAL_OVERVIEW,
payload: res.data.personalOverview
})
}
} catch (error) {
dispatch(errorHandler(error))
}
}

// GET ALL MEMBERS
export const getMembers = () => async (dispatch) => {
try {
const res = await axios.get('/org/members/all')
dispatch(setRequestStatus(false))
if (res.status === 200) {
dispatch(setRequestStatus(true))
console.log('getMembers ', res.data)
dispatch({
type: GET_ALL_MEMBERS,
payload: res.data.members
})
}
} catch (error) {
dispatch(errorHandler(error))
}
}

// SEARCH MEMBER BY FIRST NAME, LAST NAME, FULL NAME
export const getMember = (query) => async (dispatch) => {
try {
console.log('Looking for member ', query)
const res = await axios.get(`/org/members/all?search=${query}`)
dispatch(setRequestStatus(false))
if (res.status === 200) {
dispatch(setRequestStatus(true))
console.log('getMember by name ', res.data)
dispatch({
type: SEARCH_MEMBER,
payload: res.data.member
})
}
} catch (error) {
dispatch(errorHandler(error))
}
}

// BLOCK A USER (BY ADMIN)
export const blockUser = (userId) => async (dispatch) => {
try {
const res = await axios.patch(`/user/block/${userId}`)
dispatch(setRequestStatus(false))
if (res.status === 200) {
dispatch(setRequestStatus(true))
console.log('user blocked!', res.data)
dispatch({
type: BLOCK_USER,
payload: true
})
}
} catch (error) {
dispatch(errorHandler(error))
}
}

// UNBLOCK A USER (BY ADMIN)
export const unBlockUser = (userId) => async (dispatch) => {
try {
const res = await axios.patch(`/user/unblock/${userId}`)
dispatch(setRequestStatus(false))
if (res.status === 200) {
dispatch(setRequestStatus(true))
console.log('user unblocked!', res.data)
dispatch({
type: UNBLOCK_USER,
payload: false // isBlocked = false
})
}
} catch (error) {
dispatch(errorHandler(error))
}
}
41 changes: 41 additions & 0 deletions src/actions/notificationAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { GET_PLATFORM_NOTIFICATIONS, GET_USER_NOTIFICATIONS } from './types'
import axios from 'axios'
import { errorHandler } from '../utils/errorHandler';
import { setRequestStatus } from '../utils/setRequestStatus';

// GET NOTIFICATIONS FOR WHOLE PLATFORM AS WELL AS FOR A USER
export const getAllNotifications = () => async (dispatch) => {
try {
const res = await axios.get('/notification/org/all')
dispatch(setRequestStatus(false))
if (res.status === 200) {
dispatch(setRequestStatus(true))
console.log('Whole platform notification ', res.data.notifications)

dispatch({
type: GET_PLATFORM_NOTIFICATIONS,
payload: res.data.notifications
})
}
} catch (error) {
dispatch(errorHandler(error))
}
}

// GET NOTIFICATIONS FOR A USER
export const getUserNotification = () => async (dispatch) => {
try {
const res = await axios.get('/notification/user/all')
dispatch(setRequestStatus(false))
if (res.status === 200) {
dispatch(setRequestStatus(true))
console.log('User notification ', res.data.notifications)
dispatch({
type: GET_USER_NOTIFICATIONS,
payload: res.data.notifications
})
}
} catch (error) {
dispatch(errorHandler(error))
}
}
16 changes: 16 additions & 0 deletions src/actions/orgAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import axios from 'axios'
import { setRequestStatus } from '../utils/setRequestStatus'
import { errorHandler } from '../utils/errorHandler'

// CREATE COMMUNITY
export const registerCommunity = (orgInfo) => async (dispatch) => {
try {
const res = await axios.post('/org/', orgInfo)
dispatch(setRequestStatus(false))
if (res.status === 201) {
dispatch(setRequestStatus(true))
}
} catch (error) {
dispatch(errorHandler(error))
}
}
15 changes: 14 additions & 1 deletion src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@ export const SET_CURRENT_USER = "SET_CURRENT_USER";
export const RESPONSE_MSG = "RESPONSE_MSG";
export const GET_ERRORS = "GET_ERRORS";
export const SET_ERROR = "SET_ERROR";
export const SET_STATUS = "SET_STATUS";
export const SET_STATUS = "SET_STATUS";
export const GET_PLATFORM_NOTIFICATIONS = "GET_PLATFORM_NOTIFICATIONS";
export const GET_USER_NOTIFICATIONS = "GET_USER_NOTIFICATIONS";
export const GET_ALL_NOTIFICATIONS = "GET_ALL_NOTIFICATIONS";
export const SET_ADMIN = "SET_ADMIN";
export const GET_ALL_UPCOMING_EVENTS = "GET_ALL_UPCOMING_EVENTS";
export const GET_ALL_MEMBERS = "GET_ALL_MEMBERS";
export const GET_PERSONAL_OVERVIEW = "GET_PERSONAL_OVERVIEW";
export const GET_ORG_OVERVIEW = "GET_ORG_OVERVIEW";
export const SEARCH_MEMBER = "SEARCH_MEMBER";
export const BLOCK_USER = "BLOCK_USER";
export const UNBLOCK_USER = "UNBLOCK_USER";
export const REMOVE_USER = "REMOVE_USER";
export const GET_USER_PROFILE = "GET_USER_PROFILE";
21 changes: 21 additions & 0 deletions src/actions/usersAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { GET_USER_PROFILE } from './types'
import { errorHandler } from '../utils/errorHandler'
import axios from 'axios'
import { setRequestStatus } from '../utils/setRequestStatus'

export const getProfile = () => async (dispatch)=> {
try {
const res = await axios.get('/user/me')
dispatch(setRequestStatus(false))
if (res.status === 200) {
setRequestStatus(true)
console.log('user profile ', res.data)
dispatch({
type: GET_USER_PROFILE,
payload: res.data.user
})
}
} catch(error) {
dispatch(errorHandler(error))
}
}
Loading