Skip to content

Instantly share code, notes, and snippets.

@devalexandre
Last active January 15, 2018 22:33
Show Gist options
  • Save devalexandre/73ceb0e17c457c73f23ba471ae1b3dce to your computer and use it in GitHub Desktop.
Save devalexandre/73ceb0e17c457c73f23ba471ae1b3dce to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
import axios from "axios";
import Cardcalls from "../components/cardcalls/cardcalls";
import ModalCall from "../components/modals/modalcalls";
import { Grid, Loader, Dimmer } from "semantic-ui-react";
import { connect } from 'react-redux'
import {bindActionCreators} from 'redux'
import { featchCalls } from '../actions/callsAction'
class Calls extends Component {
constructor(props) {
super(props);
this.state = {
calls: [],
loader: false,
selectd: null
};
}
componentDidMount() {
let vm = this;
this.setState({ loader: true });
setInterval(() => {
this.props.featchCalls
.then(res => {
console.log(res.data, "data");
const calls = res.data;
vm.setState(state => ({ ...state, calls }));
vm.setState(state => ({ ...state, loader: false }));
});
}, 3000);
}
selecionarCall(call) {
this.state(state => ({ ...state, selectd: call }));
}
render() {
const calls = this.state.calls.map((call, index) => (
<Grid.Column key={call.id}>
<Cardcalls data={call} key={index}
/>
</Grid.Column>
));
return [
<h2 key="1">Chamados</h2>,
<Dimmer key="2" active={this.state.loader} inverted>
<Loader size="large">Carregando Dados</Loader>
</Dimmer>,
<Grid key="3" columns={4} stackable>
{calls}
</Grid>
];
}
}
function mapDispatchToProps(dispatch){
return bindActionCreators({featchCalls}, dispatch)
}
export default connect(null,mapDispatchToProps)(Calls);
@felquis
Copy link

felquis commented Jan 15, 2018

linha 61

const mapDispatchToProps = (dispatch) => {
  return {
    fetchCalls: bindActionCreators(fetchCalsl, dispatch),
  }
}

@felquis
Copy link

felquis commented Jan 15, 2018

Outra coisa é que sua função se chama featchCalls, tem um a a mais no meio, acho que vc quer fetch apenas.

@devalexandre
Copy link
Author

deu certo felquis, mapiei o metodo e não o stado

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment