|
@@ -9,16 +9,19 @@ import { useEffect, useState } from "react";
|
9
|
9
|
export default class App extends React.Component {
|
10
|
10
|
|
11
|
11
|
|
12
|
|
- // this connects us to the API and fetches the json file with the mociones
|
13
|
|
- getMociones = async (code) => {
|
|
12
|
+ // this checks the pin the user inputs to see if there is a mocion with that pin
|
|
13
|
+ getPin = async (code) => {
|
14
|
14
|
try {
|
15
|
15
|
const response = await fetch(`http://10.0.0.65:5000/send?PIN=${code}`); // connection to the website
|
16
|
16
|
const json = await response.json();
|
17
|
17
|
console.log(json);
|
18
|
18
|
|
19
|
19
|
// checks if the mocion exists
|
20
|
|
- if (json == "Error: No hay mocion con ese PIN."){
|
|
20
|
+ if (JSON.stringify(json) == '{"Error":"No hay mocion con ese PIN."}' ){
|
21
|
21
|
alert("Error: No hay mocion con ese PIN.")
|
|
22
|
+ this.pinInput.current.shake()
|
|
23
|
+ .then(() => this.setState({ code: '' }));
|
|
24
|
+
|
22
|
25
|
} else {
|
23
|
26
|
this.setState({ pincode: true});
|
24
|
27
|
}
|
|
@@ -30,32 +33,20 @@ export default class App extends React.Component {
|
30
|
33
|
|
31
|
34
|
}
|
32
|
35
|
|
33
|
|
-
|
34
|
36
|
|
35
|
|
- pressHandler = () => {
|
|
37
|
+ pressHandler = (code) => {
|
36
|
38
|
{/*Dentro del parentesis va el path al screen para redirigir*/}
|
37
|
|
- this.props.navigation.navigate('Mocion')
|
|
39
|
+ this.props.navigation.navigate('Mocion', {Pin:code})
|
|
40
|
+ this.setState({ pincode: false});
|
|
41
|
+ this.setState({ code: '' })
|
38
|
42
|
}
|
39
|
43
|
|
40
|
44
|
state = {
|
41
|
45
|
code: '',
|
42
|
46
|
pincode: false,
|
43
|
47
|
};
|
44
|
|
- pinInput = React.createRef();
|
45
|
|
-
|
46
|
|
- _checkCode = (code) => {
|
47
|
48
|
|
48
|
|
- this.getMociones(code);
|
49
|
|
-
|
50
|
|
- {/*
|
51
|
|
- if (code != 894761) { //this is for recieving the parameters from another screen
|
52
|
|
- this.pinInput.current.shake()
|
53
|
|
- .then(() => this.setState({ code: '' }));
|
54
|
|
- } else {
|
55
|
|
- this.setState({ pincode: true});
|
56
|
|
- }
|
57
|
|
- */}
|
58
|
|
- }
|
|
49
|
+ pinInput = React.createRef();
|
59
|
50
|
|
60
|
51
|
render() {
|
61
|
52
|
const { code } = this.state;
|
|
@@ -70,13 +61,13 @@ export default class App extends React.Component {
|
70
|
61
|
value={code}
|
71
|
62
|
codeLength={6}
|
72
|
63
|
onTextChange={code => this.setState({ code })}
|
73
|
|
- onFulfill={this.getMociones}
|
|
64
|
+ onFulfill={this.getPin}
|
74
|
65
|
onBackspace={() => console.log('No more back.')}
|
75
|
66
|
/>
|
76
|
67
|
</View>
|
77
|
68
|
|
78
|
69
|
<View style={globalStyles.container}>
|
79
|
|
- { pincode && <Button title='Ir a mocion' color = {'#e81b39'} onPress={this.pressHandler} />}
|
|
70
|
+ { pincode && this.pressHandler(code)}
|
80
|
71
|
</View>
|
81
|
72
|
|
82
|
73
|
</View>
|