Browse Source

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

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

40
src/app/screens/PasswordRecoveryScreen.js

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

Loading…
Cancel
Save