import React, { useContext, useState } from "react"; import { API } from "../environment/api"; import { MaterialCommunityIcons } from '@expo/vector-icons'; import { Box, Button, Center, FormControl, Heading, ScrollView, VStack,Select } from "native-base"; import { StyleSheet, TextInput } from "react-native"; import { UserContext } from "../context/UserContext"; export default function AgregarInvitados({ navigation }) { const baseURL = `${API.BASE_URL}/guest/createGuest/`; const [name, setName] = useState(); const [apellido, setApellido] =useState(); const [dni, setDNI] = useState(); const [phone, setPhone] = useState(); const [number_plate, setNumber_plate] = useState(); const [tenant_id, setTenant_id] = useState(); const [community_id, setCommunity_id] = useState(); const { user } = useContext(UserContext); const [errors, setErrors] = useState({}); const [categoria, setCategoria] = React.useState(""); const [info, setInfo] = useState({ name: "", last_name: "", dni: "", phone: "", number_plate:"", status: "1", tenant_id: user._id, //tenant_id: "6301df20dac7dcf76dcecade", community_id: user.community_id, //community_id: "62be68215692582bbfd77134", type_guest:"" }); const onHandleChange = (name) => (value) => setInfo(prev => ({...prev, [name]: value})) const validate = async() => { if( info.name === "" && info.last_name === "" && info.dni === "" && info.phone === ""){ setErrors({ ...errors, name: 'Debe ingresar un nombre', last_name: 'Debe ingresar un apellido', dni: 'Debe ingresar un número de identificación', phone: 'Debe ingresar un número de teléfono' }); return false; }else if (info.name === "" ) { setErrors({ ...errors, name: 'Debe ingresar un nombre' }); return false; } else if(info.last_name === ""){ setErrors({ ...errors, last_name: 'Debe ingresar un apellido' }); return false; }else if (info.dni === "") { setErrors({ ...errors, dni: 'Debe ingresar un número de identificación' }); return false; }else if (info.phone === "") { setErrors({ ...errors, phone: 'Debe ingresar un número de teléfono' }); return false; } return true; } const saveInvitado = async() => { const error = await validate(); if (error) { try { await fetch(baseURL, { cache: 'no-cache', method: 'POST', body: JSON.stringify(info), headers: { 'Content-Type': 'application/json' } }) .then(response => { if (response.status != 201){ console.log('ocurrio un error '); }else{ navigation.navigate('Inicio'); return response.json(); } }) } catch (error) { console.log("ERROR: " + error); } } } return (