-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fetching data for admin page using redux #125
Open
Subhang23
wants to merge
6
commits into
dsciitpatna:master
Choose a base branch
from
Subhang23:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7e16848
Fetching data for admin page using redux
Subhang23 ef314ad
renaming the category in admion page
Subhang23 3d8bd88
fetching from /helper/url
Subhang23 c06e5b2
resolving merge conflict
Subhang23 f6999c3
Minor fixes
Subhang23 fb0aff6
minor fixes
Subhang23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {FETCH_CATEGORY,DELETE_CATEGORY,ADD_CATEGORY,UPDATE_CATEGORY} from './type'; | ||
import axios from 'axios'; | ||
import {url} from '../../helper/url'; | ||
import { tokenConfig } from './authActions'; | ||
|
||
export const fetchCategory =()=>{ | ||
return dispatch =>{ | ||
axios.get(`${url}/categories`) | ||
.then(res=>{ | ||
dispatch({ | ||
type:FETCH_CATEGORY, | ||
payload: res.data.categories, | ||
}) | ||
}) | ||
} | ||
}; | ||
|
||
export const deleteCategory =(e)=> (dispatch,getState) =>{ | ||
const config = tokenConfig(getState); | ||
axios.delete(`${url}/categories/`+e,config) | ||
.then(res=>{ | ||
dispatch({ | ||
type:DELETE_CATEGORY, | ||
payload: e, | ||
}) | ||
}) | ||
|
||
}; | ||
|
||
export const addCategory =(name)=>(dispatch,getState)=>{ | ||
const config = tokenConfig(getState); | ||
Subhang23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const body = JSON.stringify({ name }); | ||
axios.post(`${url}/categories`,body,config) | ||
.then(res=>{ | ||
dispatch({ | ||
type:ADD_CATEGORY, | ||
payload: res.data, | ||
}) | ||
}) | ||
|
||
}; | ||
|
||
export const updateCategory =(name,id)=>(dispatch,getState) =>{ | ||
const config = tokenConfig(getState); | ||
Subhang23 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const body = JSON.stringify({ name }); | ||
axios.patch(`${url}/categories/`+id,body,config) | ||
.then(res=>{ | ||
dispatch({ | ||
type:UPDATE_CATEGORY, | ||
payload: id, | ||
newCategory:res.data, | ||
}) | ||
}) | ||
|
||
}; | ||
|
||
|
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,37 @@ | ||
import {FETCH_CATEGORY,DELETE_CATEGORY,ADD_CATEGORY,UPDATE_CATEGORY} from '../actions/type'; | ||
|
||
const initState={ | ||
category:[], | ||
} | ||
|
||
const fetchCategory=(state=initState,action)=>{ | ||
switch(action.type){ | ||
case FETCH_CATEGORY: | ||
return { | ||
...state, | ||
category:action.payload | ||
} | ||
case ADD_CATEGORY: | ||
return {category :state.category.concat(action.payload)} | ||
case DELETE_CATEGORY : | ||
return { category: state.category.filter(catname => | ||
catname._id !== action.payload | ||
)} | ||
case UPDATE_CATEGORY: | ||
return{ | ||
category :state.category.map(item=>{ | ||
if(item._id===action.payload) | ||
return { | ||
_id:action.payload, | ||
name:action.newCategory.name, | ||
register_date:action.newCategory.register_date | ||
} | ||
else | ||
return item | ||
}) | ||
} | ||
default: return state; | ||
} | ||
|
||
} | ||
export default fetchCategory; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to create a new variable config. directly use
tokenConfig(getState)
in the axios call