Skip to content

Instantly share code, notes, and snippets.

@rafaelaugustos
Created March 9, 2018 02:30
Show Gist options
  • Save rafaelaugustos/85f8f839fa759d6312f9b4c06616bb2f to your computer and use it in GitHub Desktop.
Save rafaelaugustos/85f8f839fa759d6312f9b4c06616bb2f to your computer and use it in GitHub Desktop.

Revisions

  1. rafaelaugustos created this gist Mar 9, 2018.
    50 changes: 50 additions & 0 deletions React.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    // Login

    Api(){
    this.setState({loading: true})

    NetInfo.isConnected.addEventListener(
    'connectionChange',
    (isConnected) => this.setState({internet: isConnected})
    )

    if(this.state.internet){
    axios.post('https://localhost:8000/api/appcompras/login', {
    scheme_url: 'namine',
    email: this.state.email,
    password: this.state.senha
    })
    .then(res => {
    console.log(res)
    this.setState({loading: false})
    if(res.data.result.success){
    this.setState({error: false})
    AsyncStorage.setItem('@MySuperStore:dados', JSON.stringify(res.data))
    AsyncStorage.setItem('@MySuperStore:token', "true")
    Actions.catalogo({})
    }else{
    this.setState({error: false})
    Toast.show({
    text: res.data.result.message,
    position: 'bottom',
    buttonText: 'Okay'
    })
    }
    })
    .catch(err => console.log(err))
    }else{
    this.setState({loading: false})
    Toast.show({
    text: 'Sem conexão',
    position: 'bottom',
    buttonText: 'Okay'
    })
    }
    }


    // Catalogo
    componentDidMount(){
    console.log(AsyncStorage.getItem('@MySuperStore:dados'))
    this.loadCatalogos()
    }