Browse Source

Adding more descriptive error messages in register screen

master
GabrielTrettel 3 years ago
parent
commit
32fc4c811e
  1. 27
      src/app/screens/RegisterScreen.js

27
src/app/screens/RegisterScreen.js

@ -265,7 +265,7 @@ export default function RegisterScreen(props) {
const [date, setDate] = useState(_moment); const [date, setDate] = useState(_moment);
const [singUpFailed, setSingUpFailed] = useState(false); const [singUpFailed, setSingUpFailed] = useState(false);
const [scroll, setScroll] = useState(); const [scroll, setScroll] = useState();
const [showLog, setShowLog] = useState(false);
const [showLog, setShowLog] = useState({show: false, message: ""});
const comparePassword = (password, confirmPassword) => { const comparePassword = (password, confirmPassword) => {
if (password !== confirmPassword) { if (password !== confirmPassword) {
@ -286,25 +286,25 @@ export default function RegisterScreen(props) {
}; };
const handleSubmit = async (form) => { const handleSubmit = async (form) => {
console.log("apaaaaaaa");
const formDate = const formDate =
date.format("DD/MM/yyyy") === moment().format("DD/MM/yyyy") ? "" : date; date.format("DD/MM/yyyy") === moment().format("DD/MM/yyyy") ? "" : date;
const result = await signup({ ...form, dateofborn: formDate }); const result = await signup({ ...form, dateofborn: formDate });
// console.log(result)
switch (result.status) { switch (result.status) {
case 200: case 200:
automaticLogin(form); automaticLogin(form);
break; break;
case 422:
// setError()
default:
setShowLog({show: true, message: "Um erro inesperado ocorreu. Tente novamente mais tarde"})
} }
}; };
const fieldsAreNotInUse = async (form, actions) => { const fieldsAreNotInUse = async (form, actions) => {
var inUse = true;
var inUse = false;
const ru = await existUsername(form.number); const ru = await existUsername(form.number);
if (ru.data) { if (ru.data) {
actions.setFieldError("number", "Este número de telefone já está em uso"); actions.setFieldError("number", "Este número de telefone já está em uso");
inUse = false; inUse = false;
@ -315,17 +315,22 @@ export default function RegisterScreen(props) {
actions.setFieldError("name", "Este apelido de usuário já está em uso"); actions.setFieldError("name", "Este apelido de usuário já está em uso");
inUse = false; inUse = false;
} }
if (!ru.ok || !rn.ok)
setShowLog({show: true, message: "Um erro inesperado ocorreu. Tente novamente mais tarde"})
inUse && setShowLog({show: true, message: "Apelido de usuário ou telefone em uso"})
return inUse;
return !inUse;
}; };
return ( return (
<Screen style={styles.containter}> <Screen style={styles.containter}>
<ConfirmationModal <ConfirmationModal
show={showLog}
description="Apelido de usuário ou telefone em uso"
show={showLog.show}
description={showLog.message}
confirmationLabel="OK" confirmationLabel="OK"
onConfirm={() => setShowLog(false)}
onConfirm={() => setShowLog({...showLog, show:false})}
/> />
<Form <Form
initialValues={{ initialValues={{
@ -347,7 +352,7 @@ export default function RegisterScreen(props) {
comparePassword(form.password, form.confirmPassword); comparePassword(form.password, form.confirmPassword);
fieldsAreNotInUse(form, actions).then((isNotUsed) => { fieldsAreNotInUse(form, actions).then((isNotUsed) => {
isNotUsed ? handleSubmit(form) : setShowLog(true);
isNotUsed && handleSubmit(form);
// NOTE: this woud be nice, but does not work... // NOTE: this woud be nice, but does not work...
// : scroll.scrollTo({ // : scroll.scrollTo({
// x: 0, // x: 0,

Loading…
Cancel
Save