katoikia-app/mobile-ui/components/AgregarInvitados.js

126 lines
3.3 KiB
JavaScript
Raw Permalink Normal View History

2022-08-23 01:31:42 +00:00
import React, { useContext, useState } from "react";
import { API } from "../environment/api";
2022-08-19 04:30:47 +00:00
import {
2022-08-23 01:31:42 +00:00
Box, Button,
Center, FormControl, Heading, ScrollView, VStack
2022-08-19 04:30:47 +00:00
} from "native-base";
2022-08-23 01:31:42 +00:00
import { StyleSheet, TextInput } from "react-native";
import { UserContext } from "../context/UserContext";
2022-08-19 04:30:47 +00:00
2022-08-23 01:31:42 +00:00
export default function AgregarInvitados({ navigation }) {
2022-08-23 02:53:07 +00:00
const baseURL = `${API.BASE_URL}/guest/createGuest/`;
2022-08-23 01:31:42 +00:00
const [name, setName] = useState();
const [apellido, setApellido] =useState();
2022-08-23 02:53:07 +00:00
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);
2022-08-23 01:31:42 +00:00
2022-08-23 02:53:07 +00:00
const saveInvitado = async() => {
2022-08-23 01:31:42 +00:00
const data = {
"name": name,
"last_name": apellido,
2022-08-23 02:53:07 +00:00
"dni": dni,
"phone": phone,
"number_plate": number_plate,
"tenant_id": user.id,
"community_id": user.community_id
2022-08-23 01:31:42 +00:00
}
try {
2022-08-23 02:53:07 +00:00
await fetch(baseURL, {
2022-08-23 01:31:42 +00:00
cache: 'no-cache',
2022-08-23 02:53:07 +00:00
method: 'POST',
2022-08-23 01:31:42 +00:00
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
.then(response => {
if (response.status != 201){
console.log('ocurrio un error ');
}else{
return response.json();
}
})
2022-08-19 04:30:47 +00:00
2022-08-23 01:31:42 +00:00
} catch (error) {
console.log("ERROR: " + error);
}
}
return (
<Center>
<ScrollView width='100%' h='550' ml='36' _contentContainerStyle={{
px: "20px",
mb: "4",
minW: "72"
}}>
<Box safeArea p="2" w="90%" maxW="290" py="8">
<Heading size="lg" color="coolGray.800" _dark={{
color: "warmGray.50"
}} fontWeight="semibold">
Registrar invitado
</Heading>
<Heading mt="1" color="coolGray.600" _dark={{
color: "warmGray.200"
}} fontWeight="medium" size="xs">
Registre el invitado que desee
</Heading>
<VStack space={3} mt="5">
<FormControl>
<FormControl.Label>Nombre</FormControl.Label>
2022-08-23 02:53:07 +00:00
<TextInput style={styles.input} type="text" onChangeText={(value) => setName(value)}/>
2022-08-23 01:31:42 +00:00
</FormControl>
<FormControl>
<FormControl.Label>Apellido</FormControl.Label>
2022-08-23 02:53:07 +00:00
<TextInput style={styles.input} type="text" onChangeText={(value) => setApellido(value)}/>
2022-08-23 01:31:42 +00:00
</FormControl>
<FormControl>
2022-08-23 02:53:07 +00:00
<FormControl.Label>Identificación</FormControl.Label>
<TextInput style={styles.input} type="text" onChangeText={(value) => setDNI(value)}/>
2022-08-23 01:31:42 +00:00
</FormControl>
<FormControl>
2022-08-23 02:53:07 +00:00
<FormControl.Label>Teléfono</FormControl.Label>
<TextInput style={styles.input} type="text" onChangeText={(value) => setPhone(value)} />
2022-08-23 01:31:42 +00:00
</FormControl>
2022-08-23 02:53:07 +00:00
<Button mt="2" onPress={() => saveInvitado()}>
2022-08-23 01:31:42 +00:00
Guardar
</Button>
</VStack>
</Box>
</ScrollView>
</Center>
)
}
2022-08-19 04:30:47 +00:00
2022-08-23 01:31:42 +00:00
const styles = StyleSheet.create({
input: {
height: 10,
margin: 3,
borderWidth: 0.5,
padding: 5,
flex: 1,
paddingTop: 9,
paddingRight: 19,
paddingBottom: 20,
paddingLeft: 0,
marginTop: 6,
marginBottom: 6,
borderRadius: 4
}
})
2022-08-19 04:30:47 +00:00