Skip to content

Commit 6b19ad0

Browse files
committed
Mexendo na Home Page, dados variaveis dependendo do estado selecionado, Estilização dados cadastrais, exclusão de conta junto com seus respectivos dados, UX no registro
1 parent f75400c commit 6b19ad0

8 files changed

+256
-118
lines changed

app/(app)/ChangeRegisterData.tsx

Lines changed: 69 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { View, Text, TextInput, TouchableOpacity } from "react-native";
2-
import { Button } from "react-native-paper";
1+
import { View, Text, Linking } from "react-native";
2+
import { TextInput, Button, ActivityIndicator, MD2Colors } from "react-native-paper";
33
import { useEffect, useState } from "react";
44
import * as SecureStore from 'expo-secure-store';
55
import axiosInstance from "../server/axios";
@@ -10,6 +10,9 @@ import { router } from "expo-router";
1010
export default function ChangeRegisterData(){
1111
const { signOut } = useSession();
1212

13+
const [loading, setLoading] = useState(false);
14+
const [loading2, setLoading2] = useState(false);
15+
1316
const getName = async () => {
1417
const token = await SecureStore.getItemAsync('session');
1518
console.log(token);
@@ -41,75 +44,81 @@ export default function ChangeRegisterData(){
4144
const [confirmarNovaSenha, setConfirmarNovaSenha] = useState("");
4245

4346
const changeRegisterData = async () => {
44-
const token = await SecureStore.getItemAsync('session');
45-
const config = {
46-
headers: {
47-
Authorization: "Bearer " + token
47+
setLoading(true);
48+
try{
49+
const token = await SecureStore.getItemAsync('session');
50+
const config = {
51+
headers: {
52+
Authorization: "Bearer " + token
53+
}
4854
}
49-
}
50-
const requestData = {
51-
name: nomeNovo,
52-
email: emailNovo,
53-
senhaAntiga: senhaAntiga,
54-
senhaNova: novaSenha,
55-
}
56-
if(emailNovo || emailNovo != ""){
57-
await axiosInstance.patch("/api/users/patch/" + id, requestData, config)
58-
router.push({
59-
pathname: "/EmailChangeVerification",
60-
params: {
61-
newEmail: emailNovo
55+
const requestData = {
56+
name: nomeNovo,
57+
email: emailNovo,
58+
senhaAntiga: senhaAntiga,
59+
senhaNova: novaSenha,
60+
}
61+
if(emailNovo || emailNovo != ""){
62+
await axiosInstance.patch("/api/users/patch/" + id, requestData, config)
63+
router.push({
64+
pathname: "/EmailChangeVerification",
65+
params: {
66+
newEmail: emailNovo
67+
}
68+
});
69+
}else{
70+
if(novaSenha != confirmarNovaSenha){
71+
alert("As senhas não coincidem!")
72+
} if(nomeNovo == "" || emailNovo == "" || senhaAntiga == "" || novaSenha == "" || confirmarNovaSenha == ""){
73+
alert("Preencha algum campos!")
6274
}
63-
});
64-
} else{
65-
if(novaSenha != confirmarNovaSenha){
66-
alert("As senhas não coincidem!")
67-
} else{
68-
if(nomeNovo){
69-
await axiosInstance.patch("/api/users/patch/" + id, requestData, config).then((response) => {
70-
alert("Dados alterados com sucesso!")
71-
signOut()
72-
}).catch((error) => {
73-
console.log(error)
74-
})
75-
} if(!nomeNovo){
75+
else{
76+
if(nomeNovo){
7677
await axiosInstance.patch("/api/users/patch/" + id, requestData, config).then((response) => {
77-
if(response.status == 500){
78-
alert("Senha antiga incorreta!")
79-
} else{
80-
alert("Dados alterados com sucesso!")
81-
signOut()
82-
}
78+
alert("Dados alterados com sucesso!")
79+
signOut()
8380
}).catch((error) => {
84-
if(error.response.status == 500){
85-
alert("Senha antiga incorreta!")
86-
}
81+
console.log(error)
8782
})
83+
} if(!nomeNovo){
84+
await axiosInstance.patch("/api/users/patch/" + id, requestData, config).then((response) => {
85+
if(response.status == 500){
86+
alert("Senha antiga incorreta!")
87+
} else{
88+
alert("Dados alterados com sucesso!")
89+
signOut()
90+
}
91+
}).catch((error) => {
92+
if(error.response.status == 500){
93+
alert("Senha antiga incorreta!")
94+
}
95+
})
96+
}
8897
}
8998
}
99+
} catch(error){
100+
console.log(error)
101+
} finally{
102+
setLoading(false);
90103
}
91104
}
92105

93106
return(
94-
<View className="pt-12 h-full bg-white">
95-
<Text>Nome: {nome}</Text>
96-
<TextInput className="border-2 border-gray-500 rounded-lg w-60 h-10" value={nomeNovo} onChangeText={setNomeNovo}></TextInput>
97-
<Text>Email: {email}</Text>
98-
<TextInput className="border-2 border-gray-500 rounded-lg w-60 h-10" value={emailNovo} onChangeText={setEmailNovo}></TextInput>
99-
<Text>Senha antiga</Text>
100-
<TextInput value={senhaAntiga} onChangeText={setSenhaAntiga} className="border-2 border-gray-500 rounded-lg w-60 h-10"></TextInput>
101-
<Text>Nova senha</Text>
102-
<TextInput value={novaSenha} onChangeText={setNovaSenha} className="border-2 border-gray-500 rounded-lg w-60 h-10"></TextInput>
103-
<Text>Confirmar nova senha</Text>
104-
<TextInput value={confirmarNovaSenha} onChangeText={setConfirmarNovaSenha} className="border-2 border-gray-500 rounded-lg w-60 h-10"></TextInput>
105-
<TouchableOpacity onPress={changeRegisterData} className="bg-blue-500 p-3 rounded-lg w-60">
106-
<Text className="text-center">Alterar dados</Text>
107-
</TouchableOpacity>
108-
<TouchableOpacity className="bg-red-500 p-3 rounded-lg w-60">
109-
<Text className="text-center">Excluir conta</Text>
110-
</TouchableOpacity>
111-
<Text>Ao alterar o E-mail, use apenas E-mails que consigam ser acessados, para fazer uma nova verificação.</Text>
112-
<Text>Em caso de problemas, contate o suporte: mercadobmxbr@gmail.com</Text>
107+
<View className="pt-12 h-full bg-white flex justify-center items-center">
108+
<Text className="mb-4 text-3xl">Alteração de cadastro</Text>
109+
<TextInput label={"Nome atual: " + nome} mode="outlined" className="text-black text-sm w-80 h-10 mb-2" value={nomeNovo} onChangeText={setNomeNovo}></TextInput>
110+
<TextInput label={"Email atual: " + email} mode="outlined" className="text-black text-sm w-80 h-10 mb-2" value={emailNovo} onChangeText={setEmailNovo}></TextInput>
111+
<TextInput label="Senha antiga" mode="outlined" value={senhaAntiga} onChangeText={setSenhaAntiga} className="text-black text-sm w-80 h-10 mb-2"></TextInput>
112+
<TextInput label="Nova senha" mode="outlined" value={novaSenha} onChangeText={setNovaSenha} className="text-black text-sm w-80 h-10 mb-2"></TextInput>
113+
<TextInput label="Confirmar nova senha" mode="outlined" value={confirmarNovaSenha} onChangeText={setConfirmarNovaSenha} className="text-black text-sm w-80 h-10"></TextInput>
114+
<View className="flex gap-2 my-4">
115+
{loading ? <ActivityIndicator animating={true} color={MD2Colors.green500} size={40}/> : <Button onPress={changeRegisterData} mode='contained' className="bg-green-500 w-40">Alterar Dados</Button>}
116+
<Button onPress={()=>{router.push({
117+
pathname: "/DeleteAccount"
118+
})}} mode='contained' className="bg-red-500 w-40">Excluir conta</Button>
119+
</View>
120+
<Text>Em caso de problemas, contate o suporte</Text>
121+
<Text className="text-purple-700" onPress={()=>{Linking.openURL("mailto:mercadobmxbr@gmail.com?subject=Suporte")}}>mercadobmxbr@gmail.com</Text>
113122
<BottomBar screen="MenuScreen"></BottomBar>
114123
</View>
115124
)

app/(app)/DeleteAccount.tsx

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import { useEffect, useState } from "react";
2+
import { View, Text } from "react-native";
3+
import { Button, TextInput } from "react-native-paper";
4+
import BottomBar from "../components/BottomBar";
5+
import * as SecureStore from 'expo-secure-store';
6+
import axiosInstance from "../server/axios";
7+
import { router } from "expo-router";
8+
9+
export default function DeleteAccount(){
10+
11+
const getName = async () => {
12+
const token = await SecureStore.getItemAsync('session');
13+
console.log(token);
14+
const config = {
15+
headers: {
16+
Authorization: "Bearer " + token
17+
}
18+
}
19+
const response = await axiosInstance.get("/api/token/jwtDecode", config)
20+
console.log(response.data);
21+
setId(response.data.jti);
22+
}
23+
24+
const [id, setId] = useState("");
25+
const [code, setCode] = useState("");
26+
const [password, setPassword] = useState("");
27+
28+
const [modal, setModal] = useState(false);
29+
const [randomCode, setRandomCode] = useState("");
30+
31+
const generateCode = () => {
32+
const randomNumber = Math.floor(Math.random() * 10000);
33+
const randomCodeString = randomNumber.toString().padStart(4, '0');
34+
setRandomCode(randomCodeString);
35+
}
36+
37+
const deleteUser = async() => {
38+
if(code != randomCode){
39+
alert("Código incorreto!");
40+
const randomNumber = Math.floor(Math.random() * 10000);
41+
const randomCodeString = randomNumber.toString().padStart(4, '0');
42+
setRandomCode(randomCodeString);
43+
} else{
44+
const token = await SecureStore.getItemAsync('session');
45+
const config = {
46+
headers: {
47+
Authorization: "Bearer " + token
48+
}
49+
}
50+
await axiosInstance.post("/api/users/delete/" + id, {password: password}, config).then((response) => {
51+
if(response.data == "Senha errada!"){
52+
alert("Senha incorreta. Tente novamente!");
53+
const randomNumber = Math.floor(Math.random() * 10000);
54+
const randomCodeString = randomNumber.toString().padStart(4, '0');
55+
setRandomCode(randomCodeString);
56+
} else {
57+
alert("Conta deletada com sucesso!");
58+
SecureStore.deleteItemAsync('session');
59+
router.push({
60+
pathname: "/LoginScreen",
61+
})
62+
}
63+
})
64+
}
65+
}
66+
67+
useEffect(()=>{
68+
generateCode();
69+
getName();
70+
}, [])
71+
72+
73+
74+
return(
75+
<View className="h-full bg-white flex justify-center items-center">
76+
<Text>Deseja realmente excluir sua conta?</Text>
77+
<Text>Com isso, excluirá também permanentemente seus anúncios e favoritos.</Text>
78+
<View className="flex flex-row">
79+
<Button onPress={()=>{setModal(true)}}>Sim</Button>
80+
<Button onPress={()=>{setModal(false)}}>Não</Button>
81+
</View>
82+
{modal &&
83+
<View>
84+
<Text>Insira o código abaixo e sua senha atual para confirmar</Text>
85+
<Text className="text-purple-700">{randomCode}</Text>
86+
<TextInput value={code} onChangeText={setCode} label="Código" mode="outlined"></TextInput>
87+
<TextInput value={password} onChangeText={setPassword} label="Senha" mode="outlined"></TextInput>
88+
<Button onPress={deleteUser}>Deletar</Button>
89+
</View>
90+
}
91+
<BottomBar screen="MenuScreen"></BottomBar>
92+
</View>
93+
)
94+
}

app/(app)/EmailChangeVerification.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { router, useLocalSearchParams } from "expo-router";
22
import { useState } from "react";
3-
import { Button, TextInput } from "react-native-paper";
3+
import { Button, TextInput, ActivityIndicator, MD2Colors } from "react-native-paper";
44
import { View, Text } from "react-native";
55
import axiosInstance from "../server/axios";
66
import * as SecureStore from 'expo-secure-store';
77
import { useSession } from "../../auth/ctx";
8+
import BottomBar from "../components/BottomBar";
89

910
export default function EmailChangeVerification(){
1011

@@ -67,13 +68,13 @@ export default function EmailChangeVerification(){
6768

6869

6970
return(
70-
<View className="mt-12">
71-
<Text>{newEmail}</Text>
72-
<Text>Verificação de E-mail</Text>
73-
<Text>Insira o código recebido no seu e-mail</Text>
74-
<TextInput label="Código" value={code} onChangeText={setCode} />
75-
<Button className="bg-purple-300" onPress={sendEmailCode}>Enviar código</Button>
76-
<Button className="bg-green-300 mt-10" onPress={activateAccount}>Ativar conta</Button>
71+
<View className="h-full bg-white flex justify-center items-center">
72+
<Text>Verifique seu email: <Text className="text-purple-700">{newEmail}</Text></Text>
73+
<Text className="mt-2">Insira o <Text className="text-green-500">código</Text> recebido abaixo</Text>
74+
<TextInput className="w-60 my-4" maxLength={6} label="Código" mode="outlined" value={code} onChangeText={setCode} />
75+
{loading ? <ActivityIndicator animating={true} color={MD2Colors.green500} size={40}/> : <Button mode='contained' className="bg-green-500 w-40" onPress={sendEmailCode}>Enviar código</Button>}
76+
{loading2 ? <ActivityIndicator className="mt-2" animating={true} color={MD2Colors.purpleA700} size={40}/> : <Button mode='contained' className="bg-purple-500 w-40 mt-2" onPress={activateAccount}>Ativar conta</Button>}
77+
<BottomBar screen="MenuScreen"></BottomBar>
7778
</View>
7879
)
7980
}

app/(app)/FormAdScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ export default function FormAdScreen(){
697697
<Text className="text-lg">Marca <Text className="text-red-600">*</Text></Text>
698698
<View className="border bg-purple-100 border-black rounded-md mb-6">
699699
<Picker selectedValue={marca} onValueChange={setMarca}>
700-
<Picker.Item label="Selecione uma opção" value={null}></Picker.Item>
700+
<Picker.Item label="Selecione uma opção" value={null}></Picker.Item>
701701
<Picker.Item label="OUTRA MARCA" value="OUTRA MARCA" />
702702
<Picker.Item label="Animal" value="Animal" />
703703
<Picker.Item label="BSD" value="BSD" />

0 commit comments

Comments
 (0)