Нет описания

PincodeScreen.js 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import React from "react";
  2. import { StyleSheet, View, Text, Button } from 'react-native';
  3. import { globalStyles } from "../styles/global";
  4. import SmoothPinCodeInput from 'react-native-smooth-pincode-input';
  5. import { useEffect, useState } from "react";
  6. export default class App extends React.Component {
  7. // this connects us to the API and fetches the json file with the mociones
  8. getMociones = async (code) => {
  9. try {
  10. const response = await fetch(`http://10.0.0.65:5000/send?PIN=${code}`); // connection to the website
  11. const json = await response.json();
  12. console.log(json);
  13. // checks if the mocion exists
  14. if (json == "Error: No hay mocion con ese PIN."){
  15. alert("Error: No hay mocion con ese PIN.")
  16. } else {
  17. this.setState({ pincode: true});
  18. }
  19. } catch (error) {
  20. console.error(error);
  21. }
  22. }
  23. pressHandler = () => {
  24. {/*Dentro del parentesis va el path al screen para redirigir*/}
  25. this.props.navigation.navigate('Mocion')
  26. }
  27. state = {
  28. code: '',
  29. pincode: false,
  30. };
  31. pinInput = React.createRef();
  32. _checkCode = (code) => {
  33. this.getMociones(code);
  34. {/*
  35. if (code != 894761) { //this is for recieving the parameters from another screen
  36. this.pinInput.current.shake()
  37. .then(() => this.setState({ code: '' }));
  38. } else {
  39. this.setState({ pincode: true});
  40. }
  41. */}
  42. }
  43. render() {
  44. const { code } = this.state;
  45. const { pincode } = this.state;
  46. return (
  47. <View style={globalStyles.container}>
  48. {/* Pin container */}
  49. <View style={globalStyles.section}>
  50. <Text style={globalStyles.titleText}>Entra el Pin de la mocion</Text>
  51. <SmoothPinCodeInput
  52. ref={this.pinInput}
  53. value={code}
  54. codeLength={6}
  55. onTextChange={code => this.setState({ code })}
  56. onFulfill={this.getMociones}
  57. onBackspace={() => console.log('No more back.')}
  58. />
  59. </View>
  60. <View style={globalStyles.container}>
  61. { pincode && <Button title='Ir a mocion' color = {'#e81b39'} onPress={this.pressHandler} />}
  62. </View>
  63. </View>
  64. );
  65. }
  66. }