Error calling more than one function in onPress

Asked

Viewed 555 times

2

I have a Button with a onPress

If I put this onPress thus:

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 sends the data to API, all right.

But if I try to call one more function in this very 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() }
}

He executes the Actions.index() correctly but returns me Request failed with status code 500 in the request

What could be the reason?

EDIT

The request that this call 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;
  • It performs the index correctly, as action is called page, and goes to ok page, it starts to return me the 500 no request, which if done alone will not result error

1 answer

1


I managed to sort it out like this

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 had to use ; in place of , and put the request amid {}

But I got better with a function and the call of this:

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 sits on the modal

{this._renderButton('Sim, cadastrar', () => this.finalizaManifestacao() )}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.