-
Notifications
You must be signed in to change notification settings - Fork 6
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 #311 from factly/feat/info
feat: space info
- Loading branch information
Showing
5 changed files
with
141 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import axios from 'axios'; | ||
import { ADD_INFO, INFO_API } from '../constants/info'; | ||
import getError from '../utils/getError'; | ||
import { addErrorNotification } from './notifications'; | ||
|
||
export const getInfo = () => { | ||
return (dispatch) => { | ||
return axios | ||
.get(INFO_API) | ||
.then((response) => { | ||
dispatch(addInfo(response.data)); | ||
}) | ||
.catch((error) => { | ||
dispatch(addErrorNotification(getError(error))); | ||
}); | ||
}; | ||
}; | ||
|
||
export const addInfo = (data) => ({ | ||
type: ADD_INFO, | ||
payload: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const ADD_INFO = 'ADD_INFO'; | ||
export const INFO_API = '/core/info'; |
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,53 @@ | ||
import { ADD_INFO } from '../constants/info'; | ||
|
||
const initialState = { | ||
categories: 0, | ||
tag: 0, | ||
article: { | ||
draft: 0, | ||
template: 0, | ||
publish: 0, | ||
}, | ||
factCheck: { | ||
draft: 0, | ||
template: 0, | ||
publish: 0, | ||
}, | ||
podcasts: 0, | ||
}; | ||
|
||
export default function infoReducer(state = initialState, action = {}) { | ||
if (!action.payload) { | ||
return state; | ||
} | ||
switch (action.type) { | ||
case ADD_INFO: | ||
const posts = action.payload.posts; | ||
let article = { | ||
draft: 0, | ||
template: 0, | ||
publish: 0, | ||
}; | ||
let factCheck = { | ||
draft: 0, | ||
template: 0, | ||
publish: 0, | ||
}; | ||
|
||
posts.forEach((each) => { | ||
if (each.slug === 'article') { | ||
article[each.status] = each.count; | ||
} | ||
if (each.slug === 'fact-check') { | ||
factCheck[each.status] = each.count; | ||
} | ||
}); | ||
return { | ||
...action.payload, | ||
article, | ||
factCheck, | ||
}; | ||
default: | ||
return state; | ||
} | ||
} |