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'
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 , CLEAR_INVITE_LINK } from './types'
22import { errorHandler } from '../utils/errorHandler'
33import axios from 'axios'
44import { setRequestStatus } from '../utils/setRequestStatus'
55import { BASE_URL } from './baseApi'
66
77// GET USER PROFILE
8- export const getProfile = ( ) => async ( dispatch ) => {
8+ export const getProfile = ( id ) => async ( dispatch ) => {
99 try {
10- const res = await axios . get ( ` ${ BASE_URL } /user/me` )
11- dispatch ( setRequestStatus ( false ) )
10+ console . log ( 'getProfile userId ' , id )
11+ const res = await axios . get ( ` ${ BASE_URL } /user/ ${ id } ` )
1212 if ( res . status === 200 ) {
13- setRequestStatus ( true )
1413 console . log ( 'user profile ' , res . data )
1514 dispatch ( {
1615 type : GET_USER_PROFILE ,
@@ -95,13 +94,12 @@ export const removeUser = (userId) => async (dispatch) => {
9594}
9695
9796// UPDATE USER PROFILE
98- export const updateProfile = ( updatedInfo ) => async ( dispatch ) => {
97+ export const updateProfile = ( userId , updatedInfo ) => async ( dispatch ) => {
9998 try {
99+ console . log ( 'updateProfile userId ' , userId )
100100 console . log ( 'updating ' , updatedInfo )
101- const res = await axios . patch ( `${ BASE_URL } /user/me` , updatedInfo )
102- dispatch ( setRequestStatus ( false ) )
101+ const res = await axios . patch ( `${ BASE_URL } /user/${ userId } ` , updatedInfo )
103102 if ( res . status === 200 ) {
104- dispatch ( setRequestStatus ( true ) )
105103 console . log ( 'user profile updated ' , res . data )
106104 dispatch ( {
107105 type : UPDATE_USER_PROFILE ,
@@ -114,9 +112,11 @@ export const updateProfile = (updatedInfo) => async (dispatch) => {
114112}
115113
116114// GET EVENTS CREATED BY USER
117- export const getEventsCreatedByUser = ( pagination = 10 , page = 1 ) => async ( dispatch ) => {
115+ export const getEventsCreatedByUser = ( userId , pagination = 10 , page = 1 ) => async ( dispatch ) => {
118116 try {
119- const res = await axios . get ( `${ BASE_URL } /event/me/all?pagination=${ pagination } &page=${ page } ` ) ;
117+ console . log ( 'getEvents userId ' , userId )
118+ const res = await axios
119+ . get ( `${ BASE_URL } /event/${ userId } /all?pagination=${ pagination } &page=${ page } ` ) ;
120120 dispatch ( setRequestStatus ( false ) )
121121 if ( res . status === 200 ) {
122122 dispatch ( setRequestStatus ( true ) )
@@ -132,9 +132,11 @@ export const getEventsCreatedByUser = (pagination = 10, page = 1) => async (disp
132132}
133133
134134// GET ALL PROJECT CREATED BY A USER
135- export const getProjectCreatedByUser = ( pagination = 10 , page = 1 ) => async ( dispatch ) => {
135+ export const getProjectCreatedByUser = ( userId , pagination = 10 , page = 1 ) => async ( dispatch ) => {
136136 try {
137- const res = await axios . get ( `${ BASE_URL } /project/me/all?pagination=${ pagination } &page=${ page } ` ) ;
137+ console . log ( 'getProjects userId ' , userId )
138+ const res = await axios
139+ . get ( `${ BASE_URL } /project/${ userId } /all?pagination=${ pagination } &page=${ page } ` ) ;
138140 dispatch ( setRequestStatus ( false ) )
139141 if ( res . status === 200 ) {
140142 dispatch ( setRequestStatus ( true ) )
@@ -150,9 +152,11 @@ export const getProjectCreatedByUser = (pagination = 10, page = 1) => async (dis
150152}
151153
152154// GET POSTS CREATED BY USER
153- export const getPostsCreatedByUser = ( pagination = 10 , page = 1 ) => async ( dispatch ) => {
155+ export const getPostsCreatedByUser = ( userId , pagination = 10 , page = 1 ) => async ( dispatch ) => {
154156 try {
155- const res = await axios . get ( `${ BASE_URL } /post/me/all?pagination=${ pagination } &page=${ page } ` ) ;
157+ console . log ( 'getPosts userId ' , userId )
158+ const res = await axios
159+ . get ( `${ BASE_URL } /post/${ userId } /all?pagination=${ pagination } &page=${ page } ` ) ;
156160 dispatch ( setRequestStatus ( false ) )
157161 if ( res . status === 200 ) {
158162 dispatch ( setRequestStatus ( true ) )
@@ -203,6 +207,14 @@ export const processInviteToken = (token) => async (dispatch) => {
203207 }
204208}
205209
210+ // CLEAR INVITE LINK
211+ export const clearInviteLink = ( ) => async ( dispatch ) => {
212+ dispatch ( {
213+ type : CLEAR_INVITE_LINK ,
214+ payload : ''
215+ } )
216+ }
217+
206218// ACTIVATE DEACTIVATE TOGGLER
207219export const activateDeactivateToggler = ( ) => async ( dispatch ) => {
208220 try {
0 commit comments