|
@ -7,6 +7,7 @@ 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"; |
|
|
import ConfirmationModal from "../components/ConfirmationModal"; |
|
|
|
|
|
import { updatePassword } from "../api/auth"; |
|
|
|
|
|
|
|
|
const validationSchema = Yup.object().shape({ |
|
|
const validationSchema = Yup.object().shape({ |
|
|
password: Yup.string() |
|
|
password: Yup.string() |
|
@ -19,26 +20,31 @@ 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({ route }) { |
|
|
|
|
|
|
|
|
export default function PasswordRecoveryChangePswd({ navigation, route }) { |
|
|
const authToken = route.params.authToken; |
|
|
const authToken = route.params.authToken; |
|
|
console.log(authToken); |
|
|
|
|
|
|
|
|
const username = route.params.username; |
|
|
|
|
|
|
|
|
const [confirmatioModalData, setConfirmatioModalData] = useState({ |
|
|
const [confirmatioModalData, setConfirmatioModalData] = useState({ |
|
|
show: false, |
|
|
show: false, |
|
|
message: "", |
|
|
message: "", |
|
|
|
|
|
onConfirmAction: () => {}, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const comparePassword = (password, confirmPassword) => { |
|
|
const comparePassword = (password, confirmPassword) => { |
|
|
return password !== confirmPassword; |
|
|
return password !== confirmPassword; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
const handleApiReturn = (apiReturn) => { |
|
|
|
|
|
console.log(apiReturn); |
|
|
|
|
|
switch (apiReturn) { |
|
|
|
|
|
|
|
|
const handleSubmit = async (password) => { |
|
|
|
|
|
const apiReturn = await updatePassword(authToken, username, password); |
|
|
|
|
|
|
|
|
|
|
|
switch (apiReturn.status) { |
|
|
case 200: |
|
|
case 200: |
|
|
setConfirmatioModalData({ |
|
|
setConfirmatioModalData({ |
|
|
message: "Senha alterada com sucesso", |
|
|
message: "Senha alterada com sucesso", |
|
|
show: true, |
|
|
show: true, |
|
|
|
|
|
onConfirmAction: () => { |
|
|
|
|
|
navigation.navigate("Login"); |
|
|
|
|
|
}, |
|
|
}); |
|
|
}); |
|
|
break; |
|
|
break; |
|
|
case 404: |
|
|
case 404: |
|
@ -49,7 +55,10 @@ export default function PasswordRecoveryChangePswd({ route }) { |
|
|
break; |
|
|
break; |
|
|
case 500: |
|
|
case 500: |
|
|
case 403: |
|
|
case 403: |
|
|
console.log("EXPIRED TOKEN"); |
|
|
|
|
|
|
|
|
setConfirmatioModalData({ |
|
|
|
|
|
message: "Algo deu errado, tente novamente mais tarde", |
|
|
|
|
|
show: true, |
|
|
|
|
|
}); |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
setConfirmatioModalData({ |
|
|
setConfirmatioModalData({ |
|
@ -66,9 +75,10 @@ export default function PasswordRecoveryChangePswd({ route }) { |
|
|
show={confirmatioModalData.show} |
|
|
show={confirmatioModalData.show} |
|
|
description={confirmatioModalData.message} |
|
|
description={confirmatioModalData.message} |
|
|
confirmationLabel="OK" |
|
|
confirmationLabel="OK" |
|
|
onConfirm={() => |
|
|
|
|
|
setConfirmatioModalData({ ...confirmatioModalData, show: false }) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
onConfirm={() => { |
|
|
|
|
|
setConfirmatioModalData({ ...confirmatioModalData, show: false }); |
|
|
|
|
|
confirmatioModalData?.onConfirmAction(); |
|
|
|
|
|
}} |
|
|
/> |
|
|
/> |
|
|
|
|
|
|
|
|
<Form |
|
|
<Form |
|
@ -88,10 +98,7 @@ export default function PasswordRecoveryChangePswd({ route }) { |
|
|
"As senhas não correspondem" |
|
|
"As senhas não correspondem" |
|
|
); |
|
|
); |
|
|
} else { |
|
|
} else { |
|
|
// FIXME: This should be replaced by the proper api call in future
|
|
|
|
|
|
const apiReturnTest = 403; |
|
|
|
|
|
|
|
|
|
|
|
handleApiReturn(apiReturnTest); |
|
|
|
|
|
|
|
|
handleSubmit(form.password); |
|
|
} |
|
|
} |
|
|
}} |
|
|
}} |
|
|
> |
|
|
> |
|
|