Error trying to call more than one function in onPress

2

I have a Button with a onPress

If I put this onPress like this:

onPress={() => request.manifestacaoAnonima(
    this.state.email,
    this.state.selected,
    this.state.manifesto,
    this.state.tipomanifestacao,
    this.state.tipopessoa,
    this.state.latitude,
    this.state.longitude,
    this.state.endereco,
    this.state.numero,
    this.state.complemento,
    this.state.bairro,
    this.state.cidade
  )}

It works send the data to API , everything ok.

But if I try to call another function in this same onPress :

onPress={() => { request.manifestacaoAnonima(
    this.state.email,
    this.state.selected,
    this.state.manifesto,
    this.state.tipomanifestacao,
    this.state.tipopessoa,
    this.state.latitude,
    this.state.longitude,
    this.state.endereco,
    this.state.numero,
    this.state.complemento,
    this.state.bairro,
    this.state.cidade
  ), Actions.index() }
}

It runs Actions.index() correctly but returns Request failed with status code 500 on request

What could be the reason?

EDIT

The request you are calling comes from import request from './services/request';

Which has:

const request = {

  let: dssenha = geraSenha(6),

  manifestacaoAnonima: (
    eeemailusuario,
    local,
    dstextomanifestacao,
    idtipomanifestacao,
    tipopessoa,
    latitude,
    longitude,
    endereco,
    numero,
    complemento,
    bairro,
    cidade
  ) => {
    axios.post('http://192.168.0.23/apiTeste/public/api/manifestacao?'
    +'dssenha='+dssenha
    +'&dstextomanifestacao='+dstextomanifestacao
    +'&eeemailusuario='+eeemailusuario
    +'&nmpessoa=Anônimo'
    +'&nrpronac='+local
    +'&tipopessoa='+tipopessoa
    +'&idtipomanifestacao='+idtipomanifestacao
    +'&latitude='+latitude
    +'&longitude='+longitude
    +'&enendereco='+endereco
    +'&nrendereco='+numero
    +'&dscomplemento='+complemento
    +'&dsbairro='+bairro
    +'&dslocalidade='+cidade
    )
    .then(response => {
      console.log(response);
    }).catch((error) => { 
      console.log(error.message)
    });
  },
};

export default request;
    
asked by anonymous 19.12.2017 / 17:43

1 answer

1

I was able to solve this problem

onPress={() => { Actions.principal();
                  { 
                    request.manifestacaoAnonima(
                      this.state.email,
                      this.state.selected,
                      this.state.manifesto,
                      this.state.tipomanifestacao,
                      this.state.tipopessoa,
                      this.state.latitude,
                      this.state.longitude,
                      this.state.endereco,
                      this.state.numero,
                      this.state.complemento,
                      this.state.bairro,
                      this.state.cidade
                    ) 
                 }
         }  

As said by Lucas Costa I had to use ; instead of , and put request between {}

But I ended up improving with a function and calling it:

finalizaManifestacao = () => {
    Actions.index();
    this.setState({ visibleModal: null });
    { 
      this.state.anonima == 1 ?
        request.manifestacaoAnonima(
          this.state.email,
          this.state.selected,
          this.state.manifesto,
          this.state.tipomanifestacao,
          this.state.tipopessoa,
          this.state.latitude,
          this.state.longitude,
          this.state.endereco,
          this.state.numero,
          this.state.complemento,
          this.state.bairro,
          this.state.cidade
        ) : 
        request.manifestacao(
          this.state.email,
          this.state.selected,
          this.state.manifesto,
          this.state.tipomanifestacao,
          this.state.tipopessoa,
          this.state.latitude,
          this.state.longitude,
          this.state.endereco,
          this.state.numero,
          this.state.complemento,
          this.state.bairro,
          this.state.cidade,
          this.state.nome,
          this.state.cel,
          this.state.tel,
          this.state.cpf,
          this.state.tipopessoa
        ) 
    } 
  }

And the call on a button that stays in the modal

{this._renderButton('Sim, cadastrar', () => this.finalizaManifestacao() )}
    
19.12.2017 / 18:39