import React, { useEffect, useState, useContext } from "react"; import { StyleSheet, View } 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 } from "react-native"; import colors from "../config/colors"; import { insertRiverData } from "../database/databaseLoader"; import { showMessage } from "react-native-flash-message"; import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"; import assets from "../config/assets"; import { dimensions } from "../config/dimensions"; 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"; import OnSubmitMessageModal from "../components/forms/OnSubmitMessageModal"; import OnSubmitAwaitModal from "../components/forms/OnSubmitAwaitModal"; const validationSchema = Yup.object().shape({ images: Yup.array(), description: Yup.string().label("Description"), }); function RiverFloodSharingDataScreen(props) { const user = props.route.params.user; const [riverScale, setRiverScale] = useState(-1); const [riverSituation, setRiverSituation] = useState(null); const code = formcode.river; const context = useContext(EventLocationContext); useEffect(() => { context.defaultLocation(); }, []); const location = context.eventCoordinates; const address = context.eventLocation; const [error, setError] = useState(false); const [date, setDate] = useState(moment()); const [time, setTime] = useState(moment()); const [showAwaitModal, setShowAwaitModal] = useState(false); const [showMessageModal, setShowMessageModal] = useState(false); const [apiMessage, setApiMessage] = useState(null); const sendForm = async ( { images, description }, user, situation, code, location, date, time, address ) => { const isSent = await AssembleIngestionObject( { images, description }, user, situation, code, location, date, time, address ); setApiMessage(isSent.ok); return apiMessage; }; return (
{ if (riverScale == -1) { setError(true); return; } setShowAwaitModal(true); sendForm( { ...values, }, user, riverSituation, code, location, date, time, address ).then((isSent) => { setShowAwaitModal(false); setShowMessageModal(true); }); }} validationSchema={validationSchema} > { setRiverScale(0); setRiverSituation("BAIXO"); }} SvgImage={assets.riverLevel.Low} label={"BAIXO"} isToggle={riverScale == 0} /> { setRiverScale(1); setRiverSituation("NORMAL"); }} SvgImage={assets.riverLevel.Normal} label={"NORMAL"} isToggle={riverScale == 1} /> { setRiverScale(2); setRiverSituation("ALTO"); }} SvgImage={assets.riverLevel.High} label={"ALTO"} isToggle={riverScale == 2} /> { setRiverScale(3); setRiverSituation("TRANSBORDADO"); }} SvgImage={assets.riverLevel.Flooding} label={"TRANSBORDADO"} isToggle={riverScale == 3} /> {error && riverScale == -1 && ( Selecione o nível do rio )} {/* */} Comentário:
); } const styles = StyleSheet.create({ container: { backgroundColor: colors.white, }, imgs_row: { flexDirection: "row", justifyContent: "space-between", }, error_txt: { paddingHorizontal: 16, marginTop: 12, fontSize: 18, color: colors.danger, }, labelStyle: { paddingHorizontal: 16, paddingBottom: 12, fontSize: dimensions.text.secondary, fontWeight: "bold", textAlign: "left", color: colors.lightBlue, }, }); export default RiverFloodSharingDataScreen;