|
@ -1,4 +1,4 @@ |
|
|
import React from "react"; |
|
|
|
|
|
|
|
|
import React, { useState } from "react"; |
|
|
import { StyleSheet, View, Text } from "react-native"; |
|
|
import { StyleSheet, View, Text } from "react-native"; |
|
|
import * as Yup from "yup"; |
|
|
import * as Yup from "yup"; |
|
|
|
|
|
|
|
@ -6,6 +6,7 @@ import { Form, SubmitButton } from "../components/forms"; |
|
|
import colors from "../config/colors"; |
|
|
import colors from "../config/colors"; |
|
|
import { dimensions } from "../config/dimensions"; |
|
|
import { dimensions } from "../config/dimensions"; |
|
|
import PasswordFormField from "../components/forms/PasswordFormField"; |
|
|
import PasswordFormField from "../components/forms/PasswordFormField"; |
|
|
|
|
|
import ConfirmationModal from "../components/ConfirmationModal"; |
|
|
|
|
|
|
|
|
const validationSchema = Yup.object().shape({ |
|
|
const validationSchema = Yup.object().shape({ |
|
|
password: Yup.string() |
|
|
password: Yup.string() |
|
@ -18,13 +19,58 @@ const validationSchema = Yup.object().shape({ |
|
|
.matches(/[a-zA-Z]/, "A senha só pode conter letras"), |
|
|
.matches(/[a-zA-Z]/, "A senha só pode conter letras"), |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
export default function PasswordRecoveryChangePswd() { |
|
|
|
|
|
|
|
|
export default function PasswordRecoveryChangePswd({ route }) { |
|
|
|
|
|
const authToken = route.params.authToken; |
|
|
|
|
|
console.log(authToken); |
|
|
|
|
|
|
|
|
|
|
|
const [confirmatioModalData, setConfirmatioModalData] = useState({ |
|
|
|
|
|
show: false, |
|
|
|
|
|
message: "", |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
const comparePassword = (password, confirmPassword) => { |
|
|
const comparePassword = (password, confirmPassword) => { |
|
|
return password !== confirmPassword; |
|
|
return password !== confirmPassword; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handleApiReturn = (apiReturn) => { |
|
|
|
|
|
console.log(apiReturn); |
|
|
|
|
|
switch (apiReturn) { |
|
|
|
|
|
case 200: |
|
|
|
|
|
setConfirmatioModalData({ |
|
|
|
|
|
message: "Senha alterada com sucesso", |
|
|
|
|
|
show: true, |
|
|
|
|
|
}); |
|
|
|
|
|
break; |
|
|
|
|
|
case 404: |
|
|
|
|
|
setConfirmatioModalData({ |
|
|
|
|
|
message: "Número de telefone inválido", |
|
|
|
|
|
show: true, |
|
|
|
|
|
}); |
|
|
|
|
|
break; |
|
|
|
|
|
case 500: |
|
|
|
|
|
case 403: |
|
|
|
|
|
console.log("EXPIRED TOKEN"); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
setConfirmatioModalData({ |
|
|
|
|
|
message: "Algo deu errado, tente novamente mais tarde", |
|
|
|
|
|
show: true, |
|
|
|
|
|
}); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<View> |
|
|
<View> |
|
|
|
|
|
<ConfirmationModal |
|
|
|
|
|
show={confirmatioModalData.show} |
|
|
|
|
|
description={confirmatioModalData.message} |
|
|
|
|
|
confirmationLabel="OK" |
|
|
|
|
|
onConfirm={() => |
|
|
|
|
|
setConfirmatioModalData({ ...confirmatioModalData, show: false }) |
|
|
|
|
|
} |
|
|
|
|
|
/> |
|
|
|
|
|
|
|
|
<Form |
|
|
<Form |
|
|
validationSchema={validationSchema} |
|
|
validationSchema={validationSchema} |
|
|
initialValues={{ |
|
|
initialValues={{ |
|
@ -32,17 +78,21 @@ export default function PasswordRecoveryChangePswd() { |
|
|
confirmPassword: "", |
|
|
confirmPassword: "", |
|
|
}} |
|
|
}} |
|
|
onSubmit={(form, actions) => { |
|
|
onSubmit={(form, actions) => { |
|
|
const psw_match = comparePassword( |
|
|
|
|
|
|
|
|
const psw_not_match = comparePassword( |
|
|
form.password, |
|
|
form.password, |
|
|
form.confirmPassword |
|
|
form.confirmPassword |
|
|
); |
|
|
); |
|
|
if (psw_match) { |
|
|
|
|
|
|
|
|
if (psw_not_match) { |
|
|
actions.setFieldError( |
|
|
actions.setFieldError( |
|
|
"confirmPassword", |
|
|
"confirmPassword", |
|
|
"As senhas não correspondem" |
|
|
"As senhas não correspondem" |
|
|
); |
|
|
); |
|
|
|
|
|
} else { |
|
|
|
|
|
// FIXME: This should be replaced by the proper api call in future
|
|
|
|
|
|
const apiReturnTest = 403; |
|
|
|
|
|
|
|
|
|
|
|
handleApiReturn(apiReturnTest); |
|
|
} |
|
|
} |
|
|
console.log("redefinir senha -> atualizar senha -> confirmar"); |
|
|
|
|
|
}} |
|
|
}} |
|
|
> |
|
|
> |
|
|
<View style={{ padding: 16 }}> |
|
|
<View style={{ padding: 16 }}> |
|
|