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