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.
 
 
 

163 lines
4.8 KiB

import React, { useState, useContext, useEffect } from "react";
import { StyleSheet, Text, View } from "react-native";
import * as Yup from "yup";
import { Form, SubmitButton, FormField } from "../components/forms";
import FormImagePicker from "../components/forms/FormImagePicker";
import colors from "../config/colors";
import { scaleDimsFromWidth, dimensions } from "../config/dimensions";
import { insertFloodZone } from "../database/databaseLoader";
import { showMessage } from "react-native-flash-message";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import Screen from "../components/Screen";
import assets from "../config/assets";
import moment from "moment";
import { EventLocationContext } from "../context/EventLocationContext";
import PickEventDateLocation from "../components/PickEventDateLocation";
import SvgLabeledButton from "../components/SvgLabeledButton";
import { formcode } from "../components/forms/FormsCode";
import { AssembleIngestionObject } from "../components/forms/AssembleIngestionObject";
const validationSchema = Yup.object().shape({
images: Yup.array(),
description: Yup.string().label("Description"),
});
function SharingFloodZonesScreen(props) {
const user = props.route.params.user;
const [passable, setPassable] = useState(-1);
const [floodSituation, setFloodSituation] = useState(null);
const code = formcode.floodzones;
const [error, setError] = useState(false);
const [date, setDate] = useState(moment());
const [time, setTime] = useState(moment());
const context = useContext(EventLocationContext);
const address = context.eventLocation;
useEffect(() => {
context.defaultLocation();
}, []);
const location = context.eventCoordinates;
return (
<Screen style={styles.container}>
<KeyboardAwareScrollView
resetScrollToCoords={{ x: 0, y: 0 }}
scrollEnabled={true}
>
<Form
initialValues={{
images: [],
description: "",
}}
onSubmit={(values) => {
if (passable == -1) {
setError(true);
return;
}
//insertFloodZone({ ...values, passable, location, date, time, address, });
AssembleIngestionObject(
{
...values,
},
user,
floodSituation,
code,
location,
date,
time,
address
);
showMessage({
message: "Informação enviada!",
duration: 1950,
icon: "success",
type: "success",
});
props.navigation.navigate("Home");
}}
validationSchema={validationSchema}
>
<View style={styles.imgs_container}>
<SvgLabeledButton
style={{ marginRight: 17 }}
label={"TRANSITÁVEL"}
isToggle={passable == 1}
SvgImage={assets.floodZones.passable}
onPress={() => {
setPassable(1);
setFloodSituation("TRANSITÁVEL");
}}
/>
<SvgLabeledButton
onPress={() => {
setPassable(0);
setFloodSituation("INTRANSITÁVEL");
}}
label={"INTRANSITÁVEL"}
isToggle={passable == 0}
SvgImage={assets.floodZones.notPassable}
/>
</View>
{error && passable == -1 && (
<Text style={styles.error_txt}>Selecione uma opção</Text>
)}
<FormImagePicker name="images" height={10} />
<PickEventDateLocation
date={date}
time={time}
setDate={setDate}
setTime={setTime}
navigation={props.navigation}
/>
<Text style={styles.labelStyle}>Comentário:</Text>
<FormField
maxLength={255}
multiline
name="description"
numberOfLines={3}
placeholder="Escreva um comentário (Opcional)..."
/>
<View paddingVertical={24}>
<SubmitButton title="Enviar" backgroundColor={colors.primary} />
</View>
</Form>
</KeyboardAwareScrollView>
</Screen>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: colors.white,
},
imgs_container: {
paddingTop: 16,
flexDirection: "row",
justifyContent: "center",
},
error_txt: {
paddingHorizontal: 16,
fontSize: 18,
color: colors.danger,
},
labelStyle: {
fontSize: dimensions.text.secondary,
fontWeight: "bold",
paddingHorizontal: 16,
paddingBottom: 12,
textAlign: "left",
color: colors.lightBlue,
},
});
export default SharingFloodZonesScreen;