fix profile
This commit is contained in:
parent
32a2df0f60
commit
4426981d24
|
@ -1,22 +1,19 @@
|
||||||
import React, { useContext, useState } from "react";
|
import React, { useContext, useState } from "react";
|
||||||
import { API } from "../environment/api";
|
import { API } from "../environment/api";
|
||||||
import {
|
import {
|
||||||
Box, Button,
|
Box, Button, FormControl, Heading, ScrollView, VStack
|
||||||
Center, FormControl, Heading, ScrollView, VStack
|
|
||||||
} from "native-base";
|
} from "native-base";
|
||||||
import { StyleSheet, TextInput, useWindowDimensions } from "react-native";
|
import { StyleSheet, TextInput} from "react-native";
|
||||||
import { UserContext } from "../context/UserContext";
|
import { UserContext } from "../context/UserContext";
|
||||||
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
|
||||||
import { stringMd5 } from 'react-native-quick-md5';
|
import { stringMd5 } from 'react-native-quick-md5';
|
||||||
|
|
||||||
|
|
||||||
const { Navigator, Screen } = createMaterialTopTabNavigator();
|
const { Navigator, Screen } = createMaterialTopTabNavigator();
|
||||||
|
|
||||||
export default function Profile({ navigation }) {
|
export default function Profile({ navigation }) {
|
||||||
|
|
||||||
const baseURL = `${API.BASE_URL}/user/updateUser/`
|
const baseURL = `${API.BASE_URL}/user/updateUser/`
|
||||||
const [index, setIndex] = useState(0);
|
|
||||||
const layout = useWindowDimensions();
|
|
||||||
const userData = useContext(UserContext)
|
const userData = useContext(UserContext)
|
||||||
const [name, setName] = useState(userData.user.name);
|
const [name, setName] = useState(userData.user.name);
|
||||||
const [apellido, setApellido] =useState(userData.user.last_name);
|
const [apellido, setApellido] =useState(userData.user.last_name);
|
||||||
|
@ -29,6 +26,26 @@ export default function Profile({ navigation }) {
|
||||||
|
|
||||||
console.log(userData.user);
|
console.log(userData.user);
|
||||||
|
|
||||||
|
|
||||||
|
const [info, setInfo] = useState({
|
||||||
|
_id: userData.user._id,
|
||||||
|
dni: userData.user.dni,
|
||||||
|
name: "",
|
||||||
|
last_name: "",
|
||||||
|
email: "",
|
||||||
|
community_id: userData.user.community_id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [infoPassword, setInfoPassword] = useState({
|
||||||
|
_id: userData.user._id,
|
||||||
|
dni: userData.user.dni,
|
||||||
|
password: ""
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const onHandleChange = (name) => (value) => setInfo(prev => ({...prev, [name]: value}))
|
||||||
|
|
||||||
const onHandleChangePassword = (value) => {
|
const onHandleChangePassword = (value) => {
|
||||||
//console.log(value);
|
//console.log(value);
|
||||||
const dpassword = stringMd5(value)
|
const dpassword = stringMd5(value)
|
||||||
|
@ -77,20 +94,20 @@ export default function Profile({ navigation }) {
|
||||||
</FormControl> */}
|
</FormControl> */}
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<FormControl.Label>Nombre</FormControl.Label>
|
<FormControl.Label>Nombre</FormControl.Label>
|
||||||
<TextInput style={styles.input} type="text" defaultValue={userData.user.name} onChangeText={(value) => setName(value) }/>
|
<TextInput style={styles.input} type="text" defaultValue={userData.user.name} onChangeText={onHandleChange("name")}/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<FormControl.Label>Apellido</FormControl.Label>
|
<FormControl.Label>Apellido</FormControl.Label>
|
||||||
<TextInput style={styles.input} type="text" defaultValue={userData.user.last_name} onChangeText={(value) => setApellido(value) } />
|
<TextInput style={styles.input} type="text" defaultValue={userData.user.last_name} onChangeText={onHandleChange("last_name") } />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<FormControl.Label>Correo electrónico</FormControl.Label>
|
<FormControl.Label>Correo electrónico</FormControl.Label>
|
||||||
<TextInput style={styles.input} type="text" defaultValue={userData.user.email} onChangeText={(value) => setEmail(value) }/>
|
<TextInput style={styles.input} type="text" defaultValue={userData.user.email} onChangeText={onHandleChange("email") }/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<Button mt="2" backgroundColor="orange.300" onPress={() => updateInfo()}>
|
<Button mt="2" backgroundColor="orange.300" onPress={() => updateInfo()}>
|
||||||
Actualizar
|
Actualizar
|
||||||
</Button>
|
</Button>
|
||||||
<Button mt="6" colorScheme="error" onPress={() => navigation.navigate('Inicio')}>
|
<Button mt="6" colorScheme="error" onPress={() => navigation.navigate('Iniciar Sesión')}>
|
||||||
Cerrar sesión
|
Cerrar sesión
|
||||||
</Button>
|
</Button>
|
||||||
</VStack>
|
</VStack>
|
||||||
|
@ -214,7 +231,7 @@ export default function Profile({ navigation }) {
|
||||||
|
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(info),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
@ -258,11 +275,7 @@ const styles = StyleSheet.create({
|
||||||
height: 35,
|
height: 35,
|
||||||
margin: 3,
|
margin: 3,
|
||||||
borderWidth: 0.5,
|
borderWidth: 0.5,
|
||||||
padding: 5,
|
|
||||||
flex: 1,
|
flex: 1,
|
||||||
paddingTop: 9,
|
|
||||||
paddingRight: 19,
|
|
||||||
paddingLeft: 0,
|
|
||||||
marginTop: 6,
|
marginTop: 6,
|
||||||
borderRadius: 4
|
borderRadius: 4
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue