Browse Source

setting timer to loading message in change password and fixing error messages

master
GabrielTrettel 3 years ago
parent
commit
afb611a7b5
  1. 34
      src/app/screens/PasswordRecoveryScreen.js

34
src/app/screens/PasswordRecoveryScreen.js

@ -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({
setShowLoading(true);
setTimeout(() => {
console.log("to rodando", showLoading)
showLoading && setConfirmatioModalData({
message: "Validando informações",
show: true,
});
const apiResponse = await loginByUsernamAnswers(number, secQuestion, answer);
}, 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);
}}
>

Loading…
Cancel
Save