getTopic.js 762 B

1234567891011121314151617181920212223242526272829
  1. import { put, call, all } from 'redux-saga/effects';
  2. import axios from 'axios';
  3. import { CREATE_TOPICS } from '../../../constants/admin';
  4. import { getTopicSuccess, getTopicFailure} from '../../../actions/admin/changeTest/getTopic';
  5. import storageKey from '../../../utils/storageKey';
  6. const getItem = localStorage.getItem(storageKey);
  7. export default function* ({payload:{_id}}) {
  8. try {
  9. const config ={
  10. headers: {
  11. "Authorization": `Bearer ${getItem}`
  12. }
  13. }
  14. const topic = yield call(() =>
  15. axios.get(`${CREATE_TOPICS}?category=${_id}` ,config)
  16. )
  17. yield put(getTopicSuccess(topic));
  18. }
  19. catch ({ message }) {
  20. yield put(getTopicFailure(message));
  21. }
  22. }