Guest User

Untitled

a guest
Jan 24th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. src/containers/Dashboard/Main/Main.js: Duplicate declaration "Main"
  2. 51 | import { faTh, faListUl } from '@fortawesome/free-solid-svg-icons'
  3. 52 |
  4. > 53 | function Main(props) {
  5. | ^
  6. 54 | useEffect(()=>{
  7. 55 | props.onGetCampaign()
  8. 56 | },[])
  9.  
  10. import React from 'react';
  11. import ReactDOM from 'react-dom';
  12. import { BrowserRouter } from 'react-router-dom'
  13. import { detect } from "detect-browser"
  14.  
  15. import { createStore, applyMiddleware, compose, combineReducers } from "redux";
  16. import thunk from 'redux-thunk'
  17. import { Provider } from 'react-redux'
  18.  
  19. import App from './App';
  20. import Unsupport from './components/UI/Unsupport'
  21.  
  22. import * as serviceWorker from './serviceWorker';
  23. import Campaign from './store/reducers/Campaign'
  24.  
  25. const composeEnhancers = process.env.NODE_ENV === "development" ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose : compose;
  26.  
  27. const rootReducer = combineReducers({
  28. Campaign: Campaign,
  29. });
  30.  
  31. const store = createStore(
  32. rootReducer,
  33. composeEnhancers(applyMiddleware(thunk))
  34. );
  35.  
  36. const browser = detect();
  37. if (browser) {
  38. console.log(browser.name);
  39. }
  40. // handle the case where we don't detect the browser
  41. let app = null
  42. switch (browser && browser.name) {
  43. case 'chrome':
  44. // case 'firefox':
  45. app = <App />
  46. break;
  47. default: app = <Unsupport />
  48.  
  49. }
  50. ReactDOM.render(
  51. <Provider store={store}>
  52. <BrowserRouter>
  53. {app}
  54. </BrowserRouter>
  55. </Provider>, document.getElementById('root'));
  56. serviceWorker.unregister();
  57.  
  58. import React,{useEffect} from 'react'
  59. import {connect} from 'react-redux'
  60. import * as actions from '../../../store/actions/index'
  61. import classes from './Main.module.scss'
  62. import { NavLink, Switch, Route, withRouter } from 'react-router-dom'
  63. import Main from '../../../components/Dashbord/Main/Campaing/Campaing'
  64.  
  65. import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
  66. import { faTh, faListUl } from '@fortawesome/free-solid-svg-icons'
  67.  
  68. function Main(props) {
  69. useEffect(()=>{
  70. props.onGetCampaign()
  71. },[])
  72.  
  73. return (
  74. <div className={classes.Main}>
  75. <h3 className={classes.Heading}>DASHBOARD</h3>
  76. <div className={classes.NavPanel}>
  77. <NavLink exact to="/" activeClassName={classes.active}>upcomming campaigns</NavLink>
  78. <NavLink to="/past" activeClassName={classes.active}>past campaigns</NavLink>
  79. </div>
  80.  
  81. </div>
  82. )
  83. }
  84. const mapStateToProps=state=>{
  85. return{
  86. campaign:state.campaign.campaign
  87. }
  88. }
  89. const mapDispatchToProps=dispatch=>{
  90. return{
  91. onGetCampaign:()=>dispatch(actions.getCampaign())
  92. }
  93. }
  94. export default connect(mapStateToProps,mapDispatchToProps)(Main)
  95.  
  96. import * as actions from './actionTypes'
  97. import axios from '../../axios'
  98.  
  99. //get campaigns
  100.  
  101. export const initGetCampaign = () => {
  102. return {
  103. type: actions.GET_CAMPAIGN_INIT
  104. }
  105. }
  106.  
  107. export const failGetCampaign = () => {
  108. return {
  109. type: actions.GET_CAMPAIGN_FAIL
  110. }
  111. }
  112. export const successGetCampaign = (data) => {
  113. return {
  114. type: actions.GET_CAMPAIGN_SUCCESS,
  115. data
  116. }
  117. }
  118. export const getCampaign = () => {
  119. return dispatch => {
  120. const token=localStorage.getItem('manage-token')
  121.  
  122. dispatch(initGetCampaign())
  123.  
  124. axios.get('campaigns/', {
  125. headers: {
  126. Authorization: `token ${token}`
  127. }
  128. }).then(res=>{
  129. dispatch(successGetCampaign(res.data))
  130. console.log(res.data);
  131.  
  132. }).catch(err=>{
  133. dispatch(failGetCampaign())
  134. console.log(err);
  135. })
  136. }
  137. }
  138.  
  139. import * as actions from '../actions/actionTypes'
  140.  
  141. const initialState = {
  142. loading: false,
  143. message: "",
  144. error: false,
  145. success: false,
  146. campaignList: null,
  147. getCampaign: null
  148. }
  149.  
  150. const reducer = (state = initialState, action) => {
  151. switch (action.type) {
  152. case actions.GET_CAMPAIGN_INIT:
  153. return {
  154. ...state,
  155. loading: true,
  156. error: false
  157. }
  158. case actions.GET_CAMPAIGN_FAIL:
  159. return {
  160. ...state,
  161. loading: false,
  162. error: true
  163.  
  164. }
  165. case actions.GET_CAMPAIGN_SUCCESS:
  166. return {
  167. ...state,
  168. loading: false,
  169. campaignList: action.data,
  170. error: false
  171. }
  172. default:
  173. return state
  174. }
  175. }
  176. export default reducer
  177.  
  178. export const
  179. GET_CAMPAIGN_FAIL="GET_CAMPAIGN_FAIL",
  180. GET_CAMPAIGN_INIT="GET_CAMPAIGN_INIT",
  181. GET_CAMPAIGN_SUCCESS="GET_CAMPAIGN_SUCCESS"
  182.  
  183. import React,{useEffect,useState} from 'react'
  184. import classes from './Campaing.module.scss'
  185. import axios from '../../../../axios'
  186.  
  187. function Main() {
  188. // const [video, setVideo] = useState(null)
  189. const [main, setMain] = useState(null)
  190.  
  191.  
  192.  
  193. useEffect(() => {
  194. const token = localStorage.getItem('manage-token')
  195.  
  196.  
  197. axios.get(`campaigns/`, {
  198. headers: {
  199. Authorization: `Token ${token}`
  200. }
  201. }).then(res => {
  202. console.log(res.data.results);
  203. setMain(res.data.results)
  204.  
  205. }).catch(err => {
  206. console.log(err);
  207.  
  208. })
  209.  
  210.  
  211.  
  212.  
  213. }, [])
  214. return (
  215. <div>
  216. <h1 className={classes.Header}>
  217. Dash Board
  218. </h1>
  219. {Main
  220. ?<ul className={classes.List}>
  221. {main.map(res=>{
  222. // console.log(res);
  223.  
  224. return(
  225. <li key={res.id}>
  226. <span>{res.heading}</span>
  227. <p>{res.description}</p>
  228. <p>{res.venue}</p>
  229. <p>{res.start_time}</p>
  230. <p>{res.end_time}</p>
  231. <p>{res.sponsors}</p>
  232. <p>{res.special_notes}</p>
  233. <p>{res.company.name}</p>
  234. <a href={res.campaign_url}>Show Campaign</a>
  235. </li>
  236. )
  237. })}
  238. </ul>
  239. :null}
  240. </div>
  241. )
  242. }
  243.  
  244. export default Main
Add Comment
Please, Sign In to add comment