|
|
@ -1,4 +1,4 @@ |
|
|
|
import React, { useState, useContext } from "react"; |
|
|
|
import React, { useState, useContext, useEffect } from "react"; |
|
|
|
import { MaterialIcons } from "@expo/vector-icons"; |
|
|
|
import { StyleSheet, Text, View } from "react-native"; |
|
|
|
import { Form, SubmitButton } from "../components/forms"; |
|
|
@ -15,7 +15,6 @@ import { AssembleIngestionPluvRegistration } from "../components/forms/AssembleI |
|
|
|
import OnSubmitAwaitModal from "../components/forms/OnSubmitAwaitModal"; |
|
|
|
import OnSubmitMessageModal from "../components/forms/OnSubmitMessageModal"; |
|
|
|
|
|
|
|
|
|
|
|
function Institution({ user }) { |
|
|
|
const institutionMap = { |
|
|
|
E: "Escola", |
|
|
@ -173,27 +172,48 @@ function PluviometerRegisterScreen(props) { |
|
|
|
const [time, setTime] = useState(moment()); |
|
|
|
const [location, setLocationAddr] = useState("Defina o endereço no mapa"); |
|
|
|
const [coordinates, setCoordinates] = useState(null); |
|
|
|
const { user, _ } = useContext(AuthContext); |
|
|
|
const { user, setUser } = useContext(AuthContext); |
|
|
|
|
|
|
|
const [showAwaitModal, setShowAwaitModal] = useState(false); |
|
|
|
const [showMessageModal, setShowMessageModal] = useState(false); |
|
|
|
const [apiMessage, setApiMessage] = useState(null); |
|
|
|
|
|
|
|
const sendForm = async (date, time, user, address, coordinates) => { |
|
|
|
const isSent = await AssembleIngestionPluvRegistration( |
|
|
|
const isSent = AssembleIngestionPluvRegistration( |
|
|
|
date, |
|
|
|
time, |
|
|
|
user, |
|
|
|
address, |
|
|
|
coordinates |
|
|
|
); |
|
|
|
).then((isSent) => { |
|
|
|
if (isSent) { |
|
|
|
setApiMessage(isSent.ok); |
|
|
|
} |
|
|
|
|
|
|
|
return apiMessage; |
|
|
|
setShowAwaitModal(false); |
|
|
|
setShowMessageModal(true); |
|
|
|
} |
|
|
|
return isSent; |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
if (apiMessage) { |
|
|
|
setUser({ |
|
|
|
...user, |
|
|
|
pluviometer: { |
|
|
|
regiterDate: date + " | " + time, |
|
|
|
address: location, |
|
|
|
institutionType: user.institutionType, |
|
|
|
institutionName: user.institutionName, |
|
|
|
coordinates: { |
|
|
|
lat: coordinates["latitude"], |
|
|
|
long: coordinates["longitude"], |
|
|
|
}, |
|
|
|
}, |
|
|
|
}); |
|
|
|
} |
|
|
|
}, [apiMessage]); |
|
|
|
|
|
|
|
return ( |
|
|
|
<View style={{ padding: 10, flex: 1 }}> |
|
|
|
<OnSubmitAwaitModal show={showAwaitModal} /> |
|
|
@ -207,10 +227,7 @@ function PluviometerRegisterScreen(props) { |
|
|
|
initialValues={{}} |
|
|
|
onSubmit={async () => { |
|
|
|
setShowAwaitModal(true); |
|
|
|
sendForm(date, time, user, location, coordinates).then((isSent) => { |
|
|
|
setShowAwaitModal(false); |
|
|
|
setShowMessageModal(true); |
|
|
|
}); |
|
|
|
sendForm(date, time, user, location, coordinates); |
|
|
|
}} |
|
|
|
> |
|
|
|
<View |
|
|
@ -224,7 +241,6 @@ function PluviometerRegisterScreen(props) { |
|
|
|
: "Cadastro do Pluviômetro"} |
|
|
|
</Text> |
|
|
|
|
|
|
|
|
|
|
|
<Text |
|
|
|
style={{ |
|
|
|
marginTop: 24, |
|
|
@ -247,7 +263,6 @@ function PluviometerRegisterScreen(props) { |
|
|
|
pluviometer={user.pluviometer} |
|
|
|
/> |
|
|
|
|
|
|
|
|
|
|
|
<Text style={styles.label}>Endereço do pluviômetro*: </Text> |
|
|
|
|
|
|
|
<View marginBottom={24} marginTop={12}> |
|
|
@ -304,7 +319,6 @@ const styles = StyleSheet.create({ |
|
|
|
textAlign: "center", |
|
|
|
color: colors.primary, |
|
|
|
}, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
export default PluviometerRegisterScreen; |