Нема описа

PincodeScreen.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 checks the pin the user inputs to see if there is a mocion with that pin
  8. getPin = async (code) => {
  9. try {
  10. const response = await fetch(`http://10.190.1.140: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.stringify(json) == '{"Error":"No hay mocion con ese PIN."}' ){
  15. alert("Error: No hay mocion con ese PIN.")
  16. this.pinInput.current.shake()
  17. .then(() => this.setState({ code: '' }));
  18. } else {
  19. //move to the mocion page
  20. this.props.navigation.navigate('Mocion', {Pin:code});
  21. this.setState({ code: '' });
  22. }
  23. } catch (error) {
  24. console.error(error);
  25. }
  26. }
  27. state = {
  28. code: '',
  29. };
  30. pinInput = React.createRef();
  31. render() {
  32. const { code } = this.state;
  33. const { pincode } = this.state;
  34. return (
  35. <View style={globalStyles.container}>
  36. {/* Pin container */}
  37. <View style={globalStyles.section}>
  38. <Text style={globalStyles.titleText}>Entra el Pin de la mocion</Text>
  39. <SmoothPinCodeInput
  40. ref={this.pinInput}
  41. value={code}
  42. codeLength={6}
  43. onTextChange={code => this.setState({ code })}
  44. onFulfill={this.getPin}
  45. onBackspace={() => console.log('No more back.')}
  46. />
  47. </View>
  48. </View>
  49. );
  50. }
  51. }