|
|
@ -9,6 +9,7 @@ import PhoneNumberFormField from "../components/forms/PhoneNumberFormField"; |
|
|
|
import SearchablePicker from "../components/SearchablePicker"; |
|
|
|
import ConfirmationModal from "../components/ConfirmationModal"; |
|
|
|
import { loginByUsernamAnswers, existUsername } from "../api/auth"; |
|
|
|
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view"; |
|
|
|
|
|
|
|
function SecQuestionPicker({ name }) { |
|
|
|
const [items, setItems] = useState([ |
|
|
@ -67,7 +68,6 @@ const validationSchema = Yup.object().shape({ |
|
|
|
|
|
|
|
export default function PasswordRecovery({ navigation, route }) { |
|
|
|
const user = route.params.user; |
|
|
|
console.log(user) |
|
|
|
|
|
|
|
const [showLoading, setShowLoading] = useState(false); |
|
|
|
const [confirmatioModalData, setConfirmatioModalData] = useState({ |
|
|
@ -78,11 +78,11 @@ export default function PasswordRecovery({ navigation, route }) { |
|
|
|
const handleSubmit = async (number, answer, secQuestion) => { |
|
|
|
setShowLoading(true); |
|
|
|
setTimeout(() => { |
|
|
|
console.log("to rodando", showLoading) |
|
|
|
showLoading && setConfirmatioModalData({ |
|
|
|
message: "Validando informações", |
|
|
|
show: true, |
|
|
|
}); |
|
|
|
showLoading && |
|
|
|
setConfirmatioModalData({ |
|
|
|
message: "Validando informações", |
|
|
|
show: true, |
|
|
|
}); |
|
|
|
}, 2000); |
|
|
|
|
|
|
|
const userExists = await existUsername(number); |
|
|
@ -94,7 +94,7 @@ export default function PasswordRecovery({ navigation, route }) { |
|
|
|
setShowLoading(false); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const apiResponse = await loginByUsernamAnswers( |
|
|
|
number, |
|
|
|
secQuestion, |
|
|
@ -104,7 +104,6 @@ export default function PasswordRecovery({ navigation, route }) { |
|
|
|
|
|
|
|
switch (apiResponse.status) { |
|
|
|
case 200: |
|
|
|
console.log("ir pra proxima tela...."); |
|
|
|
navigation.navigate("PasswordRecoveryChangePswd", { |
|
|
|
authToken: apiResponse.data, |
|
|
|
username: number, |
|
|
@ -142,51 +141,53 @@ export default function PasswordRecovery({ navigation, route }) { |
|
|
|
} |
|
|
|
/> |
|
|
|
|
|
|
|
<Form |
|
|
|
validationSchema={validationSchema} |
|
|
|
initialValues={{ |
|
|
|
number: user.username || "", |
|
|
|
answer: "", |
|
|
|
secQuestion: "", |
|
|
|
}} |
|
|
|
onSubmit={({ number, answer, secQuestion }) => { |
|
|
|
handleSubmit(number, answer, secQuestion); |
|
|
|
}} |
|
|
|
> |
|
|
|
<View style={{ padding: 16 }}> |
|
|
|
<Text style={styles.textHeader}>Recuperação de senha</Text> |
|
|
|
<Text style={styles.textSubtitle}> |
|
|
|
Responda à pergunta de segurança, isso ajuda a mostrar que essa |
|
|
|
conta realmente pertence a você |
|
|
|
</Text> |
|
|
|
</View> |
|
|
|
|
|
|
|
<View> |
|
|
|
<Text style={styles.labelStyle}>Número de telefone*:</Text> |
|
|
|
<PhoneNumberFormField |
|
|
|
name="number" |
|
|
|
maxLength={11} |
|
|
|
placeholder={"(DDD) XXXXX-XXXX"} |
|
|
|
editable={user.username == null} |
|
|
|
/> |
|
|
|
</View> |
|
|
|
|
|
|
|
<View style={{ marginTop: 24 }}> |
|
|
|
<Text style={styles.labelStyle}>Pergunta*:</Text> |
|
|
|
<SecQuestionPicker name="secQuestion" /> |
|
|
|
</View> |
|
|
|
|
|
|
|
<View style={{ marginVertical: 24 }}> |
|
|
|
<Text style={styles.labelStyle}>Resposta*:</Text> |
|
|
|
<FormField |
|
|
|
name="answer" |
|
|
|
maxLength={255} |
|
|
|
placeholder={"Digite a resposta à pergunta"} |
|
|
|
/> |
|
|
|
</View> |
|
|
|
|
|
|
|
<SubmitButton title="próximo" backgroundColor={colors.primary} /> |
|
|
|
</Form> |
|
|
|
<KeyboardAwareScrollView> |
|
|
|
<Form |
|
|
|
validationSchema={validationSchema} |
|
|
|
initialValues={{ |
|
|
|
number: user.username || "", |
|
|
|
answer: "", |
|
|
|
secQuestion: "", |
|
|
|
}} |
|
|
|
onSubmit={({ number, answer, secQuestion }) => { |
|
|
|
handleSubmit(number, answer, secQuestion); |
|
|
|
}} |
|
|
|
> |
|
|
|
<View style={{ padding: 16 }}> |
|
|
|
<Text style={styles.textHeader}>Recuperação de senha</Text> |
|
|
|
<Text style={styles.textSubtitle}> |
|
|
|
Responda à pergunta de segurança, isso ajuda a mostrar que essa |
|
|
|
conta realmente pertence a você |
|
|
|
</Text> |
|
|
|
</View> |
|
|
|
|
|
|
|
<View> |
|
|
|
<Text style={styles.labelStyle}>Número de telefone*:</Text> |
|
|
|
<PhoneNumberFormField |
|
|
|
name="number" |
|
|
|
maxLength={11} |
|
|
|
placeholder={"(DDD) XXXXX-XXXX"} |
|
|
|
editable={user.username == null} |
|
|
|
/> |
|
|
|
</View> |
|
|
|
|
|
|
|
<View style={{ marginTop: 24 }}> |
|
|
|
<Text style={styles.labelStyle}>Pergunta*:</Text> |
|
|
|
<SecQuestionPicker name="secQuestion" /> |
|
|
|
</View> |
|
|
|
|
|
|
|
<View style={{ marginVertical: 24 }}> |
|
|
|
<Text style={styles.labelStyle}>Resposta*:</Text> |
|
|
|
<FormField |
|
|
|
name="answer" |
|
|
|
maxLength={255} |
|
|
|
placeholder={"Digite a resposta à pergunta"} |
|
|
|
/> |
|
|
|
</View> |
|
|
|
|
|
|
|
<SubmitButton title="próximo" backgroundColor={colors.primary} /> |
|
|
|
</Form> |
|
|
|
</KeyboardAwareScrollView> |
|
|
|
</View> |
|
|
|
); |
|
|
|
} |
|
|
|