|
|
@ -8,7 +8,7 @@ import { dimensions } from "../config/dimensions"; |
|
|
|
import PhoneNumberFormField from "../components/forms/PhoneNumberFormField"; |
|
|
|
import SearchablePicker from "../components/SearchablePicker"; |
|
|
|
import ConfirmationModal from "../components/ConfirmationModal"; |
|
|
|
import {loginByUsernamAnswers} from "../api/auth"; |
|
|
|
import { loginByUsernamAnswers, existUsername } from "../api/auth"; |
|
|
|
|
|
|
|
function SecQuestionPicker({ name }) { |
|
|
|
const [items, setItems] = useState([ |
|
|
@ -66,29 +66,50 @@ const validationSchema = Yup.object().shape({ |
|
|
|
}); |
|
|
|
|
|
|
|
export default function PasswordRecovery({ navigation }) { |
|
|
|
const [showLoading, setShowLoading] = useState(false); |
|
|
|
const [confirmatioModalData, setConfirmatioModalData] = useState({ |
|
|
|
show: false, |
|
|
|
message: "", |
|
|
|
}); |
|
|
|
|
|
|
|
const handleSubmit = async (number, answer, secQuestion) => { |
|
|
|
setConfirmatioModalData({ |
|
|
|
message: "Validando informações", |
|
|
|
show: true, |
|
|
|
}); |
|
|
|
const apiResponse = await loginByUsernamAnswers(number, secQuestion, answer); |
|
|
|
setShowLoading(true); |
|
|
|
setTimeout(() => { |
|
|
|
console.log("to rodando", showLoading) |
|
|
|
showLoading && setConfirmatioModalData({ |
|
|
|
message: "Validando informações", |
|
|
|
show: true, |
|
|
|
}); |
|
|
|
}, 2000); |
|
|
|
|
|
|
|
const userExists = await existUsername(number); |
|
|
|
if (userExists.data == null) { |
|
|
|
setConfirmatioModalData({ |
|
|
|
message: "Número de telefone inválido", |
|
|
|
show: true, |
|
|
|
}); |
|
|
|
setShowLoading(false); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const apiResponse = await loginByUsernamAnswers( |
|
|
|
number, |
|
|
|
secQuestion, |
|
|
|
answer |
|
|
|
); |
|
|
|
setShowLoading(false); |
|
|
|
|
|
|
|
switch (apiResponse.status) { |
|
|
|
case 200: |
|
|
|
console.log("ir pra proxima tela...."); |
|
|
|
navigation.navigate("PasswordRecoveryChangePswd", { |
|
|
|
authToken: apiResponse.data, |
|
|
|
username: number |
|
|
|
username: number, |
|
|
|
}); |
|
|
|
break; |
|
|
|
case 404: |
|
|
|
setConfirmatioModalData({ |
|
|
|
message: "Número de telefone inválido", |
|
|
|
message: "Pergunta de segurança ou senha incorretos", |
|
|
|
show: true, |
|
|
|
}); |
|
|
|
break; |
|
|
@ -125,8 +146,7 @@ export default function PasswordRecovery({ navigation }) { |
|
|
|
answer: "", |
|
|
|
secQuestion: "", |
|
|
|
}} |
|
|
|
onSubmit={({number, answer, secQuestion}) => { |
|
|
|
|
|
|
|
onSubmit={({ number, answer, secQuestion }) => { |
|
|
|
handleSubmit(number, answer, secQuestion); |
|
|
|
}} |
|
|
|
> |
|
|
|