generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from mohammadkhizerkhan/feature/get-user-api-…
…integration Feature/get user api integration
- Loading branch information
Showing
15 changed files
with
315 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const getUser = (userId: string) => { | ||
return { | ||
type: 'GET_USER', | ||
payload: userId, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { combineReducers } from 'redux'; | ||
import user from './user.reducer'; | ||
|
||
const reducers = combineReducers({ user }); | ||
|
||
export default reducers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export const intialState = { | ||
data: {}, | ||
loading: false, | ||
error: '', | ||
}; | ||
|
||
const user = (state = intialState, action) => { | ||
switch (action.type) { | ||
case 'FETCH_USER': | ||
return { ...state, loading: false, data: action.user }; | ||
case 'GET_USER': | ||
return { ...state, loading: true }; | ||
case 'FETCH_USER_ERROR': | ||
return { ...state, loading: false, error: action.message }; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { call, put, takeEvery } from 'redux-saga/effects'; | ||
import { User } from '../../context/type'; | ||
import { fetchUserData } from '../requests/fetchUser'; | ||
|
||
export function* fetchUserRequest(action) { | ||
try { | ||
const user: User = yield call(fetchUserData, action.payload); | ||
yield put({ type: 'FETCH_USER', user: user }); | ||
} catch (error: any) { | ||
yield put({ type: 'FETCH_USER_ERROR', message: error.message }); | ||
} | ||
} | ||
|
||
function* watchUserRequestSaga() { | ||
yield takeEvery('GET_USER', fetchUserRequest); | ||
} | ||
|
||
export default watchUserRequestSaga; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import axios from 'axios'; | ||
import { urls } from '../../constants/appConstant/url'; | ||
import { User } from '../../context/type'; | ||
|
||
export const fetchUserData = async (userId: string): Promise<User | null> => { | ||
try { | ||
const response = await axios.get(urls.GET_USER_DATA + userId, { | ||
headers: { | ||
cookie: '', | ||
}, | ||
}); | ||
const user = response.data.user; | ||
return { | ||
name: user.github_display_name, | ||
profileUrl: user.picture?.url, | ||
userName: user.username, | ||
designation: user.designation, | ||
company: user.company, | ||
linkedInUrl: urls.LINKEDIN + user.linkedin_id, | ||
twitterUrl: urls.GITHUB + user.twitter_id, | ||
githubUrl: urls.TWITTER + user.github_id, | ||
}; | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { all } from 'redux-saga/effects'; | ||
import watchUserRequestSaga from './handlers/user'; | ||
|
||
function* rootSaga() { | ||
yield all([watchUserRequestSaga()]); | ||
} | ||
|
||
export default rootSaga; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.