|
|
@ -8,7 +8,8 @@ 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"; |
|
|
|
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"; |
|
|
|
|
|
|
|
function SecQuestionPicker({ name }) { |
|
|
|
const [items, setItems] = useState([ |
|
|
@ -65,30 +66,52 @@ const validationSchema = Yup.object().shape({ |
|
|
|
.max(255), |
|
|
|
}); |
|
|
|
|
|
|
|
export default function PasswordRecovery({ navigation }) { |
|
|
|
export default function PasswordRecovery({ navigation, route }) { |
|
|
|
const user = route.params.user; |
|
|
|
|
|
|
|
const [showLoading, setShowLoading] = useState(false); |
|
|
|
const [confirmatioModalData, setConfirmatioModalData] = useState({ |
|
|
|
show: false, |
|
|
|
message: "", |
|
|
|
}); |
|
|
|
|
|
|
|
const handleSubmit = async (number, answer, secQuestion) => { |
|
|
|
setShowLoading(true); |
|
|
|
setTimeout(() => { |
|
|
|
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; |
|
|
@ -118,15 +141,15 @@ export default function PasswordRecovery({ navigation }) { |
|
|
|
} |
|
|
|
/> |
|
|
|
|
|
|
|
<KeyboardAwareScrollView> |
|
|
|
<Form |
|
|
|
validationSchema={validationSchema} |
|
|
|
initialValues={{ |
|
|
|
number: "", |
|
|
|
number: user.username || "", |
|
|
|
answer: "", |
|
|
|
secQuestion: "", |
|
|
|
}} |
|
|
|
onSubmit={({number, answer, secQuestion}) => { |
|
|
|
|
|
|
|
onSubmit={({ number, answer, secQuestion }) => { |
|
|
|
handleSubmit(number, answer, secQuestion); |
|
|
|
}} |
|
|
|
> |
|
|
@ -143,7 +166,8 @@ export default function PasswordRecovery({ navigation }) { |
|
|
|
<PhoneNumberFormField |
|
|
|
name="number" |
|
|
|
maxLength={11} |
|
|
|
placeholder="(DDD) XXXXX-XXXX" |
|
|
|
placeholder={"(DDD) XXXXX-XXXX"} |
|
|
|
editable={user.username == null} |
|
|
|
/> |
|
|
|
</View> |
|
|
|
|
|
|
@ -163,6 +187,7 @@ export default function PasswordRecovery({ navigation }) { |
|
|
|
|
|
|
|
<SubmitButton title="próximo" backgroundColor={colors.primary} /> |
|
|
|
</Form> |
|
|
|
</KeyboardAwareScrollView> |
|
|
|
</View> |
|
|
|
); |
|
|
|
} |
|
|
|