You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

132 lines
3.4 KiB

import React, { useState } from "react";
import {
StyleSheet,
Text,
View,
Image,
ScrollView,
} from "react-native";
import * as Yup from "yup";
import {
Form,
FormField,
FormPicker as Picker,
SubmitButton,
} from "../components/forms";
import Screen from "../components/Screen";
import useLocation from "../hooks/useLocation";
import FormImagePicker from "../components/forms/FormImagePicker";
import { insertPluviometerData } from "../database/databaseLoader";
import { showMessage } from "react-native-flash-message";
import { scaleDimsFromWidth } from "../config/dimensions";
import FormDatePicker from "../components/forms/FormDatePicker";
const dims = scaleDimsFromWidth(85, 85, 25);
const validationSchema = Yup.object().shape({
pluviometer: Yup.number()
.required("Campo obrigatório")
.min(0, "O valor deve ser maior ou igual a 0.")
.max(10000)
.label("pluviometer"),
//data: Yup.string().required("Campo obrigatório. Por favor, selecione a data"),
images: Yup.array(),
});
function PluviometerSharingDataScreen(props) {
const location = useLocation();
const [dateTime, setDateTime] = useState();
return (
<Screen style={styles.container}>
<View style={{ alignItems: "center" }}>
<Image
style={styles.image}
source={require("../assets/pluviometro.png")}
/>
<Text style={{ fontSize: 18, fontWeight: "bold", color: "#1976D2" }}>
Pluviômetro
</Text>
</View>
<ScrollView>
<Form
initialValues={{
pluviometer: "",
//data: "",
images: [],
}}
onSubmit={(values) => {
insertPluviometerData({ ...values, dateTime, location });
showMessage({
message: "Informação enviada!",
duration: 3000,
icon: "success",
type: "success",
});
props.navigation.goBack(null);
}}
validationSchema={validationSchema}
>
<View style={{ marginTop: 30, flex: 1 }}>
<Text style={styles.labelStyle}>Quantidade de chuva:</Text>
<FormField
keyboardType="number-pad"
maxLength={200}
name="pluviometer"
placeholder="Digite a quantidade de chuva"
/>
</View>
<View style={{ marginTop: 10, flex: 1 }}>
<Text style={styles.labelStyle}>Data da coleta:</Text>
<FormDatePicker
textStyle={{
padding: 15,
borderColor: "gray",
borderWidth: 3,
}}
defaultDate={new Date()}
onDateChange={(value) => setDateTime(value)}
/>
</View>
<FormImagePicker
backgroundColor="#1976D2"
name="images"
styles={{ width: 50 }}
/>
<SubmitButton title="Enviar" style={{ marginBottom: 100 }} />
<View style={{ flex: 1 }}></View>
</Form>
</ScrollView>
</Screen>
);
}
const styles = StyleSheet.create({
container: {
padding: 10,
flex: 1,
},
image: {
width: dims.width * 0.8,
height: dims.height * 0.8,
justifyContent: "center",
alignItems: "center",
},
labelStyle: {
fontSize: 16,
fontWeight: "bold",
textAlign: "left",
color: "#1976D2",
marginBottom: 5,
},
});
export default PluviometerSharingDataScreen;