import React, { useContext, useState } from "react"; import { API } from "../environment/api"; import { Box, Button, Center, FormControl, Heading, ScrollView, VStack } from "native-base"; import { Dimensions, StyleSheet, TextInput, useWindowDimensions } from "react-native"; import { UserContext } from "../context/UserContext"; import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs'; import { stringMd5 } from 'react-native-quick-md5'; const { Navigator, Screen } = createMaterialTopTabNavigator(); export default function Profile({ navigation }) { const baseURL = `${API.BASE_URL}/user/updateUser/` const [index, setIndex] = useState(0); const layout = useWindowDimensions(); const userData = useContext(UserContext) const [name, setName] = useState(userData.user.name); const [apellido, setApellido] =useState(userData.user.last_name); const [email, setEmail] = useState(userData.user.email); const [password, setPassword] = useState(); const id = userData.user._id; const decode = userData.Password; const [error, setError] = useState({}) console.log(userData.user); const onHandleChangePassword = (value) => { //console.log(value); const dpassword = stringMd5(value) console.log(dpassword); console.log(userData.user.password); if (userData.user.password == dpassword) { console.log(true); setError({}); }else{ console.log(false); setError({ ...error, password: 'La contraseña no coincide con la actual' }); } } const ProfileView = () => ( Bienvenido {userData.user.name} Modifique sus datos DNI {/* Teléfono */} Nombre setName(value) }/> Apellido setApellido(value) } /> Correo electrónico setEmail(value) }/> ) const PasswordView = () => ( Bienvenido {userData.user.name} Modifique sus contraseña Contraseña actual onHandleChangePassword(value) }/> Nueva Contraseña setPassword(value) } /> Confirmar nueva contraseña setPassword(value) }/> {/* {'password' in error && La contraseña no coincide con la actual } */} ) const updatePassword = async() =>{ const dataPassword = { "_id": userData.user._id, "dni": userData.user.dni, "name": userData.user.name, "last_name": userData.user.last_name, "email": userData.user.email, "phone": userData.user.phone, "password": password, "user_type": userData.user.user_type, "status": userData.user.status, "date_entry": userData.user.date_entry, "community_id": userData.user.community_id, } try { await fetch(baseURL+`${id}`, { cache: 'no-cache', method: 'PUT', body: JSON.stringify(dataPassword), headers: { 'Content-Type': 'application/json' } }) .then(response => { // console.log(baseURL+`${id}`); if (response.status != 201 && response.status != 200){ console.log('ocurrio un error ' + response); }else{ return response.json(); } }) } catch (error) { console.log("ERROR: " + error); } } const updateInfo = async() => { const data = { "_id": userData.user._id, "dni": userData.user.dni, "name": name, "last_name": apellido, "email": email, "phone": userData.user.phone, "password": userData.user.password, "user_type": userData.user.user_type, "status": userData.user.status, "date_entry": userData.user.date_entry, "community_id": userData.user.community_id, "number_house": '20' } console.log(data); try { await fetch(baseURL+`${id}`, { cache: 'no-cache', method: 'PUT', body: JSON.stringify(data), headers: { 'Content-Type': 'application/json' } }) .then(response => { //console.log(baseURL+`${id}`); if (response.status != 201){ // console.log('ocurrio un error '); console.log(response.json()); }else{ return response.json(); } }) } catch (error) { console.log("ERROR: " + error); } } return ( ) } const styles = StyleSheet.create({ input: { height: 35, margin: 3, borderWidth: 0.5, padding: 5, flex: 1, paddingTop: 9, paddingRight: 19, paddingLeft: 0, marginTop: 6, borderRadius: 4 }, errorMessage: { height: 35, margin: 3, borderWidth: 0.5, padding: 5, flex: 1, paddingTop: 9, paddingRight: 19, paddingLeft: 0, marginTop: 6, borderRadius: 4, borderColor: '#be123c' } })