gab-social/app/javascript/gabsocial/actions/promotions.js
mgabdev 21937d9e09 Added promotions to redux and added selector for setting promotions if not PRO
• Added:
- promotions to redux
- selector for setting promotions if not PRO

• Updated:
- StatusList, SidebarPanelGroup to use promotions from redux
2020-11-09 13:28:43 -06:00

34 lines
869 B
JavaScript

import api from '../api'
import { me } from '../initial_state'
export const PROMOTIONS_FETCH_REQUEST = 'PROMOTIONS_FETCH_REQUEST'
export const PROMOTIONS_FETCH_SUCCESS = 'PROMOTIONS_FETCH_SUCCESS'
export const PROMOTIONS_FETCH_FAIL = 'PROMOTIONS_FETCH_FAIL'
export const fetchPromotions = () => {
return (dispatch, getState) => {
if (!me) return
dispatch(fetchPromotionsRequest())
api(getState).get('/api/v1/promotions').then((response) => {
dispatch(fetchPromotionsSuccess(response.data))
}).catch((error) => {
dispatch(fetchPromotionsFail(error))
})
}
}
const fetchPromotionsRequest = () => ({
type: PROMOTIONS_FETCH_REQUEST,
})
const fetchPromotionsSuccess = (items) => ({
type: PROMOTIONS_FETCH_SUCCESS,
items,
})
const fetchPromotionsFail = (error, listType) => ({
type: PROMOTIONS_FETCH_FAIL,
error,
})