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.
 
 
 

202 lines
6.3 KiB

import React, { useContext, useEffect, useState } from "react";
import { StyleSheet, View, ScrollView, PixelRatio } from "react-native";
import * as Yup from "yup";
import { Form, SubmitButton, FormField } from "../components/forms";
import Screen from "../components/Screen";
import FormImagePicker from "../components/forms/FormImagePicker";
import { Text, TouchableOpacity } from "react-native";
import colors from "../config/colors";
import { TouchableNativeFeedback } from "react-native-gesture-handler";
import { insertRainData } from "../database/databaseLoader";
import { showMessage } from "react-native-flash-message";
import { scaleDimsFromWidth, dimensions } from "../config/dimensions";
import assets from "../config/assets";
import moment from "moment";
import FormDatePicker from "../components/forms/FormDatePicker";
import FormLocationPicker from "../components/forms/FormLocationPicker";
import { EventLocationContext } from "../context/EventLocationContext";
const validationSchema = Yup.object().shape({
images: Yup.array(),
description: Yup.string().label("Description"),
});
const borderWidth = 4;
function RainSharingDataScreen(props) {
const [rain, setRain] = useState(-1);
const [error, setError] = useState(false);
const dims = scaleDimsFromWidth(85, 85, 27);
const [date, setDate] = useState(moment());
const [time, setTime] = useState(moment());
const context = useContext(EventLocationContext);
useEffect(() => {
context.defaultLocation();
}, []);
const location = context.eventCoordinates;
const address = context.eventLocation;
return (
<Screen style={styles.container}>
<ScrollView>
<Form
initialValues={{
images: [],
}}
onSubmit={(values) => {
if (rain == -1) {
setError(true);
return;
}
insertRainData({ ...values, rain, location, date, time, address });
showMessage({
message: "Informação enviada!",
duration: 1950,
icon: "success",
type: "success",
onPress: () => { },
});
props.navigation.navigate("Home");
}}
validationSchema={validationSchema}
>
<View>
<View style={styles.imgs_row}>
<TouchableNativeFeedback onPress={() => setRain(0)}>
<View style={styles.img_block}>
{rain == 0 ? (
<assets.rainLevel.Rain_0_5_Toggle {...dims} />
) : (
<assets.rainLevel.Rain_0_5 {...dims} />
)}
</View>
</TouchableNativeFeedback>
<TouchableNativeFeedback onPress={() => setRain(1)}>
<View style={styles.img_block}>
{rain == 1 ? (
<assets.rainLevel.Rain_1_5_Toggle {...dims} />
) : (
<assets.rainLevel.Rain_1_5 {...dims} />
)}
</View>
</TouchableNativeFeedback>
<TouchableNativeFeedback onPress={() => setRain(2)}>
<View style={styles.img_block}>
{rain == 2 ? (
<assets.rainLevel.Rain_2_5_Toggle {...dims} />
) : (
<assets.rainLevel.Rain_2_5 {...dims} />
)}
</View>
</TouchableNativeFeedback>
</View>
<View flexDirection="row" justifyContent="center">
<TouchableNativeFeedback onPress={() => setRain(3)}>
<View style={styles.img_block}>
{rain == 3 ? (
<assets.rainLevel.Rain_3_5_Toggle {...dims} />
) : (
<assets.rainLevel.Rain_3_5 {...dims} />
)}
</View>
</TouchableNativeFeedback>
<TouchableNativeFeedback onPress={() => setRain(4)}>
<View style={styles.img_block}>
{rain == 4 ? (
<assets.rainLevel.Rain_4_5_Toggle {...dims} />
) : (
<assets.rainLevel.Rain_4_5 {...dims} />
)}
</View>
</TouchableNativeFeedback>
</View>
</View>
{error && rain == -1 && (
<Text style={styles.error_txt}>Selecione o nível da chuva </Text>
)}
<FormImagePicker backgroundColor={colors.primary} name="images" />
<View
style={{
flex: 1,
flexDirection: "column",
justifyContent: "space-between",
alignContent: "flex-start",
}}
>
{/*Data da coleta:*/}
<View
style={{
flex: 1,
}}
>
<FormDatePicker
textStyle={{
borderColor: colors.gray,
borderWidth: 3,
}}
defaultDate={new Date()}
onDateChange={(value) => setDate(value)}
onTimeChange={(value) => setTime(value)}
/>
</View>
{/*Local do evento:*/}
<View style={{ flex: 1 }}>
<TouchableOpacity
onPress={() => props.navigation.navigate("FormMap")}
>
<FormLocationPicker />
</TouchableOpacity>
</View>
</View>
<FormField
maxLength={255}
multiline
name="description"
numberOfLines={3}
placeholder="Descrição"
/>
<SubmitButton title="Enviar" backgroundColor={colors.primary} />
</Form>
</ScrollView>
</Screen>
);
}
const styles = StyleSheet.create({
container: {
padding: 10,
backgroundColor: colors.white,
},
img_block: {
flex: 1,
borderRadius: 5,
borderStyle: "dotted",
borderColor: colors.white,
borderWidth: borderWidth,
alignItems: "center",
},
imgs_row: {
flexDirection: "row",
justifyContent: "space-between",
},
error_txt: {
fontSize: dimensions.text.default,
color: colors.danger,
},
});
export default RainSharingDataScreen;